Here is one question about MPI. I need two processors that support the modification of one variable, and I want both processors to have access to the variable with the most recent value.
from mpi4py import MPI from time import sleep comm = MPI.COMM_WORLD rank = comm.rank assert comm.size == 2 msg = 0 sec = 10 if comm.rank == 0: for i in range(sec): print msg sleep(1) msg = comm.bcast(msg,root = 1) else: for i in range(sec*2): msg += 1 sleep(0.5) comm.bcast(msg,root = 1)
So, I expect the program to print something like: 0 2 4 ...
But the program is obtained for printing: 0 1 2 3 4 5 6 7 8 9
I am wondering if there is a mechanism in mpi4py so that the msg variable is used by both processors? That is, whenever msg is modified by processor 1, the new value becomes immediately available to processor 0. In other words, I want processor 0 to access the latest msg value instead of waiting for all the changes made to msg by processor 1.
source share