MPI_Sendrecv(3)

๐Ÿ“ฆ
version 5.0.1 ยท 5 versions
, in nixos 26.05, ubuntu stonking

๐Ÿ’Œ MPI_Sendrecv(3) โ€” the MPI manual, bestie edition ๐Ÿ’Œ

okay so this is a page from the MPI manual (yes, that MPI, the Message Passing Interface one) and today's main character is MPI_Sendrecv โ€” it sends and receives a message. Both. At once. In one call. Iconic behaviour honestly.


โœจ NAME โœจ

MPI_Sendrecv โ€” sends and receives a message ๐Ÿซถ like it literally does both, no cap


๐ŸŒธ SYNOPSIS ๐ŸŒธ

int MPI_Sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
int dest, int sendtag, void *recvbuf, int recvcount,
MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm,
MPI_Status *status)

int MPI_Sendrecv_c(const void *sendbuf, MPI_Count sendcount,
MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf,
MPI_Count recvcount, MPI_Datatype recvtype, int source,
int recvtag, MPI_Comm comm, MPI_Status *status)

two versions, bestie, take ur pick ๐Ÿ’… the _c one is the big-count variant, MPI_Count instead of int for the counts.


๐Ÿ’– INPUT PARAMETERS ๐Ÿ’–

the stuff u hand in to the function, aka the vibe u bring to the function:

  • sendbuf โ€” initial address of send buffer (choice) ๐Ÿ“ค
  • sendcount โ€” number of elements in send buffer (non-negative integer)
  • sendtype โ€” type of elements in send buffer (handle)
  • dest โ€” rank of destination (integer) ๐ŸŽฏ
  • sendtag โ€” send tag (integer)
  • recvcount โ€” number of elements in receive buffer (non-negative integer)
  • recvtype โ€” type of elements receive buffer element (handle)
  • source โ€” rank of source or MPI_ANY_SOURCE (integer) ๐Ÿ‘€ mystery sender energy
  • recvtag โ€” receive tag or MPI_ANY_TAG (integer)
  • comm โ€” communicator (handle)

๐ŸŽ€ OUTPUT PARAMETERS ๐ŸŽ€

the stuff it hands back to u:

  • recvbuf โ€” initial address of receive buffer (choice) ๐Ÿ“ฅ
  • status โ€” status object (Status)

๐Ÿงต THREAD AND INTERRUPT SAFETY ๐Ÿงต

the tea โ˜•: this routine is thread-safe. that means multiple threads can use it without u having to bring ur own thread locks, no user-provided lock drama required. slay.

BUT โ€” and this is the plot twist ๐Ÿ˜ญ โ€” the routine is not interrupt safe. typically this is because of memory allocation routines like malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, don't interrupt it, it's having a moment.


๐Ÿ”ฎ NOTES FOR FORTRAN ๐Ÿ”ฎ

for the Fortran girlies:

  • All MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is an integer and has the same meaning as the return value of the routine in C.
  • In Fortran, MPI routines are subroutines, and they're invoked with the call statement.
  • All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. yes really. that's just how it is ๐Ÿ’…

๐Ÿ’€ ERRORS ๐Ÿ’€

okay so listen. All MPI routines (except MPI_Wtime and MPI_Wtick) return an error value; C routines as the value of the function and Fortran routines in the last argument. Before that value comes back, the current MPI error handler gets called. By default, this error handler aborts the MPI job ๐Ÿ˜ญ like full on kill switch, no survivors.

u can change the error handler with:

  • MPI_Comm_set_errhandler (for communicators)
  • MPI_File_set_errhandler (for files)
  • MPI_Win_set_errhandler (for RMA windows)

The MPI-1 routine MPI_Errhandler_set may be used but its use is deprecated (no bestie, we don't do that anymore ๐Ÿ™ˆ).

The predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned instead.

Note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. so like... fingers crossed ๐Ÿคž

here's the error code menu:

  • MPI_SUCCESS โ€” No error; MPI routine completed successfully. ate and left no crumbs โœจ
  • MPI_ERR_ARG โ€” Invalid argument. Some argument is invalid and is not identified by a specific error class (e.g., MPI_ERR_RANK).
  • MPI_ERR_BUFFER โ€” Invalid buffer pointer. Usually a null buffer where one is not valid.
  • MPI_ERR_COMM โ€” Invalid communicator. A common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank). ๐Ÿ’€
  • MPI_ERR_COUNT โ€” Invalid count argument. Count arguments must be non-negative; a count of zero is often valid.
  • MPI_ERR_RANK โ€” Invalid source or destination rank. Ranks must be between zero and the size of the communicator minus one; ranks in a receive (MPI_Recv, MPI_Irecv, MPI_Sendrecv, etc.) may also be MPI_ANY_SOURCE.
  • MPI_ERR_TAG โ€” Invalid tag argument. Tags must be non-negative; tags in a receive (MPI_Recv, MPI_Irecv, MPI_Sendrecv, etc.) may also be MPI_ANY_TAG. The largest tag value is available through the the attribute MPI_TAG_UB.
  • MPI_ERR_TYPE โ€” Invalid datatype argument. Additionally, this error can occur if an uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call.
  • MPI_ERR_OTHER โ€” Other error; use MPI_Error_string to get more information about this error code.

and that's the whole page, bestie ๐Ÿฆ‹ this one's dated 4/10/2026 and it's page MPI_Sendrecv(3) from the MPI manual set. go forth and sendrecv responsibly ๐Ÿ’œโœจ

๐Ÿ“ฆ where this page comes from