MPI_TestTests for the completion of a request
int MPI_Test( MPI_Request *request, int *flag, MPI_Status *status );
- [in] MPI request (handle)
- [out] true if operation completed (logical)
- [out] status object (Status). May be MPI_STATUS_IGNORE.
A call to MPI_TEST returns flag = true if the operation identified by request is complete. In such a case, the status object is set to contain information on the completed operation; if the communication object was created by a nonblocking send or receive, then it is deallocated and the request handle is set to MPI_REQUEST_NULL. The call returns flag = false, otherwise. In this case, the value of the status object is undefined. MPI_TEST is a local operation.
The return status object for a receive operation carries information that can be accessed. The status object for a send operation carries information that can be accessed by a call to MPI_TEST_CANCELLED.
One is allowed to call MPI_TEST with a null or inactive request argument. In such a case the operation returns with flag = true and empty status.
The functions MPI_WAIT and MPI_TEST can be used to complete both sends and receives.
Advice to users.
The use of the nonblocking MPI_TEST call allows the user to schedule
alternative activities within a single thread of execution. An
event-driven thread scheduler can be emulated with periodic calls to
MPI_TEST. ( End of advice to users.)
The function MPI_TEST returns with flag = true exactly in those situations where the function MPI_WAIT returns; both functions return in such case the same value in status. Thus, a blocking Wait can be easily replaced by a nonblocking Test.
Thread and Interrupt Safety
This routine is thread-safe. This means that this routine may be safely used by multiple threads without the need for any user-provided thread locks. However, the routine is not interrupt safe. Typically, this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe.
Note on status for send operationsFor send operations, the only use of status is for MPI_Test_cancelled or in the case that there is an error, in which case the MPI_ERROR field of status will be set.
Notes for FortranAll MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is an integer and has the same meaning as the return value of the routine in C. In Fortran, MPI routines are subroutines, and are invoked with the call statement.
All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran.
The status argument must be declared as an array of size MPI_STATUS_SIZE, as in integer status(MPI_STATUS_SIZE).
All MPI routines (except MPI_Wtime and MPI_Wtick) return an error value; C routines as the value of the function and Fortran routines in the last argument. Before the value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job. The error handler may be changed with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). The MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated. The predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. Note that MPI does not guarentee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible.
- No error; MPI routine completed successfully.
- Invalid MPI_Request. Either null or, in the case of a MPI_Start or MPI_Startall, not a persistent request.
- Invalid argument. Some argument is invalid and is not identified by a specific error class (e.g., MPI_ERR_RANK).
The following sample code illustrates MPI_Test.#include "mpi.h"
int main(int argc, char *argv)
int myid, numprocs, left, right, flag=0;
int buffer, buffer2;
right = (myid + 1) % numprocs;
left = myid - 1;
if (left < 0)
left = numprocs - 1;
MPI_Irecv(buffer, 10, MPI_INT, left, 123, MPI_COMM_WORLD, &request);
MPI_Send(buffer2, 10, MPI_INT, right, 123, MPI_COMM_WORLD);
MPI_Test(&request, &flag, &status);
/* Do some work ... */
MPI_Test(&request, &flag, &status);