MPI_Reduce_scatter(3)

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

πŸ’– NAME πŸ’–

MPI_Reduce_scatter β€” bestie, it combines values and scatters the results. Like a group project where everyone brings their piece, everything gets mashed together, and then the finished thing gets handed back out in slices. Iconic behavior, honestly.

This is part of the MPI manual, so if you were looking for the one about wildly scattering your feelings, wrong page, but we can work with this one.


✨ SYNOPSIS ✨

int MPI_Reduce_scatter(const void *sendbuf, void *recvbuf,
const int recvcounts[], MPI_Datatype datatype, MPI_Op op,
MPI_Comm comm)

int MPI_Reduce_scatter_c(const void *sendbuf, void *recvbuf,
const MPI_Count recvcounts[], MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm)

Two flavors, same energy. One takes the classic int counts, one takes the big-girl MPI_Count counts for when your numbers are, like, a lot. 🫢


🌸 INPUT PARAMETERS 🌸

  • sendbuf β€” starting address of send buffer (choice). This is where your contribution lives, bestie. Choice means the implementation picks the type, not you.
  • recvcounts β€” non-negative integer array (of length group size) specifying the number of elements of the result distributed to each process. (non-negative integer). So yes, one count per process in the group, and no, you can't be negative about it. Lowkey important: it needs to be exactly group size long.
  • datatype β€” data type of elements of send and receive buffers (handle). It's giving "tell me what I'm actually moving around here."
  • op β€” operation (handle). The glow-up move that gets applied to combine everything.
  • comm β€” communicator (handle). Your little group chat of processes.

πŸŽ€ OUTPUT PARAMETERS πŸŽ€

  • recvbuf β€” starting address of receive buffer (choice). Your slice of the finished result lands right here. Slay. πŸ’…

πŸ’… NOTES ON COLLECTIVE OPERATIONS πŸ’…

Okay so this part is real talk. The reduction functions (MPI_Op) do not return an error value. Not me being dramatic β€” that's literally how it works. So if these functions detect an error, all they can do is either call MPI_Abort or silently skip the problem. That's it. That's the whole toolkit. 😭

Which means: 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. Read that again. You asked for errors back and you might just get nothing. Vibe check failed, but quietly.

The reason for this is the performance problems in ensuring that all collective routines return the same error value. They traded pedantic error reporting for speed, and honestly? Fair.


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

This routine is thread-safe. Meaning you can have multiple threads calling it without needing any user-provided thread locks β€” go off, multi-threaded queen. 🧚

However, 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 thread-safe yes, interrupt-safe no, keep those two separate in your notes, bestie.


🌈 NOTES FOR FORTRAN 🌈

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. It's the Fortran bestie's version of a return value, just chilling at the end of the args.

In Fortran, MPI routines are subroutines, and are invoked with the call statement. (Yes, call. Old school and unbothered.)

All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. Not handles, not pointers, just INTEGER. Periodt.


πŸ‘‘ 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 the value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job β€” yes, the whole thing, no warning shot. πŸ’€

The error handler may 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, unless you're feeling nostalgic for legacy code, in which case, we've all been there.

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 it's giving "we'll try our best" and honestly, same.

Here's the error lineup, bestie:

  • MPI_SUCCESS β€” No error; MPI routine completed successfully. The dream. ✨
  • MPI_ERR_BUFFER β€” Invalid buffer pointer. Usually a null buffer where one is not valid. Like showing up to the function with nothing in your hands.
  • MPI_ERR_COMM β€” Invalid communicator. A common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank). Not even in MPI_Comm_rank, y'all. The bar is on the floor.
  • MPI_ERR_COUNT β€” Invalid count argument. Count arguments must be non-negative; a count of zero is often valid. So zero? fine. Negative? absolutely 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 making up your own vibe from nothing.
  • 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, bestie, or they won't commit to you. πŸ“
  • MPI_ERR_OTHER β€” Other error; use MPI_Error_string to get more information about this error code. The catch-all. The "we don't know her either, go ask MPI_Error_string."

And that's the whole page!! πŸ’– Keep your counts non-negative, keep your datatypes committed, and remember that collectives will absolutely humble you with silent error skipping. This was page MPI_Reduce_scatter(3) from the MPI manual, dated 4/10/2026 β€” go forth and scatter, you main character. πŸ‘‘πŸŒˆ

πŸ“¦ where this page comes from