MPI Asynchronous: Example
Buffer management with asynchronous communcation:
- buffers declared in isend/irecv can be (re-)used only after the communication has actually completed.
- Requests should be freed (mpi_test, mpi_wait, mpi_request_free) for all the isend calls in the program, otherwise mpi_finalize might hang
integer stat(MPI_STATUS_SIZE,10)
if(mype.eq.0) then ! Master receiving from all slaves
call mpi_irecv(B1(ip),NB1,MPI_REAL,
ip,MPI_ANY_TAG,MPI_COMM_WORLD,req(ip),info)
else ! Slave send to master
call mpi_isend(B1(mype),NB1,MPI_REAL,0,itag,MPI_COMM_WORLD,req,info)
… ! Some unrelated calculations
call mpi_waitall(nreq,req,stat,ierr)
… ! Data is available in B1 in the master process
… ! Buffer B1 can be reused in the slave processes