NERSC logo National Energy Research Scientific Computing Center
  A DOE Office of Science User Facility
  at Lawrence Berkeley National Laboratory
 

Broadcast

Often you will have data on one processor that it needs to share with all other processors. You accomplish this by using a broadcast, which sends data to a group of processes. The MPI routine MPI_BCAST() transfers data from one task to a group of others. The format is:

Fortran

FORTRAN_TYPE:: buff
INTEGER:: count, root, ierr

CALL MPI_BCAST(buff, count, MPI_TYPE, root, comm, ierr)

C

int MPI_Bcast( void *buff, int count, MPI_Datatype datatype, int root,
	MPI_Comm comm)

where the variables are the same as before, except

  • FORTRAN_TYPE : is to be replaced with the Fortran data type of the variable being passed, e.g. REAL and INTEGER.
  • MPI_TYPE : is to be replaced with the MPI type of the data being passed, e.g. MPI_REAL and MPI_INTEGER .
  • buff : the variable name of the data being broadcast. When the call returns, all tasks will have the same value placed in buff
  • root : This is the task which has the value to be shared with all the others. In other words, if buff=10 on task 3, setting root=3 will cause the call to MPI_BCAST to set buff=10 on all the tasks.

Example

This sample program, bcast.f90 is available in $EXAMPLES/mpi/intro/bcast/. The program has task 0 calculate a value for the variable rsq and then broadcast that value to all the other tasks. Each task then prints out the value, thus verifying the broadcast.

If we compile and run, we get these results

franklin% ftn -o bcast  bcast.f90
franklin% qsub -I -lmppwidth=8
frnaklin% cd $PBS_O_WORKDIR
franklin% aprun -n 8 ./bcast 
 TASK # 0  has rsq=  27.562500
 TASK # 1  has rsq=  27.562500
 TASK # 2  has rsq=  27.562500
 TASK # 3  has rsq=  27.562500
 TASK # 4  has rsq=  27.562500
 TASK # 5  has rsq=  27.562500
 TASK # 6  has rsq=  27.562500
 TASK # 7  has rsq=  27.562500

Each task ends up with the same value of the variable rsq.


LBNL Home
Page last modified: Fri, 07 Mar 2008 21:50:17 GMT
Page URL: http://www.nersc.gov/nusers/help/tutorials/mpi/intro/bcast.php
Web contact: webmaster@nersc.gov
Computing questions: consult@nersc.gov

Privacy and Security Notice
DOE Office of Science