# L-04 MCS 572 Mon 29 Aug 2016 : mpi4py_broadcast.py

"""
A broadcast is a collective communication in which
one process sends the same data to all processes
which belong to the same intracommunicator.

At the command prompt, type
mpiexec -n 3 python mpi4py_broadcast.py
where '3' is the number of processes.
On kepler.math.uic.edu, to avoid the error messages:
mpiexec --mca btl tcp,self -n 3 python mpi4py_broadcast.py
"""

from mpi4py import MPI

COMM = MPI.COMM_WORLD
RANK = COMM.Get_rank()

if(RANK == 0):
    DATA = {'e' : 2.7182818284590451,
            'pi' : 3.1415926535897931 }
else:
    DATA = None # DATA must be defined

DATA = COMM.bcast(DATA, root=0)
print RANK, 'has data', DATA
