Reputation: 124
I have a MPI_Isend and MPI_Recv program. Assume that i have 2 processors and both of them are like this.
What i expect from this is sending the data on both processors without blocking. Then wait for the data to come. Then resume, like this.
But what i get is this.
I thought that MPI_Recv should wait until the data comes. What may be causing this?
Upvotes: 2
Views: 3099
Reputation: 2346
What you can do to have kind of an unbuffered output is to perform the output and flush with interleaved MPI_Barrier
. Provided you have P
processes, the rank of the current process is stored in the variable rank
and you are using the communicator comm
, you can do:
for (int p = 0; p < P; ++p)
{
// Only one process writes at this time
// std::endl flushes the buffer
if (p == rank)
std::cout << "Message from process " << rank << std::endl;
// Block the other processes until the one that is writing
// flushes the buffer
MPI_Barrier(comm);
}
Of course this is just a C++ example. You may have to translate it into C of Fortran. Also notice that this code still does not guarantee with 100% probability that the output will actually be what you are expecting, but there are good probabilities.
Anyway, the principle is to always add a barrier between two output operations and to flush the buffer.
Upvotes: 0
Reputation: 9215
MPI_Recv
does block.
You just do not see the messages in the correct order because standard output is buffered and you do not see all outputs at once.
Upvotes: 1