MPI makes no guarantee about the order in which messages from different processes will be recieved. In fact, a receive operation can begin after a send has completed if an output buffer is used in standard mode: http://www.mpi-forum.org/docs/mpi-1.1/mpi-11-html/node40.html#Node40. The only order you can guarantee with standard mode send is that message3
will always arrive after message1
. Here is a possible (not unique) sequence that would lead to your anomalous scenario:
- Rank 2 sends a message (message1) to rank 0;
- Rank 0 receives message1 from rank2;
- Rank 0 sends a message (message1) to rank 1;
- Rank 1 receives message1 from rank0;
- Rank 2 sends a message (message2) to rank 1;
- Rank 2 sends a message (message3) to rank 0;
- Rank 0 receives message3 from rank2;
- Rank 0 sends a message (message3) to rank 1;
- Rank 1 receives message3 from rank0;
- Rank 1 receives message2 from rank2;
Essentially, MPI_Send
is an alias for either MPI_BSend
or MPI_SSend
, and it is not up to you which one is picked. Your anomaly is caused by MPI_BSend
. You can guarantee a write to the corresponding receive buffer using synchronous mode (MPI_SSend
) or ready mode (MPI_RSend
). The main diffrerence between the two is that ready mode requires the receiver to already be waiting for the message for it not to fail, while synchronous mode will wait for it to happen.
If you are on a Linux platform, you can play with the standard mode by using the nice
command to increase the priority of rank0
and decrease that of rank2
. The anomaly should happen more consistently the more you increase the priority difference. Here is a brief tutorial on the subject: http://www.nixtutor.com/linux/changing-priority-on-linux-processes/