简体   繁体   中英

Does a mpi request finish if recv and send is matched

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();

}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM