MPI_Scatter(3)

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

πŸ’Œ MPI_Scatter(3) β€” the MPI manual, but make it make sense

okay bestie, welcome to the MPI manual section for MPI_Scatter(3) ✨ yes it's a section 3 page, yes it's the MPI docs, yes we're doing this together πŸ’–


🌸 NAME 🌸

MPI_Scatter β€” sends data from one process to all other processes in a communicator πŸ“€βž‘οΈπŸ‘―β€β™€οΈ

like... one process has the goods, and everybody else gets their lil share. iconic distribution behavior, no cap.


✨ SYNOPSIS ✨

int MPI_Scatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, int root,
MPI_Comm comm)
int MPI_Scatter_c(const void *sendbuf, MPI_Count sendcount,
MPI_Datatype sendtype, void *recvbuf, MPI_Count recvcount,
MPI_Datatype recvtype, int root, MPI_Comm comm)

two flavors, same vibe πŸ’… the _c one is the big-count girlie version.


🧚 INPUT PARAMETERS 🧚

  • sendbuf β€” the address of the send buffer, it's a choice type (handle-ish situation) πŸŽ€
  • sendcount β€” how many elements get sent to each process, non-negative integer so like, zero is fine but negative is NOT the move 😭
  • sendtype β€” the data type of the elements chillin' in the send buffer (handle) πŸ¦‹
  • recvcount β€” how many elements live in the receive buffer, also a non-negative integer πŸ’«
  • recvtype β€” the data type of the receive buffer elements (handle) 🌈
  • root β€” the rank of the sending process, an integer. she's the main character feeding everyone else πŸ‘‘
  • comm β€” the communicator (handle), aka the group chat everyone's in πŸ’¬

πŸ’ OUTPUT PARAMETERS πŸ’

  • recvbuf β€” the address of the receive buffer (choice) 🫢 this is where your slice lands, bestie

πŸ”’ THREAD AND INTERRUPT SAFETY πŸ”’

this routine is thread-safe 🧡✨ which means multiple threads can use it at the same time and you do NOT need to bring your own thread locks. she handles it. periodt.

BUT β€” and this is the important part β€” the routine is not interrupt safe 🚨 typically that's because of memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so like, don't be messy with interrupts, okay? πŸ™ˆ


πŸŽ€ NOTES FOR FORTRAN πŸŽ€

  • every MPI routine in Fortran (except MPI_WTIME and MPI_WTICK) has an extra argument ierr tacked on at the end of the argument list πŸ“Ž
  • ierr is an integer and it means the same thing as the return value of the routine in C
  • in Fortran, MPI routines are subroutines and you invoke them with the call statement πŸ“ž
  • all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran πŸ’œ

πŸ’€ ERRORS πŸ’€

so every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β€” C routines as the function's return value, Fortran routines in that last argument 🫠 before that value comes back to you, the current MPI error handler gets called. by default, that error handler aborts the MPI job 😭 so yeah, she's dramatic by default.

you can swap the error handler 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 also exists but its use is deprecated 🚫 don't do it, that's old news.

the predefined error handler MPI_ERRORS_RETURN can be used to make error values actually get returned.

heads up: MPI does not guarantee that an MPI program can continue past an error 😬 that said, MPI implementations will attempt to continue whenever possible. so like, fingers crossed energy 🀞

here's the error code lineup:

  • MPI_SUCCESS β€” no error, the routine completed successfully. slay πŸ’š
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid πŸ™ƒ
  • MPI_ERR_COMM β€” invalid communicator. a very common oopsie is using a null communicator in a call β€” which isn't even allowed in MPI_Comm_rank πŸ’€
  • MPI_ERR_COUNT β€” invalid count argument. counts must be non-negative; a count of zero is often valid πŸ“
  • MPI_ERR_TYPE β€” invalid datatype argument. also, this can pop off if an uncommitted MPI_Datatype (see MPI_Type_commit) gets used in a communication call πŸ¦‹
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more info about this error code πŸ’«

and that's the whole page bestie, every flag, every error, every lil Fortran footnote, all of it 🫢 go forth and scatter πŸ’…

this lil masterpiece is from the MPI manual, page MPI_Scatter(3), dated 4/10/2026 πŸ“…βœ¨ catch you in the SEE ALSO section of your heart 🌈

πŸ“¦ where this page comes from