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

"""
Adapting a script from the mpi4py tutorial we illustrate
the point-to-point communication between 2 processes.
At the command prompt, type
mpiexec -n 2 python3 mpi4py_point2point.py
to run the script.
"""

from mpi4py import MPI

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

if(RANK == 0):
    DATA = {'a': 7, 'b': 3.14}
    COMM.send(DATA, dest=1, tag=11)
    print(RANK, 'sends', DATA, 'to 1')
elif(RANK == 1):
    DATA = COMM.recv(source=0, tag=11)
    print(RANK, 'received', DATA, 'from 0')
