MPI_Scatter(3)
π 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_WTIMEandMPI_WTICK) has an extra argumentierrtacked on at the end of the argument list π ierris 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
callstatement π - all MPI objects (like
MPI_Datatype,MPI_Comm) are of typeINTEGERin 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 inMPI_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 uncommittedMPI_Datatype(seeMPI_Type_commit) gets used in a communication call π¦MPI_ERR_OTHERβ other error; useMPI_Error_stringto 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
- 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