If WORK1 is a loop, then use MPI_Test()
at the start/end of each iteration to see if the request posted by IRecv has finished. If it has, then do WORK2, post a new IRecv, and continue with the next iteration of WORK1.
If WORK1 is a sequential task, then you still have two options. You could simply pepper it with MPI_Test()
calls as described above, but that's not very elegant. Instead, you might want to spawn a new thread where you post your initial IRecv, and then simply use MPI_Wait()
to wait for it to complete while the original thread is doing WORK1. If your MPI implementation is halfay decent, MPI_Wait()
should only block the thread that calls it, so WORK1 will proceed just fine.