I am implementing MPI non-blocking communication inside my program. I see on MPI_Isend man_page, it says:
A nonblocking send call indicates that the system may start copying data out of the send buffer. The sender should not modify any part of the send buffer after a nonblocking send operation is called, until the send completes.
My code works like this:
// send messages
if(s > 0){
MPI_Requests s_requests[s];
MPI_Status s_status[s];
for(int i = 0; i < s; ++i){
// some code to form the message to send
std::vector<doubel> send_info;
// non-blocking send
MPI_Isend(&send_info[0], ..., s_requests[i]);
}
MPI_Waitall(s, s_requests, s_status);
}
// recv info
if(n > 0){ // s and n will match
for(int i = 0; i < n; ++i){
MPI_Status status;
// allocate the space to recv info
std::vector<double> recv_info;
MPI_Recv(&recv_info[0], ..., status)
}
}
My question is: am I modify the send buffers since they are in the inner curly brackets (the send_info vector get killed after the loop finishes)? Therefore, this is not a safe communication mode? Although my program works fine now, I still being suspected. Thank you for your reply.
sendmethod. You aren't doing that. - user207421MPI_Isend()to me. - Gilles Gouaillardetstd::vectorso it is allocated on stack. So the right way is to putMPI_Wait()andMPI_Isend()in the same loop? - ShiqiMPI_Send(). Other options include allocating a giant buffer before theforloop, and a singleMPI_Waitall()after. An other common technique is to use 2 buffers:isend(buffer0);isend(buffer1);wait(req0);isend(buffer(0);wait(req1); ...so you still have some room for overlap between computation and communication while keeping your memory usage reasonable. - Gilles Gouaillardet