MPI_Reduce(3)

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

πŸ’– 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_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is 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 call statement. periodt.
  • all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in 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 in MPI_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 type MPI_Op) must either be one of the predefined operations (e.g., MPI_SUM) or created with MPI_Op_create. no homemade ops that skipped the process πŸŽ€
  • 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. commit your types first, bestie, like commit to the bit πŸ’…
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to 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