MPI_Reduce_scatter_block(3)

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

πŸ’– MPI_Reduce_scatter_block β€” bestie edition πŸ’–

okay so this is a page from the MPI manual, section 3 (MPI_Reduce_scatter_block(3), hi πŸ‘‹), and it's about one of those collective calls that does two things at once because apparently one thing was not enough for her πŸ’…


✨ NAME ✨

MPI_Reduce_scatter_block β€” combines values and scatters the results 🫢


🌸 SYNOPSIS 🌸

int MPI_Reduce_scatter_block(const void *sendbuf, void *recvbuf, int recvcount,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
int MPI_Reduce_scatter_block_c(const void *sendbuf, void *recvbuf,
MPI_Count recvcount, MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm)

πŸŽ€ INPUT PARAMETERS πŸŽ€

  • sendbuf β€” the starting address of the send buffer (choice). it's giving "here's my stuff, do something with it" ✨
  • recvcount β€” element count per block, and she must be a non-negative integer, no exceptions, we do not do negative counts here 🚫
  • datatype β€” the data type of the elements in the send and receive buffers (handle)
  • op β€” the operation (handle)
  • comm β€” the communicator (handle)

πŸ’œ OUTPUT PARAMETERS πŸ’œ

  • recvbuf β€” the starting address of the receive buffer (choice)

πŸ”₯ NOTES ON COLLECTIVE OPERATIONS πŸ”₯

so this is the part where it gets real. the reduction functions (MPI_Op) do not return an error value. like, at all. nope. πŸ™ˆ

which means if those functions detect an error, all they can do is either call MPI_Abort or silently skip the problem 😭 bestie. silently. skipping.

so if you change the error handler from MPI_ERRORS_ARE_FATAL to literally anything else β€” for example MPI_ERRORS_RETURN β€” then no error may be indicated. you just... won't know. it's giving mystery πŸ’€

and the reason for this whole situation? performance problems with making sure all collective routines return the same error value. so basically it's a trade-off and we live with it ✨


πŸ¦‹ THREAD AND INTERRUPT SAFETY πŸ¦‹

this routine is thread-safe πŸŽ‰ which means you can safely use it from multiple threads and you do not need any user-provided thread locks. she handles herself. main character energy πŸ‘‘

however β€” and this is the important bit β€” the routine is not interrupt safe. typically this is because of memory allocation routines like malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so like. she's safe from threads but not from interruptions. pick your battles πŸ’…


🌈 NOTES FOR FORTRAN 🌈

all MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK, they're the special little exceptions 🧚) have an additional argument called ierr at 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. no cap.

in Fortran, MPI routines are subroutines, and you invoke them with the call statement. that's just how it is ✨

and every MPI object (e.g. MPI_Datatype, MPI_Comm) is 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 that last argument. before the value is returned, the current MPI error handler gets called. by default, this error handler aborts the MPI job 😳 so yeah, dramatic.

the error handler can be changed with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). the MPI-1 routine MPI_Errhandler_set may be used, but its use is deprecated 🚩 so maybe don't, 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 🫢

here's the full roster of error codes, no skips:

  • MPI_SUCCESS β€” no error; the MPI routine completed successfully πŸŽ‰
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid. rude.
  • MPI_ERR_COMM β€” invalid communicator. a common one is using a null communicator in a call (not even allowed in MPI_Comm_rank 😭)
  • MPI_ERR_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid ✨
  • 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.
  • 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.

πŸ’‘ quick vibe check: MPI_ERR_TYPE and the ones above it are all just chillin' in the same list, so don't stress about the spacing, she's fine.

and that's the whole page, bestie, you ate it πŸ’…βœ¨ this edition of the MPI manual (MPI_Reduce_scatter_block(3)) is dated 4/10/2026 β€” go forth and scatter, but like, responsibly πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from