Does a mpi request finish if recv and send is matched

846 views Asked by At

Is it enough to check only one request object from two matching non-blocking send and recv operations.

This would be great as this would reduce the effort to handle the request objects in my program.

Here a small example with boost mpi:

#include <boost/mpi.hpp>

int main(int argc, char* argv[]) {
    // initialize mpi

    mpi::environment env(argc, argv);
    boost::mpi::communicator world;
    boost::mpi::request req0, req1;
    double blub;
    if(world.rank()==1)
       req1 = world.irecv(0, 23, blub);
    if(world.rank()==0)
       req0 = world.isend(0, 23, blub);

    //now I want to synchronize the processors is this enough?
    req0.wait();
    //or do I also need this line
    req1.wait();

}
1

There are 1 answers

0
Jonathan Dursi On BEST ANSWER

Rank 1 doesn't have a valid req0, and rank 0 doesn't have a valid req1; they are requests which are only valid on the tasks that actually performed the nonblocking operation (and returned a handle to a request).

So no, neither rank here needs to (or even could) call wait on both requests; each calls a wait on the request that it has, eg

if(world.rank()==0)
    req0.wait();
if(world.rank()==1)
    req1.wait();

or, better (I assume that the isend for rank 0 should go to rank 1, not 0):

boost::mpi::request req;
...
if(world.rank()==1)
   req = world.irecv(0, 23, blub);
if(world.rank()==0)
   req = world.isend(1, 23, blub);

if (world.rank() == 0 || world.rank() == 1)
   req.wait();

Note that when you do need to wait for the multiple operations corresponding to multiple requests, you can have a list of the requests and call wait_all.