MPI_Isendrecv_replace(3)
π MPI_Isendrecv_replace(3) β the MPI manual, bestie edition π
okay so you found the page, and honestly? iconic. this is the MPI manual page for MPI_Isendrecv_replace, and we're gonna get you all the way through it, no skips, no "we'll come back to that later". pookie, let's go π¦
β¨ NAME β¨
MPI_Isendrecv_replace β starts a nonblocking send and receive with a single buffer π
like... one buffer doing BOTH jobs. multitasking queen behavior, fr fr.
πΈ SYNOPSIS πΈ
int MPI_Isendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dest,
int sendtag, int source, int recvtag, MPI_Comm comm,
MPI_Request *request)
int MPI_Isendrecv_replace_c(void *buf, MPI_Count count, MPI_Datatype datatype,
int dest, int sendtag, int source, int recvtag,
MPI_Comm comm, MPI_Request *request)
two whole flavors, bestie: the regular one and the _c one (spoiler: the _c one takes an MPI_Count for count, so it's giving "for when numbers get big" energy π). both return int, both hand you back a request. slay.
π INPUT PARAMETERS π
countβ how many elements are chillin' in the send buffer and the receive buffer (non-negative integer). it's literally the same number for both, because one buffer, remember? β¨datatypeβ what kind of elements live in those buffers (handle)destβ rank of the destination π― (integer)sendtagβ the message tag on the send side (integer)sourceβ rank of the source, orMPI_ANY_SOURCEif you're in your "I'll take whoever" era (integer)recvtagβ the message tag on the receive side, orMPI_ANY_TAG(integer)commβ the communicator (handle)
π«Ά INPUT/OUTPUT PARAMETERS π«Ά
bufβ initial address of the send and receive buffer (choice)
yes bestie, ONE buffer, IN and OUT, main character energy. it sends from it and it receives into it. no cap.
π OUTPUT PARAMETERS π
requestβ the communication request (handle) π β this is your receipt, hold onto it, you'll need it later for all the waiting/testing stuff
π§΅ THREAD AND INTERRUPT SAFETY π§΅
okay this one is good news: this routine is thread-safe. that means multiple threads can use it at the same time and nobody needs to bring their own thread locks β the routine handles it, periodt. π
β οΈ BUT. and this is a real but: it is not interrupt safe. typically that's because it uses memory allocation routines like malloc, or other non-MPICH runtime routines, and those are themselves not interrupt-safe. so like... thread-safe, yes; interrupt-safe, no. don't get it twisted. π
π NOTES FOR FORTRAN π
- literally all MPI routines in Fortran have an extra argument called
ierrtacked onto the end of the argument list β the only exceptions areMPI_WTIMEandMPI_WTICK. (they're special. they know it. π ) ierris an integer and it Means The Same Thing as the return value of the routine in C. same vibes, different language.- in Fortran, MPI routines are subroutines, and you call them with the
callstatement. - all MPI objects (like
MPI_Datatype,MPI_Comm) are of typeINTEGERin Fortran. that's just how it is.
π ERRORS π
so, all MPI routines (again, except MPI_Wtime and MPI_Wtick) return an error value β C routines return it as the value of the function, and Fortran routines put it in that last argument we just talked about.
before that value comes back to you, the current MPI error handler gets called. by default? this error handler aborts the MPI job. like, whole thing, gone, bye. π
the error handler can be swapped out with:
MPI_Comm_set_errhandlerβ for communicatorsMPI_File_set_errhandlerβ for filesMPI_Win_set_errhandlerβ for RMA windows
the MPI-1 routine MPI_Errhandler_set may be used too, but its use is deprecated (old, crusty, don't).
you can also use the predefined error handler MPI_ERRORS_RETURN to make error values actually get returned to you instead of just nuking everything. and note that MPI does not guarantee a program can continue past an error β however, MPI implementations will attempt to continue whenever possible. π«
here are the error codes, and what they're giving:
MPI_SUCCESSβ no error, the MPI routine completed successfully. the dream. β¨MPI_ERR_ARGβ invalid argument. some argument is invalid and doesn't get caught by a more specific error class (likeMPI_ERR_RANK).MPI_ERR_BUFFERβ invalid buffer pointer. usually a null buffer where one isn't valid bestie, c'mon.MPI_ERR_COMMβ invalid communicator. a very common oopsie is using a null communicator in a call (which isn't even allowed inMPI_Comm_rank).MPI_ERR_COUNTβ invalidcountargument. counts must be non-negative; a count of zero is often valid though, so don't panic.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. (yes, "the the", the manpage said it, we're keeping it, it's canon now π)MPI_ERR_TYPEβ invalid datatype argument. also, this error can occur if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. commit your types, bestie. πMPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code.
and that's the whole page π₯Ή you ate that. go forth and sendrecv-replace nonblockingly, you absolute legend.
signing off with love: this was the MPI manual page, dated 4/10/2026 β mwah π
π¦ 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