MPI_RECV(3)
π MPI_RECV(3) β Open MPI
okay bestie, buckle up π this is the Open MPI manual page for MPI_Recv, and yes it's a whole mood. it does a standard-mode blocking receive, and honestly it's kind of the main character of every MPI program you'll ever write. no cap.
β¨ NAME β¨
MPI_Recv β performs a standard-mode blocking receive π«Ά
πΈ SYNTAX πΈ
π C Syntax
#include <mpi.h>
int MPI_Recv(void *buf, int count, MPI_Datatype datatype,
int source, int tag, MPI_Comm comm, MPI_Status *status)
π Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_RECV(BUF, COUNT, DATATYPE, SOURCE, TAG, COMM, STATUS, IERROR)
<type> BUF(*)
INTEGER COUNT, DATATYPE, SOURCE, TAG, COMM
INTEGER STATUS(MPI_STATUS_SIZE), IERROR
π Fortran 2008 Syntax
USE mpi_f08
MPI_Recv(buf, count, datatype, source, tag, comm, status, ierror)
TYPE(*), DIMENSION(..) :: buf
INTEGER, INTENT(IN) :: count, source, tag
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Comm), INTENT(IN) :: comm
TYPE(MPI_Status) :: status
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS π
countβ the max number of elements you're willing to receive, bestie (integer). it's a ceiling, not a promise.datatypeβ the datatype of each entry in the receive buffer (handle).sourceβ rank of the source process (integer).tagβ the message tag (integer).commβ the communicator (handle).
π¦ OUTPUT PARAMETERS π¦
bufβ the initial address of the receive buffer (choice). this is where the good stuff lands β¨statusβ the status object (status). it's giving receipts.ierrorβ Fortran only: error status (integer).
π₯ DESCRIPTION π₯
so MPI_Recv is the basic receive operation, and the key word is blocking: it literally does not return until the receive buffer actually contains the newly received message. like, it will sit there. patient. iconic. π
a fun little detail: a receive can complete before the matching send has completed β but obviously it can only complete after the matching send has started. so the handshake's gotta begin, but the sender doesn't need to be done.
the blocking semantics of this call are described in the "Communication Modes" section of the MPI Standard, iykyk.
your receive buffer holds a number of consecutive elements β that number is defined by the value of count. the very first element in that set lives at address_buf, and the type of each element is specified by datatype.
here's the rule: the length of the received message must be less than or equal to the length of the receive buffer. if it overflows, you get an MPI_ERR_TRUNCATE back. π
and if a message that's shorter than the length of the receive buffer shows up? then only those locations corresponding to the (shorter) received message get modified. everything else stays untouched, no notes.
π NOTES π
the count argument is the maximum number of entries of type datatype that can be received in a message. so once a message actually arrives, use MPI_Get_count to find out how many entries were really in there. don't just assume, bestie.
receiving messages of unknown length? that's a job for MPI_Probe π΅οΈ for more info about MPI_Probe and MPI_Cancel, check their respective man pages and the "Probe and Cancel" section of the MPI Standard.
a message can only be received by a receive operation if it's addressed to the receiving process and its source, tag, and communicator (comm) values match the source, tag, and comm values you specified in the receive. the receive operation may specify a wildcard value for source and/or tag, meaning any source and/or tag is acceptable:
- the wildcard value for source is
source = MPI_ANY_SOURCE - the wildcard value for tag is
tag = MPI_ANY_TAG - there is no wildcard value for
commπ
the scope of these wildcards is limited to the processes in the group of the specified communicator.
the message tag is specified by the tag argument of the receive operation.
the source argument, if it's different from MPI_ANY_SOURCE, is specified as a rank within the process group associated with that same communicator (remote process group, for intercommunicators). so the range of valid values for the source argument is {0,β¦,n-1} βͺ {MPI_ANY_SOURCE}, where n is the number of processes in this group. π―
okay so here's the asymmetry, and it's lowkey important: a receive operation may accept messages from an arbitrary sender, but a send operation must specify a unique receiver. this matches a "push" communication mechanism, where the data transfer is effected by the sender β not a "pull" mechanism, where the data transfer is effected by the receiver.
source = destination is allowed, meaning a process can send a message to itself. however, it is not recommended for a process to send messages to itself using the blocking send and receive operations described above, since this may lead to deadlock. π see the "Semantics of Point-to-Point Communication" of the MPI Standard for more details.
and if your application doesn't need to examine the status field, you can save resources by using the predefined constant MPI_STATUS_IGNORE as a special value for the status argument. free real estate. π
β ERRORS β
almost all MPI routines return an error value β C routines as the return result of the function, and Fortran routines in the last argument.
before the error value is returned, the current MPI error handler associated with the communication object (e.g., communicator, window, file) is called. if no communication object is associated with the MPI call, then the call is considered attached to MPI_COMM_SELF and will call the associated MPI error handler. when MPI_COMM_SELF is not initialized (i.e., before MPI_Init/MPI_Init_thread, after MPI_Finalize, or when using the Sessions Model exclusively) the error raises the initial error handler. the initial error handler can be changed by calling MPI_Comm_set_errhandler on MPI_COMM_SELF when using the World model, or the mpi_initial_errhandler CLI argument to mpiexec or info key to MPI_Comm_spawn/MPI_Comm_spawn_multiple. if no other appropriate error handler has been set, then the MPI_ERRORS_RETURN error handler is called for MPI I/O functions and the MPI_ERRORS_ABORT error handler is called for all other MPI functions.
Open MPI includes three predefined error handlers you can use π
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. yeah. all of them. πMPI_ERRORS_ABORTβ an error handler that can be invoked on a communicator, window, file, or session. when called on a communicator, it acts as ifMPI_Abortwas called on that communicator. if called on a window or file, it acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. if called on a session, it aborts only the local process.MPI_ERRORS_RETURNβ returns an error code to the application. chill of it.
MPI applications can also implement their own error handlers by calling:
MPI_Comm_create_errhandlerthenMPI_Comm_set_errhandlerMPI_File_create_errhandlerthenMPI_File_set_errhandlerMPI_Session_create_errhandlerthenMPI_Session_set_errhandleror atMPI_Session_initMPI_Win_create_errhandlerthenMPI_Win_set_errhandler
heads up: MPI does not guarantee that an MPI program can continue past an error. like at all. so don't get cute.
see the MPI man page for a full list of MPI error codes, and the Error Handling section of the MPI-3.1 standard for more information.
one more thing, and it's a niche one but it's real π«Ά: per the "Return Status" section in the "Point-to-Point Communication" chapter in the MPI Standard, MPI errors on messages received by MPI_Recv do not set the status.MPI_ERROR field in the returned status. the error code is always passed to the back-end error handler and may be passed back to the caller through the return value of MPI_Recv if the back-end error handler returns it. the pre-defined MPI error handler MPI_ERRORS_RETURN exhibits this behavior, for example.
π SEE ALSO
MPI_IrecvMPI_Probe
π COPYRIGHT
copyright 2003-2026, The Open MPI Community.
and that's the whole page, bestie π§β¨ this was the Open MPI MPI_RECV(3) manual page, dated Sep 11, 2026 β go forth and receive your messages responsibly. periodt. π
π¦ where this page comes from
- arch rolling: openmpi 5.0.11-1 Β· BSD-3-Clause AND LicenseRef-MPICH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms