Boost logo

Boost Users :

Subject: Re: [Boost-users] mpi: sending/receiving different types
From: Riccardo Murri (riccardo.murri_at_[hidden])
Date: 2010-12-09 06:57:52


Hi Hicham,

On Wed, Dec 8, 2010 at 2:50 PM, Riccardo Murri <riccardo.murri_at_[hidden]> wrote:
>> 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!)
>

Now I actually tried and could not get this to work; the main problem
is that the mpi::broadcast expects an already-built object to call the
(de)serialization procedure on, irrespective of whether the object was
passed as a pointer or as a reference.

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

I think this is the way to go; I'm attaching a sample program. Not
sure this is exactly what you need, but could be enough to get you
started.

Best regards,
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