MPI_IMRECV(3)
π MPI_IMRECV(3) β the Open MPI glow-up β¨
okay bestie, gather round, because today we're talking about MPI_Imrecv from the Open MPI crew β a non-blocking receive for a message that's already been matched. yes, that one. let's get into it π«Ά
πΈ SYNTAX
π C Syntax
#include <mpi.h>
int MPI_Imrecv(void *buf, int count, MPI_Datatype type,
MPI_Message *message, MPI_Request *request)
π Fortran Syntax
USE MPI
! or the older form: INCLUDE 'mpif.h'
MPI_IMRECV(BUF, COUNT, DATATYPE, MESSAGE, REQUEST, IERROR)
<type> BUF(*)
INTEGER COUNT, DATATYPE, MESSAGE, REQUEST, IERROR
π¦ Fortran 2008 Syntax
USE mpi_f08
MPI_Imrecv(buf, count, datatype, message, request, ierror)
TYPE(*), DIMENSION(..), ASYNCHRONOUS :: buf
INTEGER, INTENT(IN) :: count
TYPE(MPI_Datatype), INTENT(IN) :: datatype
TYPE(MPI_Message), INTENT(INOUT) :: message
TYPE(MPI_Request), INTENT(OUT) :: request
INTEGER, OPTIONAL, INTENT(OUT) :: ierror
π INPUT PARAMETERS
countβ how many elements you're receiving, and it's gotta be a nonnegative integer, no exceptions πdatatypeβ the datatype of each send buffer element (a handle, bestie)messageβ the message (handle). yep, that's it, that's the whole vibe
π OUTPUT PARAMETERS
bufβ initial address of the receive buffer (a choice)requestβ the request (handle) β¨ierrorβ Fortran only: error status (integer)
π DESCRIPTION
so MPI_Mrecv and MPI_Imrecv are the duo that receives messages that were previously matched by a matching probe. like, the probe already did the intros, and now these two actually take the call π
the request that comes back from MPI_Imrecv is a whole main-character non-blocking receive request β you can use it with any of the MPI_Test and MPI_Wait variants, no cap.
if you call MPI_Imrecv with MPI_MESSAGE_NULL as the message argument, then a call to one of the MPI_Test or MPI_Wait variants will return immediately, with the status object set to source = MPI_PROC_NULL, tag = MPI_ANY_TAG, and count = 0 β as if a receive from MPI_PROC_NULL was issued. iconic shortcut behavior tbh π§
and if reception of a matched message is started with MPI_Imrecv, you can cancel the returned request with MPI_Cancel π₯. if MPI_Cancel succeeds, the matched message must be found by a subsequent message probe (MPI_Probe, MPI_Iprobe, MPI_Mprobe, or MPI_Improbe), received by a subsequent receive operation, or canceled by the sender. that's the rule, periodt.
β οΈ but note, however β it is possible for the cancellation of operations initiated withMPI_Imrecvto fail, and that's not a vibe. an example of a failing case is when canceling the matched message receive would violate MPI message ordering rules (e.g., if another message matching the same message signature has matched β and possibly received β before thisMPI_Imrecvis canceled). so like, respect the ordering, bestie π
also: if your application does not 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. self-care via skipping the status field, we love to see it πΈ
π 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. lowkey the classic.
before that 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 that can be used:
MPI_ERRORS_ARE_FATALβ causes the program to abort all connected MPI processes. dramatic, but make it real π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, acts as ifMPI_Abortwas called on a communicator containing the group of processes in the corresponding window or file. if called on a session, aborts only the local process. very "know your scope" of it.MPI_ERRORS_RETURNβ returns an error code to the application. the polite one π
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
π«Ά note that MPI does not guarantee that an MPI program can continue past an error. like, no promises, bestie.
see the MPI man page for a full list of MPI error codes. and see the Error Handling section of the MPI-3.1 standard for more information.
one more thing, and this is important: per the "Return Status" section in the "Point-to-Point Communication" chapter in the MPI Standard, MPI errors on messages received by MPI_Imrecv 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_Imrecv if the back-end error handler returns it. the pre-defined MPI error handler MPI_ERRORS_RETURN exhibits this behavior, for example. iykyk β
π¦ SEE ALSO
MPI_MprobeMPI_ImprobeMPI_ProbeMPI_IprobeMPI_ImrecvMPI_Cancel
π COPYRIGHT
2003-2026, The Open MPI Community
and that's the whole page, bestie π this Open MPI moment was brought to you by the Sep 11, 2026 edition β go forth and MPI_Imrecv responsibly, mwah πβ¨
π¦ 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