# L-13 MCS 507 Wed 20 Sep 2023 : mpi4py_gather.py

"""
A gather is a collective communication in which
data is sent from all processes in the same
intracommunicator to one process.

At the command prompt, type
mpiexec -n 10 python3 mpi4py_gather.py
where '10' is the number of processes.
"""

from mpi4py import MPI

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

DATA = (RANK+1)**2
DATA = COMM.gather(DATA, root=0)
if(RANK == 0):
    print(RANK, 'has data', DATA)
