I have questions about MPI send and receive operations.
Suppose, we have 2 MPI threads that try to send message to each other. Following are three code snippets doing that:
First (Blocking 'send' and 'receive'):
...
int data = ...;
...
MPI_Send( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD );
MPI_Status status;
MPI_Recv( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD, &status );
...
Second (Non-blocking 'send' but blocking 'receive'):
...
int data = ...;
...
MPI_Request request;
MPI_Isend( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD, &request);
MPI_Status status;
MPI_Recv( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD, &status );
// Synchronize sender & receiver
MPI_Wait( &request, &status);
...
Third (Non-blocking 'receive' with blocking 'send'):
...
int data = ...;
...
MPI_Request request;
MPI_Irecv( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD, &request );
MPI_Send( &data, sizeof( int ), MPI_INT,
(my_id == 0)?1:0, 0, MPI_COMM_WORLD);
MPI_Status status;
// Synchronize sender & receiver
MPI_Wait( &request, &status);
...
I guess there are potential problems with above three code but I want your opinion. So, I have the following questions:
What are the (potential) problems (if any) with 3 codes given above?
Which of the above three code are valid/correct considering MPI standard so that it can work with all MPI implementations?
What is the best way (if not one of above 3 please write it) to do that?
In the third code, what if we change the order of MPI_Irecv and MPI_Send call?
PS: By the way, I have tried executing them using Scali MPI and all of them worked!