Question

My pseudo code has something like this:

//Some work
MPI_Send(....)
MPI_Irecv(&yesno, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
//Do some WORK1 (background work) till MPI_Irecv completes and when receive completes do WORK 2.
--WORK1
--WORK2

Where do I put WORK1 and WORK2 and how to redirect control to WORK2 just when receive completes?

MORE INFO: I am trying to implement a master-slave program where the master issues work to slaves. The master continues to work when it has issued work to say slave 1 and needs to be interrupted by slave 1 when done. When this interrupt happens some code needs to be executed by the master. Then the master needs to continue from where it left off before interrupt.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top