
Hi Boosters!
In this post I just wanted to throw in my two cents about the newly
accepted MPI library, from a luser's point of view.
(doc: http://tinyurl.com/fjc9x)
It was a great excitement to see the news on boost.org "Message Passing
Review Begins"! The C bindings of MPI are a great pain to use -- a fact
which is mostly denied by programmers who are unaware of C++'s beauty
and content with even good old F77 most of the time. And, as it has been
pointed out by Boost.MPI developers, the C++ bindings of standard MPI,
though an improvement, are nothing more than simple wrappers on top of
the C bindings. Moreover, certain supercomputing centers do not even
have these C++ bindings of MPI installed on their otherwise
state-of-the-art clusters.
So, anyway, it was great to hear that finally MPI will be *boost*ed.
There is a lot to what is good about this new boost library. For one,
quoting Jeremy: "One particularly nice aspect of Boost.MPI is the way it
leverages the Boost serialization library". This indeed appears to be a
greatly elegant way to message-pass user types around. There are other
features to applaud, such as reduce() via arbitrary functors. Yet, in
this post, with the intent of providing constructive criticism, I'd like
to point out several design issues related to the user interface; mostly
in comparison with other MPI implementations.
(hereafter the discussion will assume specific knowledge about MPI)
Here is a brief outline of what I'll be talking about, somewhat in the
order of importance:
1. Port object
2. Message object
3. Skeleton and content questions
4. MPI-2 bindings
*Port Object*
Those of you who have actively programmed with MPI certainly have used
or at least heard of the OOMPI library (I believe Doug Gregor, one of
the two developers of Boost.MPI, is affiliated with the institution
OOMPI was born). Its web page, http://www.osl.iu.edu/research/oompi/ ,
greets you with random (mostly funny) messages, such as "OOMPI- Isn't it
time you did something for YOU?" :)
Anyway, it was thanks to OOMPI library that I realized that in fact MPI
programming could be fun! Especially, there is this *OOMPI_Port*
abstraction that literally _enlighten_s the way point-to-point (PTP) and
rooted-collective (RC) operations are made. Let's contrast the way PTP
is carried out for the three interfaces (Standard MPI, Boost.MPI and OOMPI):
//================================================\\
// Standard way
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int msg;
int msg_tag = 10;
if (rank == 0) {
msg = 17;
MPI_Send(&msg, 1, MPI_INT, 1, msg_tag, MPI_COMM_WORLD);
// (synopsis: http://tinyurl.com/ejmgg )
} elseif (rank==1) {
MPI_Recv(&msg, 1, MPI_INT, 0, msg_tag, MPI_COMM_WORLD,
MPI_STATUS_IGNORE);
// (synopsis: http://tinyurl.com/elkez )
}
// Boost.MPI way
mpi::communicator world;
int msg;
int msg_tag = 10;
if (world.rank() == 0) {
msg = 17;
world.send(1, msg_tag, msg);
} elseif (world.rank() == 1) {
world.recv(0, msg_tag, msg);
}
// OOMPI way
OOMPI_Comm_world& world = OOMPI_COMM_WORLD;
world.Init(argc,argv);
int msg;
int msg_tag = 10;
OOMPI_Port to (world[1]);
OOMPI_Port from (world[0]);
if (world.Rank() == from.Rank()) {
msg = 17;
to.Send(msg,msg_tag);
} else if (world.Rank() == to.Rank()) {
from.Recv(msg,msg_tag);
}
//=============================================
The standard C provides global functions for this simplest and most
commonly employed Send/Recv commands. These functions require a long
list of arguments, which are usually a pain to keep track of (here is
another P2P command which is really harsh http://tinyurl.com/mk6dq).
Also, such an interface does not provide any conceptual description of
what is going on. The design of MPI is indeed mostly object oriented
(http://tinyurl.com/qm9hd), however the implementation doesn't realize
this fact.
Boost.MPI improves two aspects of this: For one the P2P commands are
member functions of the communicator (same as the standard C++
bindings); and two, the message's type is templated and the user does
not have to repeatedly specify what she is sending. But, as in
C-version, one still has to realize the points (P's in P2P) of
communication as a bunch of integer values rather than, well, the points
of communication, which are an entities by themselves.
OOMPI takes this one step further and things kind of fit in place with
the whole framework of MPI's design: The points of communication are
objects themselves, abstracted as OOMPI_Port class. P2P functions are
member functions of OOMPI_Port and OOMPI_Port is in turn a certain piece
of a given communicator. Here is how an RC communication looks like:
//=============================================
// Root-collective communication with OOMPI.
// The message will be created at the 4th process and
//+ will be broadcasted to everyone in the world communicator.
OOMPI_Port root = world[4];
root.Bcast(msg);
// or if the Port will not be used for anything else, it is
//+ possible to create a temporary:
world[4].Bcast(msg);
// Here is how this is with Boost.MPI
broadcast(world, msg, 4);
//=============================================
Clearly the OOMPI version is more instructive of the communication
process. A more elaborate illustration can be given in the context of
communication topologies (a feature that is not yet available in
Boost.MPI, unless I am mistaken). For instance:
//=============================================
// Create a cartesian virtual topology
enum {X,Y,NDIM};
int shape[NDIM] = {3,2}; // requires world.size() >= 6;
bool is_periodic[] = {true,true};
OOMPI_Cart_comm grid(world,NDIM,shape,is_periodic);
// Get nodes of subsequent P2P communication
OOMPI_Port left = grid[grid.Shift(X,-1)]; // left neighbor
OOMPI_Port right = grid[grid.Shift(X, 1)]; // right neighbor
// get cartesian coordinates
int mycoords[NDIM]; grid.Coords(mycoords);
// create a message
int msg = grid.Rank();
// P2P communicate
left.Send(msg); // send to left
right.Recv(msg); // recv from right
//================================================
I wonder why this Port abstraction (or a similar idea) couldn't make its
way to Boost.MPI? Is there an underlying design decision to this?
Also, why the P2P commands are members of the communicator class but RC
commands such as broadcast and gather are global?
*Message object*
A message in MPI is created by specifiying a data type, data count, data
address and finally a message tag. Note the C interface of passing a
message in a P2P communication (see first example above). The 4 out of 6
arguments in MPI_Send() is just to specify the message. And for every
communication statement of the same kind, this list should be repeated.
Boost.MPI (ignoring the skeleton/content idea for a second) reduces this
to three arguments (http://tinyurl.com/k2w7q): Reference to the data
(from which the type is deduced), data count and the message tag.
However, this message is still not a separate entity; and all this
information is repeatedly specified as arguments to communication functions.
OOMPI provides the convenience of OOMPI_Message object, which is then
used in communications. For instance, to pass an array of integers:
//=============================================
int size = 5;
int arr[size];
OOMPI_Tag msg_tag = 10;
OOMPI_Message msg(arr1,size,msg_tag);
if (world.Rank() == root.Rank()) /* fill up the arr */;
root.Bcast(msg);
//=============================================
*Skeleton and Content - Separating structure from content*
Boost.MPI provides this promising functionality which not only
simplifies message specifications during communication calls but also
helps to easily create more complex data types.
But as admittedly a naive user, I am not so sure if this won't actually
degrade the performance, or why is this even necessary at all. For
instance, let's examine the example given here
(http://tinyurl.com/mgwkt). A plain C implementation of the same thing
would be something like this:
//===================================================
int root = 0;
// Create the message type (this section of the
//+ code is run by ALL processes in the communicator).
int list_len = 10; // size of the message
std::list<int> mylist(list_len);
std::vector

Hello Levent, [Matthias: There's a question for you below, about the skeleton/ content mechanism] On Sep 25, 2006, at 7:17 PM, Levent Yilmaz wrote:
I wonder why this Port abstraction (or a similar idea) couldn't make its way to Boost.MPI? Is there an underlying design decision to this?
I view ports as a useful feature that can easily be added on top of the current Boost.MPI interface. You can expect ports to be in an upcoming version of Boost.MPI because, as you've shown, they certainly simplify many uses of MPI.
Also, why the P2P commands are members of the communicator class but RC commands such as broadcast and gather are global?
The motivation behind this decision was to keep the "algorithms" (collectives) separate from the "core" operations (P2P with a communicator). It's a philosophical viewport with a practical point to it... #including all of the algorithms pulls in a lot more code than including the communicator alone. But, perhaps we should revisit this decision. Perhaps it's unfamiliarity, but I find world[0].Bcast(data) to be a little strange. I know it means that we're broadcasting from rank 0, but it reads awkwardly for me because it's a receive on any other rank. Ports feel like a great interface for point-to-point, but they don't seem to convey the "collective" nature that free-standing algorithms do. Another advantage of free functions for the algorithms (which we don't currently realize) is that we could have versions that don't take a communicator argument at all. Many simple applications just use MPI_COMM_WORLD anyway.
*Message object*
A message in MPI is created by specifiying a data type, data count, data address and finally a message tag. Note the C interface of passing a message in a P2P communication (see first example above). The 4 out of 6 arguments in MPI_Send() is just to specify the message. And for every communication statement of the same kind, this list should be repeated.
Boost.MPI (ignoring the skeleton/content idea for a second) reduces this to three arguments (http://tinyurl.com/k2w7q): Reference to the data (from which the type is deduced), data count and the message tag. However, this message is still not a separate entity; and all this information is repeatedly specified as arguments to communication functions.
OOMPI provides the convenience of OOMPI_Message object, which is then used in communications. For instance, to pass an array of integers:
//============================================= int size = 5; int arr[size]; OOMPI_Tag msg_tag = 10; OOMPI_Message msg(arr1,size,msg_tag);
if (world.Rank() == root.Rank()) /* fill up the arr */; root.Bcast(msg); //=============================================
I guess in the context of Boost.MPI we would parameterize the message
on the data type (to avoid having to dispatch through virtual
functions), e.g.,
boost::message
Now, Boost.MPI conveniently reduces the data type definition down to a single statement:
mpi::skeleton(mylist);
But, then the example has this extra broadcasting statement (indeed, the example is such that the skeleton (MPI_Datatype) is created as a temporary):
broadcast(world, mpi::skeleton(mylist), 0);
Here, I am not so sure why this is useful. The only thing that is common with the master and slave processes' lists is the list_len, which is already assumed to be known by all.
I need to clear up this example. We're not assuming that list_len is known by all. Rather, the master has some kind of data structure that only it knows about. It broadcasts the skeleton---or, shape---of that data structure so that everyone else can build identically-shaped containers. The content is passed separately.
The containers live in totally distinct memory spaces and the elements are located at different addresses. So everybody has to call mpi::skeleton(mylist) separately, but not _receive_ it from the master.
The actual data is passed by subsequent possibly multiple broadcast calls:
mpi::content c = mpi::get_content(l); broadcast(world, c, root);
Now, here is the content anything more than MPI_BOTTOM? What extra information does it carry?
Content is merely MPI_BOTTOM, with an appropriate data type. The skeleton/content mechanism is meant to abstract this use of MPI_BOTTOM.
Is it possible to apply the same skeleton to a different list<int> of same size?
Receiving a skeleton into a list<int> reshapes that list<int> to mirror the shape of the list<int> that was transmitted.
Another point, as I indicated before with the C example, is it possible to create skeletons of different containers of the same value_type (say list<int> on master and vector<int>'s on slaves) and pass the contents around without performance penalty?
I don't believe this is possible, but let's see what Matthias has to say. He's the expert on skeleton/content.
*MPI-2 Bindings*
Somewhere in the documentation a reference to MPI-2 bindings has been made (http://tinyurl.com/jhjo8). Including modern MPI-2 bindings are of course an important provision; however as I indicated previously, there are certain supercomputing centers which do not support MPI-2 yet. Does this resctrict the usage of Boost.MPI in anyway? In other words, would my code still compile and link if I avoid the MPI-2 subset of Boost.MPI?
Yes, it will. Boost.MPI will be compatible with MPI 1.1 for the foreseeable future. At present, the only part of Boost.MPI that relies on MPI-2 is the allocator. It will only be available in Boost.MPI if we have determined that the underlying MPI provides MPI_Alloc_mem and MPI_Free_mem. If we start introducing abstractions for MPI-2 in Boost.MPI (we'd like to; time is a big issue), they'll only be available when the underlying C MPI supports the necessary MPI-2 functionality.
Also, as indicated by the developers themselves, the current implementation supports only a limited subset of MPI 1.1. Yet, IMHO, given this subset doesn't even include the virtual topology creation, it is perhaps a bit too early to have it in boost.
Right. We're missing groups, inter-communication, and topologies. As with MPI-2, we'd like to provide complete support, but in this case I (personally) do not have suitable experience with these features (especially topologies) to be certain that we're getting the abstractions right. In all fairness, our limited subset is the subset of MPI used by a large number of people. Many of us don't need intercommunicators or virtual topologies, so the library itself can be very useful even before it is complete. That doesn't mean we won't complete it, of course. We want to.
Well, thanks for bearing with me this far. I hope I was able to provide useful feedback for this fresh library.
Thanks for the feedback! Cheers, Doug
participants (2)
-
Doug Gregor
-
Levent Yilmaz