MPI_Gather(3)

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

πŸ’– MPI_Gather(3) πŸ’–

okay so bestie, welcome to the gather page β€” it's from the MPI manual, section 3, and it's literally the moment every process in your communicator hands over their lil values so one special process can hold them all. group chat energy but for data. slay.


✨ NAME ✨

MPI_Gather β€” gathers together values from a group of processes 🫢


✨ SYNOPSIS ✨

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

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

yes there are two of them, one is the classic and one is the big-count _c variant, both iconic πŸ’…


🌸 INPUT PARAMETERS 🌸

  • sendbuf β€” starting address of send buffer (choice). it's giving "here's my contribution bestie"
  • sendcount β€” number of elements in send buffer (non-negative integer), so no negative vibes allowed 🚫
  • sendtype β€” data type of send buffer elements (handle)
  • recvcount β€” number of elements for any single receive (non-negative integer) β€” note it's per-single-receive, not the grand total, iykyk
  • recvtype β€” data type of recv buffer elements (handle)
  • root β€” rank of receiving process (integer) β€” this is the main character who gets everything πŸ‘‘
  • comm β€” communicator (handle)

πŸŽ€ OUTPUT PARAMETERS πŸŽ€

  • recvbuf β€” address of receive buffer (choice)

🧚 THREAD AND INTERRUPT SAFETY 🧚

this routine is thread-safe, periodt. that means it can safely be used by multiple threads at the same time, no user-provided thread locks needed, you can just go πŸ¦‹

but β€” and this is the lowkey 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 don't be out here interrupting it mid-alloc, bestie 😭


πŸ’œ NOTES FOR FORTRAN πŸ’œ

all MPI routines in Fortran (except for MPI_WTIME and MPI_WTICK) have an extra argument ierr tacked on 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. also, in Fortran, MPI routines are subroutines and you invoke them with the call statement.

all MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. yes, everything. one type. commitment. ✨


πŸ’€ ERRORS πŸ’€

every MPI routine (except MPI_Wtime and MPI_Wtick, the two little rebels) returns an error value β€” C routines as the value of the function, Fortran routines in that last argument. before the value comes back, the current MPI error handler gets called. by default, this error handler aborts the MPI job 😭 so like, no cap, that's the default behavior.

the error handler can 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 β€” don't do it, it's giving 1994.

the predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned instead. and note: MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible. so like... crossing fingers 🀞

  • MPI_SUCCESS β€” no error; MPI routine completed successfully. the dream scenario 🌈
  • MPI_ERR_BUFFER β€” invalid buffer pointer. usually a null buffer where one is not valid. (null buffer? in this economy? πŸ™ˆ)
  • MPI_ERR_COMM β€” invalid communicator. a common error is to use a null communicator in a call (not even allowed in MPI_Comm_rank). literally not even allowed, bestie
  • MPI_ERR_COUNT β€” invalid count argument. count arguments must be non-negative; a count of zero is often valid.
  • 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.

fr fr the one thing to remember: send your stuff, root collects it all, and if you skipped MPI_Type_commit you're gonna have a bad time πŸ’…

okay that's the whole page bestie, you're so ready for this gather. mwah πŸ«ΆπŸ’–βœ¨

this little cutie comes from the MPI manual, dated 4/10/2026, and it's page MPI_Gather(3) β€” go be the root of your own destiny, queen πŸ‘‘πŸŒΈ

πŸ“¦ where this page comes from