Databases Reference
In-Depth Information
Hello World (from process 3)
Hello World (from process 2)
The COMM_WORLD object is an MPI communicator . Communication between processes
all happens though the MPI library, via these objects. In addition to “send” and “receive”
methods, communicators in MPI support a variety of advanced “scatter” operations to
distribute work among processes. Since a complete treatment of MPI features is beyond
the scope of this topic, we will limit ourselves to a few basic features.
The COMM_WORLD attribute rank is an integer that identifies the running process. You'll
notice that the output statements print “out of order” with respect to rank . As with
threads, since our four processes run in parallel there's no guarantee as to which will
finish first. Later on we'll examine some basic methods for interprocess synchronization.
Check out the mpi4py website for a great introduction to using MPI
from Python, and a large number of examples.
MPI-Based HDF5 Program
Building h5py in MPI mode is simple. The tricky bit is getting access to a version of
HDF5 compiled in “parallel” mode; increasingly, this is available as a built-in package
on most Linux distributions. Then, when you build h5py, just enable the --mpi option:
$ python setup.py build --mpi [--hdf5=/path/to/parallel/hdf5]
$ [sudo] python setup.py install
If you have installation problems, consult the guide at www.h5py.org
for tips and additional examples. The examples shown here use an
OpenMPI build of HDF5, running on Linux.
On the Python side, all you have to do is open your file with the mpio driver. You have
to supply an MPI communicator as well; COMM_WORLD does nicely:
from mpi4py import MPI
import h5py
f = h5py . File ( "foo.hdf5" , "w" , driver = "mpio" , comm = MPI . COMM_WORLD )
In contrast to the other file drivers, a file opened with mpio can safely be accessed from
multiple processes.
Here's the MPI equivalent of our distance-calculation code. Note that the division of
work is done implicitly (in this case using the process rank) in contrast to the explicit
map() -based approach we saw in the multiprocessing example:
Search WWH ::




Custom Search