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 with MPI_Imrecv to 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 this MPI_Imrecv is 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 if MPI_Abort was called on that communicator. if called on a window or file, acts as if MPI_Abort was 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_errhandler then MPI_Comm_set_errhandler
  • MPI_File_create_errhandler then MPI_File_set_errhandler
  • MPI_Session_create_errhandler then MPI_Session_set_errhandler or at MPI_Session_init
  • MPI_Win_create_errhandler then MPI_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_Mprobe
  • MPI_Improbe
  • MPI_Probe
  • MPI_Iprobe
  • MPI_Imrecv
  • MPI_Cancel

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