The source or tag of a received message may not be known if wildcard values were used in the receive operation. Also, if multiple requests are completed by a single MPI function (see Section Multiple Completions ), a distinct error code may need to be returned for each request. The information is returned by the status argument of MPI_RECV. The type of status is MPI-defined. Status variables need to be explicitly allocated by the user, that is, they are not system objects.
In C, status is a structure that contains three fields named MPI_SOURCE, MPI_TAG, and MPI_ERROR; the structure may contain additional fields. Thus, status.MPI_SOURCE, status.MPI_TAG and status.MPI_ERROR contain the source, tag, and error code, respectively, of the received message.
In Fortran, status is an array of INTEGERs of size MPI_STATUS_SIZE. The constants MPI_SOURCE, MPI_TAG and MPI_ERROR are the indices of the entries that store the source, tag and error fields. Thus, status(MPI_SOURCE), status(MPI_TAG) and status(MPI_ERROR) contain, respectively, the source, tag and error code of the received message.
In general, message passing calls do not modify the value of the error code field of status variables. This field may be updated only by the functions in Section Multiple Completions which return multiple statuses. The field is updated if and only if such function returns with an error code of MPI_ERR_IN_STATUS.
[] Rationale.
The error field in status is not needed for calls that return only one
status, such as MPI_WAIT, since that would only duplicate the
information returned by the function itself. The current design
avoids the additional overhead of setting it, in such cases. The field
is needed for calls that return multiple statuses, since each request
may have had a different failure.
( End of rationale.)
The status argument also returns information on the length of the message received. However, this information is not directly available as a field of the status variable and a call to MPI_GET_COUNT is required to ``decode'' this information.
MPI_GET_COUNT(status, datatype, count)
[ IN status] return status of receive operation (Status)
[ IN datatype] datatype of each receive buffer entry (handle)
[ OUT count] number of received entries (integer)
int MPI_Get_count(MPI_Status *status, MPI_Datatype datatype, int *count)
MPI_GET_COUNT(STATUS, DATATYPE, COUNT, IERROR)
INTEGER STATUS(MPI_STATUS_SIZE), DATATYPE, COUNT, IERROR
Returns the number of entries received. (Again, we count entries, each of type datatype, not bytes.) The datatype argument should match the argument provided by the receive call that set the status variable. (We shall later see, in Section Use of general datatypes in communication , that MPI_GET_COUNT may return, in certain situations, the value MPI_UNDEFINED.)
[] Rationale.
Some message passing libraries use INOUT count, tag and source arguments, thus using them both to specify the selection criteria for incoming messages and return the actual envelope values of the received message. The use of a separate status argument prevents errors that are often attached with INOUT argument (e.g., using the MPI_ANY_TAG constant as the tag in a receive). Some libraries use calls that refer implicitly to the ``last message received.'' This is not thread safe.
The datatype argument is passed to MPI_GET_COUNT so as to
improve performance. A message might be received without counting the number
of elements it contains, and the count value is often not needed.
Also, this allows the same function to be used after a call to
MPI_PROBE.
( End of rationale.)
All send and receive operations use the buf, count,
datatype, source, dest, tag,
comm and status arguments in the same way as the blocking
MPI_SEND and
MPI_RECV operations described in this section.