Site Tools


mpi-probing

Table of Contents

MPI Probing for messages

Probing checks for incoming messages without consuming them. MPI_Probe returns metadata in MPI_Status (including element count) so you can allocate the right buffer before calling MPI_Recv.

MPI_Status status;
MPI_Probe(src, tag, MPI_COMM_WORLD, &status);
 
int count;
MPI_Get_count(&status, MPI_DOUBLE, &count);
double *buf = malloc(count * sizeof(double));
 
MPI_Recv(buf, count, MPI_DOUBLE, src, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

MPI_Iprobe is the non-blocking variant: it sets a flag and returns immediately whether or not a matching message is available. Both functions accept MPI_ANY_SOURCE and MPI_ANY_TAG. When wildcards are used, the source rank from the MPI_Status must be passed verbatim to the following MPI_Recv to ensure the same message is consumed, not a different one that arrived in between.

mpi-probing.md · Last modified: by 127.0.0.1