from mpi4py import MPI comm = MPI.COMM_WORLD rank=comm.rank size=comm.size name=MPI.Get_processor_name() if rank == 0: shared = {'d1':55,'d2':42} comm.send(shared, dest=1) if rank == 1: receive = comm.recv(source=0) print receive print receive['d1']
So this isn't tagging just yet, but I wanted to show you this. What is so special about this? Well, the data we're sending here is not just an int or a string, this is a dictionary! So, as you can see, we can also send objects with MPI4py. This is actually pretty exciting, at least to me.
from mpi4py import MPI comm = MPI.COMM_WORLD rank=comm.rank size=comm.size name=MPI.Get_processor_name() if rank == 0: shared = {'d1':55,'d2':42} comm.send(shared, dest=1, tag=1) shared2 = {'d3':25,'d4':22} comm.send(shared2, dest=1, tag=2) if rank == 1: receive = comm.recv(source=0, tag=1) print receive receive2 = comm.recv(source=0, tag=2) print receive2
Tagging messages is basically a requirement, unless maybe you treat a node itself as a variable name, and that node only produces one element. The idea of tagging is that you can actually put a label to the data that you're sending, otherwise there's really no way to differentiate between one bit of "data" and another.
Tagging allows us to control data flow, and make sure correct data gets stored where we expect. As you can see, we use the tag parameter in both
mpirun.openmpi -np 5 -machinefile /home/pi/mpi_testing/machinefile python ~/Desktop/sct/sct7.py