Reputation: 145
I'm a little bit confused about MPI point-to-point blocking modes.
now i have the following code.
y = id;
j = id - 1;
if(j<0) j = p -1;
k = id + 1;
if(k>p-1) k = 0;
MPI_Recv(&x, 1, MPI_INT, k, 0, MPI_COMM_WORLD, &status);
MPI_Send(&y, 1, MPI_INT, j, 0, MPI_COMM_WORLD);
z = x + y;
That will be blocked as MPI_Recv is a blocking function, but when i change the order to call MPI_Send first everything goes ok and i do not know the reason.
Thanks in advance and sorry for my English.
Upvotes: 0
Views: 320
Reputation: 8395
MPI_Send()
blocks until the send buffer can be reused.
from a pragmatic point of view, MPI_Send()
returns immediatly if the message is short enough, and otherwise, blocks until a matching MPI_Recv()
is posted.
this is a general behavior, but you should not rely on that.
in this case, your best option is to use a single MPI_Sendrecv()
call instead of two blocking send/recv calls
an other option is to
MPI_Irecv(); MPI_Send(); MPI_Wait();
Upvotes: 2