MPI.Irecv!
is a non-blocking operation, that is, it returns immediately without waiting for the operation to complete. So by the time you call println(mid)
, data in mid
has not been yet updated since the data has not been yet received.
Unlike its blocking variant (MPI.Recv!
), MPI.Irecv!
returns a “request”. At some point of your code, you need to wait for this request to complete, before you can operate on the received data. In your specific case, you want to do the following:
for i in 1:size-1
req = MPI.Irecv!(mid, i, 0, comm)
MPI.Wait!(req) # wait for operation to complete
println("mid: $mid")
buf = mid[1]
println("buf: $buf")
end
Note that all of this also applies to MPI.Isend
, which is also non-blocking.