Search code examples
cmpiintel-mpi

What is the use of status of MPI_Isend obtained using MPI_Wait?


Case: 1. What is the use of status obtained using MPI_Wait()

if(rank==0)
MPI_Isend(&buffer0, count, MPI_INT, 1, 0, MPI_COMM_WORLD, &request0);
if(rank==1)
MPI_Recv(&buffer1, count, MPI_INT, 0, 0, MPI_COMM_WORLD);

if(rank==0)
MPI_Wait(&request0, &status);
// Can i use status here to do something?
MPI_Finalize();

Case:2. Use of status is clear here (Just added for comparison)

if(rank==0)
MPI_Ssend(&buffer0, count, MPI_INT, 1, 0, MPI_COMM_WORLD);
if(rank==1)
MPI_Irecv(&buffer1, count, MPI_INT, 0, 0, MPI_COMM_WORLD, &request1);

if(rank==1)
MPI_Wait(&request1, &status);
printf("The source is %d", status.MPI_SOURCE);
MPI_Finalize();

Solution

  • Generally MPI_Status is used to get the the following properties for received messages.

    1. rank of the sender, (status.MPI_SOURCE) particularly relevant when MPI_ANY_SOURCE was used.
    2. tag of the message, (status.MPI_TAG) particularly relevant when MPI_ANY_TAG was used
    3. element-count that was sent, which may differ from posted receive buffer, using MPI_Get_count.

    For send messages, you can use the status to test for MPI_Test_cancelled. Further, for functions that return multiple status, such as MPI_Waitall, in the case of errors, you can use status[i].MPI_ERROR. The main wait function will return MPI_ERR_IN_STATUS in this case.

    If you do not need any of those, you may pass MPI_STATUS_IGNORE instead of a MPI_Status*.