MPI_Reduce_scatter_init(3)

๐Ÿ“ฆ
version 5.0.1 ยท 5 versions
, in nixos 26.05, ubuntu stonking

โœจ MPI_Reduce_scatter_init โœจ

okay bestie, so this is a page from the MPI manual (that's the Message Passing Interface, the whole "many computers pretending to be one brain" situation ๐Ÿ’…), and we're gonna talk about MPI_Reduce_scatter_init.

๐ŸŽ€ NAME ๐ŸŽ€

MPI_Reduce_scatter_init โ€” create a persistent request for reduce_scatter.

like, you know how a regular reduce_scatter is a whole thing you do over and over in a loop and it keeps re-doing all the setup? yeah. this one sets it up once and hands you a request you can fire off again and again. iconic behavior honestly. ๐Ÿ”ฅ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

int MPI_Reduce_scatter_init(const void *sendbuf, void *recvbuf,
const int recvcounts[], MPI_Datatype datatype,
MPI_Op op, MPI_Comm comm, MPI_Info info,
MPI_Request *request)

int MPI_Reduce_scatter_init_c(const void *sendbuf, void *recvbuf,
const MPI_Count recvcounts[],
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
MPI_Info info, MPI_Request *request)

two versions bestie โ€” the classic one and the _c one with big boi MPI_Count counts. both valid, both slaying. โœจ


๐ŸŒธ INPUT PARAMETERS ๐ŸŒธ

  • sendbuf โ€” the starting address of the send buffer. it's a choice, so you get options. (look at you having options ๐Ÿ’…)
  • recvcounts โ€” a non-negative integer array that says how many elements of the result each process gets. it's giving "we divided the vibes up equally-ish". โš ๏ธ this array must be identical on all calling processes โ€” no cap, everyone has to agree or it's chaos.
  • datatype โ€” the data type of the elements in the input buffer (a handle).
  • op โ€” the operation you're doing (a handle).
  • comm โ€” the communicator (a handle).
  • info โ€” the info argument (a handle).

๐Ÿ’– OUTPUT PARAMETERS ๐Ÿ’–

  • recvbuf โ€” the starting address of the receive buffer (again, a choice).
  • request โ€” the communication request (a handle). hold onto this one, it's your little persistent ticket. ๐ŸŽŸ๏ธ

๐Ÿงš THREAD AND INTERRUPT SAFETY ๐Ÿงš

this routine is thread-safe. meaning: multiple threads can call it at the same time and you do not need to bring your own thread locks. she handles herself. ๐Ÿ’โ€โ™€๏ธ

however โ€” and this is the important part bestie โ€” the routine is not interrupt safe. ๐Ÿšจ typically this is because it uses memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, don't be interrupting her mid-alloc. ๐Ÿ™ˆ


๐Ÿ”ฎ NOTES FOR FORTRAN ๐Ÿ”ฎ

so in Fortran, all MPI routines (except MPI_WTIME and MPI_WTICK) get an extra argument ierr tacked onto the end of the argument list. ierr is an integer, and it means the exact same thing as the return value of the routine in C.

also in Fortran, MPI routines are subroutines and they're invoked with the call statement. very retro, very demure. ๐ŸŽ€

and! all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. that's just the way it is. โญ


๐Ÿ’€ ERRORS ๐Ÿ’€

okay so every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value โ€” C routines return it as the value of the function, and Fortran routines put it in that last argument. before the value comes back, the current MPI error handler gets called. by default, that error handler aborts the MPI job. like, full stop, everyone out of the pool. ๐Ÿ˜ญ

you can change the error handler 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 heads up โ€” its use is deprecated. โš ๏ธ the predefined error handler MPI_ERRORS_RETURN may be used to make error values get returned instead.

note that MPI does not guarantee an MPI program can continue past an error. however, MPI implementations will attempt to continue whenever possible. so like... fingers crossed ๐Ÿคž

here's the error roster, all of them, no skips:

  • MPI_SUCCESS โ€” no error; MPI routine completed successfully. we love a happy ending. ๐Ÿซถ
  • MPI_ERR_ARG โ€” invalid argument. some argument is invalid and isn't identified by a specific error class (e.g., MPI_ERR_RANK).
  • MPI_ERR_BUFFER โ€” invalid buffer pointer. usually a null buffer where one isn't valid. ๐Ÿ’€
  • MPI_ERR_COMM โ€” invalid communicator. a common one is using a null communicator in a call (which is 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_INFO โ€” invalid Info.
  • 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.

that's literally the whole page bestie, you ate it up. now go make a persistent request and be the main character of your own communicator. ๐ŸŒˆ๐Ÿ‘‘

โœง๏ฝฅ๏พŸ: โœง๏ฝฅ๏พŸ:

signing off from the MPI manual, dated 4/10/2026, page MPI_Reduce_scatter_init(3) โ€” mwah, love u, bye ๐Ÿ“๐Ÿ’œ

๐Ÿ“ฆ where this page comes from