MPI_Sendrecv_replace(3)
π 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, orMPI_ANY_SOURCE. integer πrecvtagβ the receive message tag, orMPI_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. typeStatusβ
π§ 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 inMPI_Comm_rank. yeah, that strict. πMPI_ERR_COUNTβ invalidcountargument. 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 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. 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
- 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