|
Purpose:
Send a message from the root process to all processes in the group, including the root process. Fortran Binding:
MPI_BCAST (buffer, count, datatype, root, comm, ierr)
C Binding:
int MPI_Bcast (void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
Broadcast Effect

In many cases, one process needs to send (broadcast) some data (either a scalar or vector) to all the processes in a group. MPI provides the broadcast primitive MPI_BCAST to accomplish this task. The syntax of the MPI_BCAST is given by:
C
| int MPI_Bcast |
(void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) |
FORTRAN
| MPI_BCAST |
(buffer, count, datatype, root, comm, ierr) |
where:
| buffer |
is the starting address of a buffer, |
| count |
is an integer indicating the number of data elements in the buffer, |
| datatype |
is MPI defined constant indicating the data type of the elements in the buffer, |
| root |
is an integer indicating the rank of broadcast root process, and |
| comm |
is the communicator. |
The MPI_BCAST must be called by each node in the group, specifying the same comm and root. The message is sent from the root process to all processes in the group, including the root process.

Example:
- "hello, world" example used in earlier modules could use broadcast instead of multiple sends and receives
use MPI
character(12) message
integer rank,root
data root/0/
call MPI_INIT(ierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
if (rank .eq. root) then
message = 'Hello, world'
endif
call MPI_BCAST(message, 12, MPI_CHARACTER, root, &
MPI_COMM_WORLD, ierr)
print*, 'node', rank, ':', message
call MPI_FINALIZE(ierr)
end
|