@@ -500,6 +500,38 @@ function reduction_impl(op,a::MPIArray,destination;init=nothing)
500500 MPIArray (b_item,comm,size (a))
501501end
502502
503+ function setup_non_blocking_reduction_impl (a:: MPIArray , :: Type{T} ) where T
504+ request = MPI. UnsafeRequest () # Single reduction request
505+ buffer = Ref {T} ()
506+ return (request = request, recvbuf = buffer)
507+ end
508+
509+ function non_blocking_reduction_impl (op, a:: MPIArray , setup, destination= :all ; init= nothing )
510+ @assert destination === :all
511+ T = eltype (a)
512+ comm = a. comm
513+ opr = MPI. Op (op, T)
514+
515+ sendbuf = Ref (a. item)
516+ recvbuf = setup. recvbuf
517+ request = setup. request
518+ rbuf = MPI. RBuffer (sendbuf, recvbuf)
519+
520+ state = (sendbuf, recvbuf, request)
521+
522+ GC. @preserve state MPI. API. MPI_Iallreduce (rbuf. senddata, rbuf. recvdata, rbuf. count, rbuf. datatype, opr, comm, request)
523+
524+
525+ @fake_async begin
526+ GC. @preserve state MPI. Wait (request)
527+ b_item = recvbuf[]
528+ if init != = nothing
529+ b_item = op (b_item,init)
530+ end
531+ MPIArray (b_item,comm,size (a))
532+ end
533+ end
534+
503535function Base. reduce (op,a:: MPIArray ;kwargs... )
504536 r = reduction (op,a;destination= :all ,kwargs... )
505537 r. item
0 commit comments