MPI_Bcast(3)

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

πŸ’– 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_WTIME and MPI_WTICK) have an additional argument ierr at the end of the argument list. ierr is 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 call statement.
  • All MPI objects (e.g., MPI_Datatype, MPI_Comm) are of type INTEGER in 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 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_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.

🌟 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