Databases Reference
In-Depth Information
sleep ( random () * 5 )
print "A (rank %d )" % rank
sleep ( random () * 5 )
print "B (rank %d )" % rank
Running it, we get:
$ mpiexec -n 4 python demo2.py
A (rank 2)
B (rank 2)
A (rank 1)
A (rank 0)
B (rank 1)
A (rank 3)
B (rank 3)
B (rank 0)
Our COMM_WORLD communicator includes a Barrier function. If we add a barrier for all
processes just before the “B” print statement, we get:
from random import random
from time import sleep
from mpi4py import MPI
comm = MPI . COMM_WORLD
rank = comm . rank
sleep ( random () * 5 )
print "A (rank %d )" % rank
comm . Barrier () # Blocks until all processes catch up
sleep ( random () * 5 )
print "B (rank %d )" % rank
$ mpiexec -n 4 python demo3.py
A (rank 2)
A (rank 3)
A (rank 0)
A (rank 1)
B (rank 2)
B (rank 0)
B (rank 1)
B (rank 3)
Now that you know about Barrier , what do you think the following two-process pro‐
gram outputs?
import h5py
from mpi4py import MPI
comm = MPI . COMM_WORLD
rank = comm . rank
Search WWH ::




Custom Search