4.8.1. Probe

PreviousUpNext
Up: Probe and Cancel Next: Matching Probe Previous: Probe and Cancel

MPI_IPROBE(source, tag, comm, flag, status)
IN sourcerank of source or MPI_ANY_SOURCE (integer)
IN tagmessage tag or MPI_ANY_TAG (integer)
IN commcommunicator (handle)
OUT flag true if there is a matching message that can be received (logical)
OUT statusstatus object (status)
C binding
int MPI_Iprobe(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
Fortran 2008 binding
MPI_Iprobe(source, tag, comm, flag, status, ierror)

INTEGER, INTENT(IN) :: source, tag
TYPE(MPI_Comm), INTENT(IN) :: comm
LOGICAL, INTENT(OUT) :: flag
TYPE(MPI_Status) :: status
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_IPROBE(SOURCE, TAG, COMM, FLAG, STATUS, IERROR)

INTEGER SOURCE, TAG, COMM, STATUS(MPI_STATUS_SIZE), IERROR
LOGICAL FLAG

MPI_IPROBE returns flag = true if there is a message that can be received and that matches the pattern specified by the arguments source, tag, and comm. The call matches the same message that would have been received by a call to MPI_RECV with the same argument values for source, tag, comm, and status executed at the same point in the program, and returns in status the same value that would have been returned by MPI_RECV. Otherwise, the call returns flag = false, and leaves status undefined.

If MPI_IPROBE returns flag = true, then the content of the status object can be subsequently accessed as described in Section Return Status to find the source, tag, and length of the probed message.

MPI_IPROBE is a local procedure since its return does not depend on MPI calls in other MPI processes, which is marked with the prefix I (for immediate).

A subsequent receive executed with the same communicator, and the source and tag returned in status by MPI_IPROBE will receive the message that was matched by the probe, if no other intervening receive occurs after the probe, and the send is not successfully cancelled before the receive. If the receiving MPI process is multithreaded, it is the user's responsibility to ensure that the last condition holds.

The source argument of MPI_IPROBE can be MPI_ANY_SOURCE, and the tag argument can be MPI_ANY_TAG, so that one can probe for messages from an arbitrary source and/or with an arbitrary tag. However, a specific communication context must be provided with the comm argument.

It is not necessary to receive a message immediately after it has been probed for, and the same message may be probed for several times before it is received.

A probe with MPI_PROC_NULL as source returns flag = true, and the status object returns source = MPI_PROC_NULL, tag = MPI_ANY_TAG, and count = 0; see Section Null MPI Processes.

MPI_PROBE(source, tag, comm, status)
IN sourcerank of source or MPI_ANY_SOURCE (integer)
IN tagmessage tag or MPI_ANY_TAG (integer)
IN commcommunicator (handle)
OUT statusstatus object (status)
C binding
int MPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status *status)
Fortran 2008 binding
MPI_Probe(source, tag, comm, status, ierror)

INTEGER, INTENT(IN) :: source, tag
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(MPI_Status) :: status
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
Fortran binding
MPI_PROBE(SOURCE, TAG, COMM, STATUS, IERROR)

INTEGER SOURCE, TAG, COMM, STATUS(MPI_STATUS_SIZE), IERROR

MPI_PROBE behaves like MPI_IPROBE except that it is a nonlocal call that returns only after a matching message has been found.

The MPI implementation of MPI_PROBE and MPI_IPROBE needs to guarantee progress: if a call to MPI_PROBE has been issued by an MPI process, and a send that matches the probe has been initiated by some MPI process, then the call to MPI_PROBE will return, unless the message is received by another concurrent receive operation (that is executed by another thread at the probing MPI process).

Similarly, if an MPI process repeatedly calls MPI_IPROBE and a matching message has been issued, then MPI_IPROBE will eventually return flag = true unless the message is received by another concurrent receive operation or matched by a concurrent matching probe. See also Section Progress on progress.


Example Use probe to wait for an incoming message.

Image file

Each message is received with the right type.


Example A similar program to the previous example, but now it has a problem.

Image file

In Example Probe, the two receive calls in statements labeled 100 and 200 in Example Probe are slightly modified, using MPI_ANY_SOURCE as the source argument. The program is now incorrect: the receive operation may receive a message that is distinct from the message probed by the preceding call to MPI_PROBE.


Advice to users.

In a multithreaded MPI program, MPI_PROBE and MPI_IPROBE might need special care. If a thread probes for a message and then immediately posts a matching receive, the receive may match a message other than that found by the probe since another thread could concurrently receive that original message [34]. MPI_MPROBE and MPI_IMPROBE solve this problem by matching the incoming message so that it may only be received with MPI_MRECV or MPI_IMRECV on the corresponding message handle. ( End of advice to users.)

Advice to implementors.

A call to MPI_PROBE will match the message that would have been received by a call to MPI_RECV with the same argmument values for source, tag, comm, and status executed at the same point. Suppose that this message has source s, tag t and communicator c. If the tag argument in the probe call has value MPI_ANY_TAG then the message probed will be the earliest pending message from source s with communicator c and any tag; in any case, the message probed will be the earliest pending message from source s with tag t and communicator c (this is the message that would have been received, so as to preserve message order). This message continues as the earliest pending message from source s with tag t and communicator c, until it is received. A receive operation subsequent to the probe that uses the same communicator as the probe and uses the tag and source values returned by the probe, must receive this message, unless it has already been received by another receive operation. ( End of advice to implementors.)


PreviousUpNext
Up: Probe and Cancel Next: Matching Probe Previous: Probe and Cancel


Return to MPI-4.1 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-4.1 of November 2, 2023
HTML Generated on November 19, 2023