On Mar 14, 2005, at 11:18 AM, karla b wrote:
> I followed those comments some months ago as at the time they were
> very pertinent to me, though at that time I was still very new to
> parallel programming so felt that I needed to go off and learn myself
> first, not having experience with the problems mentioned. Now however
> I am at the next stage having made all manner of attempts.
Things have started moving in the MPI community site. We'll post back
here when there's more information.
> My struct based attempt is an effort to reduce communication overhead,
> however my question then became how do I pass a struct? Or is
> contiguous a better option? The tutorial that Brian suggested (which I
> spent some time working with) in its user defined types example uses
> variables named lena, loca, for defining length and types etc (it was
> so confusing, I was looking for Ricky Martin the whole time!) of new
> datatype, it was extremely confusing in that I was trying to send a 2d
> array, so number of elements was a sticking point (and still I am
> not sure how exactly to set it up properly!) I found something of an
> answer in the Notre Dame tutorial 2, slide 41 I think, which gave a
> better example of this procedure. Also in my problem area, the Lam
> master/skeleton treats work as a finite set, whereas I'll have to keep
> working until a minimum is converged upon, this of course can only
> happen if and when I can figure out how to pass my struct!!
So it sounds like there's three issues involved in your project:
1. how to pass the struct
2. how to pass a 2D array
3. how to do flow control based on someone (probably the master?)
deciding when the work is done, not based on a finite set
1 is a little complicated to get your head wrapped around, but makes
sense after you do it a few times. 2 is generally pretty easy, but
depends on how the array is stored in memory. 3 is pretty easy.
1. For passing structs, it is generally easiest to call
MPI_TYPE_STRUCT to create a datatype for the struct and then any time
you want to send or receive the struct, you just pass a pointer to the
instance and use the datatype. MPI will then roll up the datatype,
send it, and expand it on the other side. If you're familiar with Java
and the like, this is similar to serialization / de-serialization. The
only real complexity is in how to make the datatype.
Poke through those tutorials, examples, and the description in the MPI
standard; I won't be able to state it any better here. :-\
2. If the 2D array is contiguous in memory, it's probably easiest just
to pass a pointer to the first element and specify how many elements to
send. Something like:
MPI_Send(&array[0][0], N * M, MPI_DOUBLE, ...);
That's usually the easiest way to do it. You can do it if they're not
contiguous in memory, but it takes a bit more effort.
3. You want to implement flow control between the manager and workers.
For example, when the workers come online, send a message to the
manager asking for work. The manager will reply with "here's some
work" or "sorry, no more work -- time to quit". The worker will take
appropriate action based on what message was received. When the master
has told all workers to quit, it can quit, too.
An easy way to do these different messages is to use different tags.
For example, the "time to quit" message can be a 0 byte send on the
MASTER_TIME_TO_QUIT_TAG tag (assuming MASTER_TIME_TO_QUIT is an enum or
#define -- just some unique int value that everyone agrees on). The
work message can be some other tag and actually contain the work to do.
The worker posts 2 non-blocking receives: one on both tags. Then do
an MPI_WAITANY and see which of them completes. If the QUIT request
completes, then the master sent you a quit message, and you can quit.
If the work request completes, then you just received some work to do
and you need to go off and process it.
There's a million different variations on this -- the one I proposed
above is not the most efficient, but it was easiest to explain. :-)
The idea is that you just setup intelligent communication between the
manager and workers; don't think that the *only* thing you can send
around is data. Once you open the door to sending meta-communication
around, many more ideas become possible.
Does that help?
--
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/
|