MPI_Reduce(3)
π MPI_Reduce(3) β the MPI manual, but make it cute π
okay bestie, welcome to the MPI manual page for MPI_Reduce. Yes this is really from the MPI manual and yes it is dated MPI_Reduce(3) at the top, we are doing this together, grab a boba π§
β¨ NAME β¨
MPI_Reduce β reduces values on all processes down to a single value π
it's giving "everyone shouts their number, one person adds them all up" energy fr fr
π SYNOPSIS π
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
int MPI_Reduce_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
two versions, two vibes, the _c one just uses MPI_Count for the count because sometimes your count is big big π
π INPUT PARAMETERS π
sendbufβ address of send buffer (choice). that's your little contribution to the group project πcountβ number of elements in the send buffer (non-negative integer). no negative counts, that's not the vibe, ok?? π«datatypeβ data type of the elements of the send buffer (handle) πopβ reduce operation (handle). like, what are we doing to these numbers πrootβ rank of the root process (integer). the main character of this operation πcommβ communicator (handle) π«
π OUTPUT PARAMETERS π
recvbufβ address of receive buffer (choice). only the root ends up with the goodies here, everyone else just sends and goes about their day π
π NOTES ON COLLECTIVE OPERATIONS π
okay so this is the part you NEED to know, no cap:
the reduction functions (MPI_Op) do not return an error value. so if those functions detect an error, literally all they can do is either call MPI_Abort or silently skip the problem π which is such a jump-scare behaviour, I know.
so lowkey β if you change the error handler from MPI_ERRORS_ARE_FATAL to something else, for example MPI_ERRORS_RETURN, then no error may be indicated. like, none. nothing. silence. bestie you will not be told π
the reason for this is the performance problems in ensuring that all collective routines return the same error value. so it's not a bug, it's a tradeoff, and the tradeoff is your peace of mind πΈ
π§ THREAD AND INTERRUPT SAFETY π§
good news: this routine is thread-safe β¨ that means you can safely use it from multiple threads without any user-provided thread locks. no mutexes needed, we're just built different π
bad news: the routine is not interrupt safe π«β‘ typically this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, don't interrupt it mid-glow-up π
πΈ NOTES FOR FORTRAN πΈ
calling all 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 are invoked with the
callstatement. periodt. - all MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin Fortran. iconic, honestly β
π₯ ERRORS π₯
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 is returned, the current MPI error handler is called. by default, this error handler aborts the MPI job π dramatic but true.
the error handler may be changed 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 π΅ (we don't do that anymore, bestie).
the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned. 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, they'll try their best π₯Ί
here's the whole error code lineup:
MPI_SUCCESSβ no error; MPI routine completed successfully. the slay outcome β¨MPI_ERR_BUFFERβ invalid buffer pointer. usually a null buffer where one is not valid. not the vibe π«MPI_ERR_COMMβ invalid communicator. a common error is to use a null communicator in a call (not even allowed inMPI_Comm_rank). so don't π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_OPβ invalid operation. MPI operations (objects of typeMPI_Op) must either be one of the predefined operations (e.g.,MPI_SUM) or created withMPI_Op_create. no homemade ops that skipped the process πMPI_ERR_TYPEβ invalid datatype argument. additionally, this error can occur if an uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call. commit your types first, bestie, like commit to the bit πMPI_ERR_OTHERβ other error; useMPI_Error_stringto get more information about this error code π
π sign-off π
okay that's the whole page, you ate that π½οΈβ¨ this was MPI_Reduce(3) from the MPI manual, version stamped 4/10/2026 β so like, keep this date in your notes because some of us are still reading the 2026 docs and that's just the reality π
go reduce something. slay. ππ¦π
π¦ 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