Boost logo

Boost Users :

Subject: Re: [Boost-users] mpi: sending/receiving different types
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-12-08 08:50:40


Hi Hicham,

now I see your problem...

On Tue, Dec 7, 2010 at 9:41 AM, Hicham Mouline <hicham_at_[hidden]> wrote:
> During a sequence of communication, the slave processes don't know what type
> to get broadcast of, next.
> What should be the T in the call to broadcast.
>
> 1. the root sends a tag for the T to tell the receivers I will broadcast you
> this and this. This means 2 broadcast each time
>

Safe and easy option. Could be the slowest if you plan broadcasting a
lot of messages and/or running on a large number of ranks.

> 2. the root sends directly a reference to a base class of anything sendable,
> then the receivers construct the derived classes on reception with
> broadcast. The T is then the base class type.
>

There's a risk of slicing here, i.e., if you pass a reference to a
base class, only the base class data will be serialized and received.

As far as I understand, Boost.Serialization (hence Boost.MPI) will do
the correct thing if you use *pointers* instead: i.e., you send a
pointer to a (derived) class and you receive it through a pointer to
the base class.

(Beware: I have not checked!)

> 3. I just thought of using boost::variant<> over all the possible types.
>

Should work, provided you #include <boost/serialization/variant.hpp>

Riccardo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net