# L-13 MCS 507 Wed 20 Sep 2023 : 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 python3 mpi4py_broadcast.py
where '3' is the number of processes.
"""

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)
