MPI_Gather(3)
π 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, iykykrecvtypeβ 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 inMPI_Comm_rank). literally not even allowed, bestieMPI_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 uncommittedMPI_Datatype(seeMPI_Type_commit) is used in a communication call.MPI_ERR_OTHERβ other error; useMPI_Error_stringto 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
- 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