MPI_Bcast(3)
π MPI_Bcast(3) β the MPI manual, bestie edition π
okay so you opened the MPI section of the manual and found MPI_Bcast and you're like "what is this, why is it yelling". It's not yelling, it's broadcasting. Let's get into it. π
β¨ NAME β¨
MPI_Bcast β Broadcasts a message from the process with rank "root" to all other processes of the communicator
like, one process has the tea, and it tells literally everybody else. that's the whole vibe. π
π SYNOPSIS π
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root,
MPI_Comm comm)
int MPI_Bcast_c(void *buffer, MPI_Count count, MPI_Datatype datatype, int root,
MPI_Comm comm)
two flavors, same energy. the _c one just takes an MPI_Count instead of an int for count, so it can handle the big big numbers. slay. β¨
π«Ά INPUT PARAMETERS π«Ά
countβ number of entries in buffer (non-negative integer). not negative, we don't do that here.datatypeβ data type of buffer (handle)rootβ rank of broadcast root (integer). this is the main character of the operation, the one holding the message.commβ communicator (handle)
π¦ INPUT/OUTPUT PARAMETERS π¦
bufferβ starting address of buffer (choice)
it's input/output because on the root it's what you're sending and on everybody else it's where the message lands. it's giving duality. two things at once. we love a versatile parameter. π
π THREAD AND INTERRUPT SAFETY π
This routine is thread-safe. Which means: multiple threads can safely use it, and you do not need to bring your own thread locks. no gatekeeping, no extra chores. β¨
However β and this is the important part, don't scroll past it β the routine is not interrupt safe. Typically this is due to the use of memory allocation routines such as malloc or other non-MPICH runtime routines that are themselves not interrupt-safe. so: threads? yes. signals interrupting mid-call? absolutely not, bestie. π
πΈ NOTES FOR FORTRAN πΈ
- All MPI routines in Fortran (except for
MPI_WTIMEandMPI_WTICK) have an additional argumentierrat the end of the argument list.ierris an integer and has the same meaning as the return value of the routine in C. - In Fortran, MPI routines are subroutines, and are invoked with the
callstatement. - All MPI objects (e.g.,
MPI_Datatype,MPI_Comm) are of typeINTEGERin Fortran.
so Fortran girlies, you get a bonus ierr at the end. it's like a little parting gift. π
π ERRORS π
All MPI routines (except MPI_Wtime and MPI_Wtick) return an error value; C routines as the value of the function and Fortran routines in the last argument. Before the value is returned, the current MPI error handler is called. By default, this error handler aborts the MPI job. like, full stop, everyone out. so maybe don't rely on the default unless you enjoy chaos. π
The error handler may 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 (we don't do that anymore). The predefined error handler MPI_ERRORS_RETURN may be used to cause error values to be returned.
Note that MPI does not guarantee that an MPI program can continue past an error; however, MPI implementations will attempt to continue whenever possible.
okay so the error codes, one by one, no skipping:
MPI_SUCCESSβ No error; MPI routine completed successfully. π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_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.
π SEE ALSO π
wait, there isn't one in this page. π the original doesn't list SEE ALSO, so neither do I. no inventing references, that's the rule. rule is rule. π
and that's the whole page, bestie. go forth and broadcast. may your root be correct and your buffer never null. πβ¨π¦
with love, from the MPI manual β version MPI, dated 4/10/2026, under the name MPI_Bcast(3). mwah. π
π¦ 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