MPI_Reduce_init(3)
π MPI_Reduce_init(3) β the MPI manual, but make it cute π
okay bestie, welcome to MPI_Reduce_init from the MPI manual page family π«Ά this one is giving "set it up once, vibe forever" energy and honestly? iconic.
β¨ NAME β¨
MPI_Reduce_init β Create a persistent request for reduce π
πΈ SYNOPSIS πΈ
int MPI_Reduce_init(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm,
MPI_Info info, MPI_Request *request)
int MPI_Reduce_init_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm,
MPI_Info info, MPI_Request *request)
so there's the classic C one and then MPI_Reduce_init_c which is the same thing but the count is an MPI_Count instead of an int, because sometimes you have BIG numbers of elements and the plain int said "not me, I can't" π
π INPUT PARAMETERS π
the stuff you gotta hand over, bestie:
sendbufβ address of send buffer (choice) π€countβ number of elements in send buffer (non-negative integer) π’datatypeβ data type of elements of send buffer (handle) π·οΈopβ reduce operation (handle) βrootβ rank of root process (integer) πcommβ communicator (handle) π‘infoβ info argument (handle) π
π OUTPUT PARAMETERS π
the stuff it hands back to you:
recvbufβ address of receive buffer (choice) π₯requestβ communication request (handle) ποΈ
π§΅ THREAD AND INTERRUPT SAFETY π§΅
good news first: 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 user-provided thread locks. no babysitting required, she's self-sufficient π
bad news: the routine is not interrupt safe π and typically that's because of memory allocation routines like malloc, or other non-MPICH runtime routines, which are themselves not interrupt-safe. so like. it's not her fault fr fr, it's the company she keeps π
π¦ NOTES FOR FORTRAN π¦
Fortran besties, listen up π’ β all MPI routines in Fortran have an extra argument called ierr tacked onto the end of the argument list, except for MPI_WTIME and MPI_WTICK. ierr is an integer and it means exactly the same thing as the return value of the routine in C. and in Fortran, MPI routines are subroutines, invoked with the call statement, periodt.
also: all MPI objects (like MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. that's just the rules π
π ERRORS π
okay so, all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β C routines as the value of the function, Fortran routines in that last argument. and before the value comes back to you, the current MPI error handler gets called. by default that error handler aborts the MPI job π so yeah, dramatic.
you can switch the error handler with MPI_Comm_set_errhandler (for communicators), MPI_File_set_errhandler (for files), and MPI_Win_set_errhandler (for RMA windows). there's also the MPI-1 routine MPI_Errhandler_set, which may be used but its use is deprecated π« (old, tired, let her rest). and the predefined error handler MPI_ERRORS_RETURN can be used to make error values get returned instead.
real talk though: MPI does not guarantee that an MPI program can continue past an error. however, MPI implementations will attempt to continue whenever possible π«Ά
now the error codes, one by one:
MPI_SUCCESSβ No error; MPI routine completed successfully. π slay.MPI_ERR_ARGβ Invalid argument. Some argument is invalid and is not identified by a specific error class (e.g.,MPI_ERR_RANK). π€¨MPI_ERR_BUFFERβ Invalid buffer pointer. Usually a null buffer where one is not valid. πMPI_ERR_COMMβ Invalid communicator. A common error is to use a null communicator in a call (not even allowed inMPI_Comm_rank). π΅MPI_ERR_COUNTβ Invalid count argument. Count arguments must be non-negative; a count of zero is often valid. π’MPI_ERR_INFOβ Invalid Info. πMPI_ERR_OPβ Invalid operation. MPI operations (objects of typeMPI_Op) must either be one of the predefined operations (e.g.,MPI_SUM) or created withMPI_Op_create. β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. π
that's the whole page bestie, you ate this π β¨
signed off from the MPI manual, page dated 4/10/2026, filed under MPI_Reduce_init(3) β mwah, go forth and reduce responsively πππ¦
π¦ 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