MPI_Allgather(3)

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

✨ MPI_Allgather(3) ✨

okay bestie, welcome to the MPI girlies manual page for MPI_Allgather. sit down, grab a boba, we're doing collective communication πŸ’–


🌸 NAME 🌸

MPI_Allgather β€” gather all the data from every task, then hand the combined lil pile back to every task. no cap, everybody gets everything. it's giving "no secrets in this friend group" 🫢


✨ SYNOPSIS ✨

int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype,
MPI_Comm comm)

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

πŸ’Œ INPUT PARAMETERS πŸ’Œ

  • sendbuf β€” the starting address of your send buffer (choice). this is what you're offering to the group chat.
  • sendcount β€” how many elements are chillin' in the send buffer. must be a non-negative integer, so no negative vibes pls πŸ™…
  • sendtype β€” the data type of the send buffer elements (handle).
  • recvcount β€” how many elements you receive from any process (non-negative integer, bestie, keep it positive or zero).
  • recvtype β€” the data type of the receive buffer elements (handle).
  • comm β€” the communicator (handle). it's the group chat itself, iykyk.

πŸŽ€ OUTPUT PARAMETERS πŸŽ€

  • recvbuf β€” address of the receive buffer (choice). this is where the whole squad's data lands πŸ‘‘

πŸ“ NOTES πŸ“

so the MPI standard (versions 1.0 and 1.1) says this:

The jth block of data sent from each process is received by every process and placed in the jth block of the buffer recvbuf.

and like… it's misleading, bestie. a better way to say it is:

The block of data sent from the jth process is received by every process and placed in the jth block of the buffer recvbuf.

see the difference? the first one makes it sound like every process sends the "jth block" β€” no ma'am. it's the block from the jth process. this clarification was suggested by Rajeev Thakur and the MPI Forum adopted it as an official clarification. we love a glow-up ✨


🧡 THREAD AND INTERRUPT SAFETY 🧡

this routine is thread-safe. that means multiple threads can use it at the same time, no user-provided thread locks needed. slay πŸ’…

however β€” and this is the important part β€” the routine is NOT interrupt safe. typically that's because it uses memory allocation routines like malloc, or other non-MPICH runtime routines that are themselves not interrupt-safe. so yeah, don't interrupt it, she's busy 😭


πŸ¦‹ NOTES FOR FORTRAN πŸ¦‹

every MPI routine in Fortran (except for MPI_WTIME and MPI_WTICK) has an extra argument called ierr glued onto 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 call them with the call statement. periodt.

also! all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. πŸ’œ


πŸ’€ ERRORS πŸ’€

every MPI routine (except MPI_Wtime and MPI_Wtick) returns an error value β€” C routines return it as the function's value, 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, end of story, everyone out the group chat. 😭

the error handler can be changed 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 may be used but its use is deprecated (we don't do that anymore bestie).

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 keep going after an error; however, MPI implementations will attempt to continue whenever possible. optimistic queens 🌈

here's the error list:

  • MPI_SUCCESS β€” no error; the MPI routine completed successfully. we love a happy ending πŸ₯°
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where null is not valid. she's not there, bestie.
  • MPI_ERR_COMM β€” invalid communicator. a 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. count arguments must be non-negative; a count of zero is often valid, so don't panic.
  • MPI_ERR_TYPE β€” invalid datatype argument. also, this error can pop up if an uncommitted MPI_Datatype (see MPI_Type_commit) is used in a communication call. commit your types first, girl πŸ’…
  • MPI_ERR_OTHER β€” other error; use MPI_Error_string to get more info about this error code.

and that's the whole page, bestie! you ate that. go forth and allgather your lil heart out πŸ‘‘πŸ’–

this was brought to you by the MPI manual, dated 4/10/2026 β€” MPI_Allgather(3), and yes, the number in the parens means it's a library call. iconic behavior fr fr πŸŽ€βœ¨

πŸ“¦ where this page comes from