|
| 1 | +# NAME |
| 2 | + |
| 3 | +`MPI_Bcast`, `MPI_Ibcast` - Broadcasts a message from the process with |
| 4 | +rank *root* to all other processes of the group. |
| 5 | + |
| 6 | +# SYNTAX |
| 7 | + |
| 8 | +## C Syntax |
| 9 | + |
| 10 | +```C |
| 11 | +#include <mpi.h> |
| 12 | +int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, |
| 13 | + int root, MPI_Comm comm) |
| 14 | + |
| 15 | +int MPI_Ibcast(void *buffer, int count, MPI_Datatype datatype, |
| 16 | + int root, MPI_Comm comm, MPI_Request *request) |
| 17 | +``` |
| 18 | +
|
| 19 | +## Fortran Syntax |
| 20 | +
|
| 21 | +```Fortran |
| 22 | +USE MPI |
| 23 | +! or the older form: INCLUDE 'mpif.h' |
| 24 | +MPI_BCAST(BUFFER, COUNT, DATATYPE, ROOT, COMM, IERROR) |
| 25 | + <type> BUFFER(*) |
| 26 | + INTEGER COUNT, DATATYPE, ROOT, COMM, IERROR |
| 27 | +
|
| 28 | +MPI_IBCAST(BUFFER, COUNT, DATATYPE, ROOT, COMM, REQUEST, IERROR) |
| 29 | + <type> BUFFER(*) |
| 30 | + INTEGER COUNT, DATATYPE, ROOT, COMM, REQUEST, IERROR |
| 31 | +``` |
| 32 | + |
| 33 | +## Fortran 2008 Syntax |
| 34 | + |
| 35 | +``` Fortran |
| 36 | +USE mpi_f08 |
| 37 | +MPI_Bcast(buffer, count, datatype, root, comm, ierror) |
| 38 | + TYPE(*), DIMENSION(..) :: buffer |
| 39 | + INTEGER, INTENT(IN) :: count, root |
| 40 | + TYPE(MPI_Datatype), INTENT(IN) :: datatype |
| 41 | + TYPE(MPI_Comm), INTENT(IN) :: comm |
| 42 | + INTEGER, OPTIONAL, INTENT(OUT) :: ierror |
| 43 | +
|
| 44 | +MPI_Ibcast(buffer, count, datatype, root, comm, request, ierror) |
| 45 | + TYPE(*), DIMENSION(..), ASYNCHRONOUS :: buffer |
| 46 | + INTEGER, INTENT(IN) :: count, root |
| 47 | + TYPE(MPI_Datatype), INTENT(IN) :: datatype |
| 48 | + TYPE(MPI_Comm), INTENT(IN) :: comm |
| 49 | + TYPE(MPI_Request), INTENT(OUT) :: request |
| 50 | + INTEGER, OPTIONAL, INTENT(OUT) :: ierror |
| 51 | +``` |
| 52 | + |
| 53 | +# INPUT/OUTPUT PARAMETERS |
| 54 | + |
| 55 | +* `buffer`: Starting address of buffer (choice). |
| 56 | +* `count`: Number of entries in buffer (integer). |
| 57 | +* `datatype`: Data type of buffer (handle). |
| 58 | +* `root`: Rank of broadcast root (integer). |
| 59 | +* `comm`: Communicator (handle). |
| 60 | + |
| 61 | +# OUTPUT PARAMETERS |
| 62 | + |
| 63 | +* `request`: Request (handle, non-blocking only). |
| 64 | +* `IERROR`: Fortran only: Error status (integer). |
| 65 | + |
| 66 | +# DESCRIPTION |
| 67 | + |
| 68 | +`MPI_Bcast` broadcasts a message from the process with rank root to all |
| 69 | +processes of the group, itself included. It is called by all members of |
| 70 | +group using the same arguments for `comm`, `root`. On return, the contents |
| 71 | +of root's communication buffer has been copied to all processes. |
| 72 | + |
| 73 | +General, derived datatypes are allowed for datatype. The type signature |
| 74 | +of count, datatype on any process must be equal to the type signature o f |
| 75 | +count, datatype at the root. This implies that the amount of data sent |
| 76 | +must be equal to the amount received, pairwise between each process and |
| 77 | +the root. `MPI_Bcast` and all other data-movement collective routines make |
| 78 | +this restriction. Distinct type maps between sender and receiver are |
| 79 | +still allowed. |
| 80 | + |
| 81 | +**Example:** Broadcast 100 ints from process 0 to every process in the |
| 82 | +group. |
| 83 | + |
| 84 | +```C |
| 85 | +MPI_Comm comm; |
| 86 | +int array[100]; |
| 87 | +int root=0; |
| 88 | +//... |
| 89 | +MPI_Bcast( array, 100, MPI_INT, root, comm); |
| 90 | +``` |
| 91 | +
|
| 92 | +As in many of our sample code fragments, we assume that some of the |
| 93 | +variables (such as comm in the example above) have been assigned |
| 94 | +appropriate values. |
| 95 | +
|
| 96 | +# WHEN COMMUNICATOR IS AN INTER-COMMUNICATOR |
| 97 | +
|
| 98 | +When the communicator is an inter-communicator, the root process in the |
| 99 | +first group broadcasts data to all the processes in the second group. |
| 100 | +The first group defines the root process. That process uses `MPI_ROOT` as |
| 101 | +the value of its `root` argument. The remaining processes use |
| 102 | +`MPI_PROC_NULL` as the value of their `root` argument. All processes in |
| 103 | +the second group use the rank of that root process in the first group as |
| 104 | +the value of their `root` argument. The receive buffer arguments of the |
| 105 | +processes in the second group must be consistent with the send buffer |
| 106 | +argument of the root process in the first group. |
| 107 | +
|
| 108 | +# NOTES |
| 109 | +
|
| 110 | +This function does not support the in-place option. |
| 111 | +
|
| 112 | +# ERRORS |
| 113 | +
|
| 114 | +Almost all MPI routines return an error value; C routines as the value |
| 115 | +of the function and Fortran routines in the last argument. |
| 116 | +
|
| 117 | +Before the error value is returned, the current MPI error handler is |
| 118 | +called. By default, this error handler aborts the MPI job, except for |
| 119 | +I/O function errors. The error handler may be changed with |
| 120 | +`MPI_Comm_set_errhandler`; the predefined error handler `MPI_ERRORS_RETURN` |
| 121 | +may be used to cause error values to be returned. Note that MPI does not |
| 122 | +guarantee that an MPI program can continue past an error. |
0 commit comments