Boost logo

Boost :

Subject: Re: [boost] Boost mpi, serialization and shared_ptr
From: Max Moorkamp (mm489_at_[hidden])
Date: 2012-06-12 10:48:58


On 11/06/12 15:27, Max Moorkamp wrote:
> Hi,
>
> I guess this got drowned in the discussion about the beta release and
> the review of the multi-precision library. If anybody could tell me
> what I am doing wrong, any help is greatly appreciated.
>
>> ________________________________________
>> From: boost-bounces_at_[hidden] [boost-bounces_at_[hidden]]
>> On Behalf Of Robert Ramey [ramey_at_[hidden]]
>> Sent: 02 June 2012 03:30
>> To: boost_at_[hidden]
>> Subject: Re: [boost] Boost mpi, serialization and shared_ptr
>>
>> Max Moorkamp wrote:
>>> Hi,
>>>
>>> I have started to parallelize one of my applications using MPI and I
>>> am running into trouble with serializing classes that contain
>>> shared_ptr member to be send through MPI. Below is a minimal case
>>> that demonstrates my problem.
>>
>> before we get too carried away, please double check the documentation.
>>
>> the macro BOOST_SERIALIZATION_EXPORT has
>> been upgraded to the more precise versions
>>
>> BOOST_SERIALIZATION_EXPORT_IMPLEMENT
>> and
>> BOOST_SERIALIZATION_EXPORT_KEY
>>
>> Make these tweaks and see if this helps.
>>
>> Robert Ramey
>
>
>
> I tried what you suggested. Now I have
> Derived.h
> #ifndef DERIVED_H_
> #define DERIVED_H_
>
> #include "Base.h"
> #include <boost/serialization/serialization.hpp>
> #include <boost/shared_ptr.hpp>
> #include <boost/serialization/shared_ptr.hpp>
> #include <boost/serialization/export.hpp>
>
> class Derived: public Base
> {
> private:
> double b;
> boost::shared_ptr<Base> MemberPointer;
> friend class boost::serialization::access;
> template<class Archive>
> void serialize(Archive & ar, const unsigned int version)
> {
> ar & boost::serialization::base_object<Base>(*this);
> ar & MemberPointer;
> ar & b;
> }
> public:
> Derived();
> virtual ~Derived();
> };
>
> BOOST_CLASS_EXPORT_KEY(Derived)
>
> #endif /* DERIVED_H_ */
>
>
> and
>
> Derived.cpp
>
> #include "Derived.h"
> #include <boost/mpi.hpp>
> #include <boost/serialization/shared_ptr.hpp>
> #include <boost/serialization/export.hpp>
>
>
> Derived::Derived()
> {
> }
>
> Derived::~Derived()
> {
> }
>
> BOOST_CLASS_EXPORT_IMPLEMENT(Derived)
>
> but now I get
>
> In file included from Derived.h:14,
> from Derived.cpp:8:
> /usr/local/include/boost/serialization/shared_ptr.hpp: In function
> ‘void boost::serialization::load(Archive&, boost::shared_ptr<U>&,
> unsigned int) [with Archive = boost::mpi::packed_skeleton_iarchive, T
> = Base]’:
> /usr/local/include/boost/serialization/split_free.hpp:58:
> instantiated from ‘static void
> boost::serialization::free_loader<Archive, T>::invoke(Archive&, T&,
> unsigned int) [with Archive = boost::mpi::packed_skeleton_iarchive, T
> = boost::shared_ptr<Base>]’
> /usr/local/include/boost/serialization/split_free.hpp:74:
> instantiated from ‘void boost::serialization::split_free(Archive&, T&,
> unsigned int) [with Archive = boost::mpi::packed_skeleton_iarchive, T
> = boost::shared_ptr<Base>]’
> /usr/local/include/boost/serialization/shared_ptr.hpp:171:
> instantiated from ‘void boost::serialization::serialize(Archive&,
> boost::shared_ptr<U>&, unsigned int) [with Archive =
> boost::mpi::packed_skeleton_iarchive, T = Base]’
> /usr/local/include/boost/serialization/serialization.hpp:128:
> instantiated from ‘void boost::serialization::serialize_adl(Archive&,
> T&, unsigned int) [with Archive =
> boost::mpi::packed_skeleton_iarchive, T = boost::shared_ptr<Base>]’
> /usr/local/include/boost/archive/detail/iserializer.hpp:188:
> instantiated from ‘void boost::archive::detail::iserializer<Archive,
> T>::load_object_data(boost::archive::detail::basic_iarchive&, void*,
> unsigned int) const [with Archive =
> boost::mpi::packed_skeleton_iarchive, T = boost::shared_ptr<Base>]’
> Derived.cpp:25: instantiated from here
> /usr/local/include/boost/serialization/shared_ptr.hpp:155: error:
> ‘class boost::mpi::packed_skeleton_iarchive’ has no member named ‘reset’
>
>
> If I omit the #include <boost/mpi.hpp> from Derived.cpp everything
> compiles, but as expected I get a runtime error
> terminate called after throwing an instance of
> 'boost::archive::archive_exception'
> what(): unregistered class - derived class not registered or exported
>
>
> Any ideas?
>
> Regards
>
> Max

Just an additional observation that might help to localize the problem.
If I split the serialize function like this:

   friend class boost::serialization::access;
   template<class Archive>
   void save(Archive & ar, const unsigned int version) const
     {
       ar & boost::serialization::base_object<Base>(*this);
       ar & Pointer;
       ar & b;
     }
   template<class Archive>
   void load(Archive & ar, const unsigned int version)
     {
       ar & boost::serialization::base_object<Base>(*this);
       ar & Pointer;
       ar & b;
     }
   BOOST_SERIALIZATION_SPLIT_MEMBER()

the code compiles (but crashes, of course) as long as I comment out the
loading of the pointer.

Max


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk