MPI_Allreduce_init(3)

✨ MPI_Allreduce_init ✨

okay bestie so this is a page from the MPI manual β€” the C one, MPI_Allreduce_init(3) β€” and it's literally about creating a persistent request for allreduce. πŸ’–


🌸 NAME 🌸

MPI_Allreduce_init β€” Create a persistent request for allreduce 🫢


πŸ’… SYNOPSIS πŸ’…

int MPI_Allreduce_init(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
MPI_Info info, MPI_Request *request)

int MPI_Allreduce_init_c(const void *sendbuf, void *recvbuf, MPI_Count count,
MPI_Datatype datatype, MPI_Op op, MPI_Comm comm,
MPI_Info info, MPI_Request *request)

πŸŽ€ INPUT PARAMETERS πŸŽ€

okay so these are the things you hand in, no take-backs:

  • sendbuf β€” starting address of send buffer (choice) πŸ“€
  • count β€” number of elements in send buffer (non-negative integer, so like… zero or more, no negativity allowed) πŸ”’
  • datatype β€” data type of elements of send buffer (handle)
  • op β€” operation (handle)
  • comm β€” communicator (handle)
  • info β€” info argument (handle)

πŸ¦‹ OUTPUT PARAMETERS πŸ¦‹

and these are the ones that come back out to you, lil gift πŸ’:

  • recvbuf β€” starting address of receive buffer (choice)
  • request β€” communication request (handle)

πŸ‘‘ THREAD AND INTERRUPT SAFETY πŸ‘‘

so this routine is thread-safe, periodt. that means it's literally fine to have multiple threads using it at the same time, and nobody needs to bring their own thread locks β€” the routine handles that. πŸ’ͺ

BUT β€” and this is the important part bestie β€” it is not interrupt safe. 🚨 typically that's because of memory allocation routines like malloc, or other non-MPICH runtime routines, which are themselves not interrupt-safe. so like… not it. πŸ’€


🌈 NOTES FOR FORTRAN 🌈

  • Every single MPI routine in Fortran (except for MPI_WTIME and MPI_WTICK) gets an extra argument called ierr slapped 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. iykyk. ✨
  • In Fortran, MPI routines are subroutines, and you invoke them with the call statement. classic.
  • All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in Fortran. yes really. 🧚

πŸ’€ ERRORS πŸ’€

okay so story time: all MPI routines (except MPI_Wtime and MPI_Wtick) return an error value β€” C routines give it as the value of the function, and Fortran routines put it in that last argument. and before the value even comes back to you, the current MPI error handler gets called. πŸ™ˆ

by default, that error handler aborts the MPI job. no second chances. 😭

you can change 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 may be used, but its use is deprecated β€” so like, don't, unless you must. 🚫

there's also a predefined error handler called MPI_ERRORS_RETURN that you can use to make error values get returned instead.

⚠️ Note that MPI does not guarantee that an MPI program can continue past an error. However, MPI implementations will attempt to continue whenever possible. so… maybe it works, maybe it doesn't. vibe check inconclusive. 🫠

here's the full error roster, no skips:

  • MPI_SUCCESS β€” No error; MPI routine completed successfully. πŸ₯³
  • 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 in MPI_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 type MPI_Op) must either be one of the predefined operations (e.g., MPI_SUM) or created with MPI_Op_create.
  • 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.

and that's the whole page, you ate that fr fr πŸ’…βœ¨

so basically β€” this page is from the MPI manual, dated 4/10/2026, and it's the page for MPI_Allreduce_init(3). go forth and reduce, bestie πŸ¦‹πŸ’œ

πŸ“¦ where this page comes from