MPI_Reduce_scatter_block(3)
π 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 inMPI_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 typeMPI_Op) must either be one of the predefined operations (e.g.MPI_SUM) or created withMPI_Op_create.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.
π‘ 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
- 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