LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Jeff Squyres (jsquyres_at_[hidden])
Date: 2005-02-15 07:17:12


On Feb 15, 2005, at 5:28 AM, Leslie Nkansa Osei-Bonsu wrote:

> I am working on a particle simulation using C++ and MPI
> I have a class particle as in the following,
>
> class Particle{
> float mass;
> float charge;
> float pos[3];
> float vel[3];
> int id;
> //plus more data members
> }
> in the form of array say-: Particle simparticle[1000];
>
> After each iteration, I want to broadcast the pos[3] and vel[3]
> values but I dont want to BCast in bit and pieces, I wanted to
> use a derived datatype that would automatically send the values
> as once communication block.

That should work fine.

> Can it be done in MPI without serious overhead? If so any ideas
> on how to construct the relevant data types? I constructed a
> datatype using the full typemap but I am stuck on how to proceed
> from there.

I'm not sure what you mean by "I constructed a datatype using the full
typemap". You should just create a datatype of just those two members
(pos[3] and vel[3] -- do *not* assume that they will be contiguous in
memory! -- and use that to bcast the data.

If you need to bcast the pos/vel members from more than one Particle
(i.e., from several members of your simparticle[] array), then you'll
need to augment the datatype with a lower and/or upper bound so that
the spacing is worked out properly when MPI traverses memory to find
the correct data to send.

It sounds like you could use a good tutorial on MPI datatypes (they're
a little tricky, and probably beyond what can be reasonably explained
here). It's worth your time to work through a tutorial; once you
understand them, you can do some pretty neat (and useful) things.
Check out the following MPI tutorial -- skip ahead to the datatypes
section:

        http://webct.ncsa.uiuc.edu:8900/public/MPI/

-- 
{+} Jeff Squyres
{+} jsquyres_at_[hidden]
{+} http://www.lam-mpi.org/