MPI_Sendrecv(3)
๐ 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 orMPI_ANY_SOURCE(integer) ๐ mystery sender energyrecvtagโ receive tag orMPI_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_WTIMEandMPI_WTICK) have an additional argumentierrat the end of the argument list.ierris 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
callstatement. - All MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin 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 inMPI_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 beMPI_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 beMPI_ANY_TAG. The largest tag value is available through the the attributeMPI_TAG_UB.MPI_ERR_TYPEโ Invalid datatype argument. Additionally, this error can occur if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call.MPI_ERR_OTHERโ Other error; useMPI_Error_stringto 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
- nixos 26.05: mpich 5.0.1
- ubuntu stonking: mpich-doc 5.0.1-9 ยท other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms