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, or MPI_ANY_SOURCE if you're in your "I'll take whoever" era (integer)
  • recvtag β€” the message tag on the receive side, or MPI_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 ierr tacked onto the end of the argument list β€” the only exceptions are MPI_WTIME and MPI_WTICK. (they're special. they know it. πŸ’…)
  • ierr is 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 call statement.
  • all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in 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 communicators
  • MPI_File_set_errhandler β€” for files
  • MPI_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 (like MPI_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 in MPI_Comm_rank).
  • MPI_ERR_COUNT β€” invalid count argument. 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 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. (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 uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call. commit your types, bestie. πŸ’…
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to 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