MPI_Sendrecv_replace(3)

πŸ“¦
version 5.0.1 Β· 5 versions
, in nixos 26.05, ubuntu stonking

πŸ’– MPI_Sendrecv_replace(3) β€” the MPI manual, bestie edition πŸ’–

okay so this is a page from the MPI manual, and honestly? it's giving "one buffer, two jobs, zero drama." stay with me.


✨ NAME ✨

MPI_Sendrecv_replace β€” sends and receives using a single buffer πŸŽ€

like... you send AND you receive, and it all happens in the same buffer. one buffer. main character energy. periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

int MPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype, int dest,
int sendtag, int source, int recvtag, MPI_Comm comm,
MPI_Status *status)

int MPI_Sendrecv_replace_c(void *buf, MPI_Count count, MPI_Datatype datatype,
int dest, int sendtag, int source, int recvtag,
MPI_Comm comm, MPI_Status *status)

two flavors, same vibe ✨ β€” the _c one is just the big-count version, iykyk.


🌸 INPUT PARAMETERS 🌸

  • count β€” how many elements are chillin' in the send and receive buffer. it's a non-negative integer, so like, no negativity allowed bestie πŸ™ˆ
  • datatype β€” the type of the elements in the send and receive buffer. it's a handle 🫢
  • dest β€” rank of the destination. an integer πŸ’…
  • sendtag β€” the send message tag. also an integer ✨
  • source β€” rank of the source, or MPI_ANY_SOURCE. integer πŸ’–
  • recvtag β€” the receive message tag, or MPI_ANY_TAG. integer πŸŽ€
  • comm β€” the communicator. a handle 🌈

πŸ’œ INPUT/OUTPUT PARAMETERS πŸ’œ

  • buf β€” initial address of the send and receive buffer. it's a choice 🌟 (both jobs, one address, obsessed)

πŸ‘‘ OUTPUT PARAMETERS πŸ‘‘

  • status β€” the status object. type Status ⭐

🧚 THREAD AND INTERRUPT SAFETY 🧚

this routine is thread-safe. and what that actually means: multiple threads can use it safely with no user-provided thread locks needed. you don't have to do anything, it just handles it. slay. πŸ’…

BUT. it is not interrupt safe. 😭 typically that's because of memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, not her fault, it's the company she keeps. πŸ’€


🌈 NOTES FOR FORTRAN 🌈

every MPI routine in Fortran (except for MPI_WTIME and MPI_WTICK) gets an extra argument called ierr tacked onto the end of the argument list. ierr is an integer and it means exactly the same thing as the return value of the routine in C. 🫢

in Fortran, MPI routines are subroutines and you invoke them with the call statement. no cap.

also: all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. ✨


πŸ’€ ERRORS πŸ’€

okay so here's the deal: all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value. C routines return it as the value of the function; Fortran routines put it in that last argument. πŸŽ€

before that value comes back to you, the current MPI error handler gets called. and by default? that error handler aborts the MPI job. yes, literally ends it. 😭

you can swap 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, so like... why would you πŸ™ˆ

you can also use the predefined error handler MPI_ERRORS_RETURN to make error values get returned to you instead. note that MPI does not guarantee an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. best effort, bestie 🫢

here's the full error roster:

  • MPI_SUCCESS β€” no error, the MPI routine completed successfully. the ideal outcome, the dream, the moment ✨
  • MPI_ERR_ARG β€” invalid argument. some argument is invalid and it's not identified by a specific error class (e.g. MPI_ERR_RANK). mystery problem, iconic πŸ’…
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid. πŸ™ˆ
  • MPI_ERR_COMM β€” invalid communicator. a common one is using a null communicator in a call β€” which is not even allowed in MPI_Comm_rank. yeah, that strict. πŸ’€
  • MPI_ERR_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid. zero is fine, negative is not. πŸŽ€
  • 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. the catch-all, the wildcard, the "it's giving mysterious" 😭

reminder bestie: that default error handler aborts the whole MPI job. not a vibe. set MPI_ERRORS_RETURN if you want to actually handle things. 🫢

and that's the whole page, no notes, no skips, every single flag and error code present and accounted for πŸ’…βœ¨

this was MPI_Sendrecv_replace(3) from the MPI manual, dated 4/10/2026 🌸 β€” love u, go forth and replace your buffers, mwah πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from