Boost logo

Boost :

Subject: [boost] Boost mpi, serialization and shared_ptr
From: Max Moorkamp (mm489_at_[hidden])
Date: 2012-06-01 11:05:05


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.

#include <boost/serialization/serialization.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/mpi.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/export.hpp>

class Base
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
}
public:
Base()
{
}
virtual ~Base()
{
}
};

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(Base)
BOOST_CLASS_EXPORT(Derived)
int main(int argc, char *argv[])
{
boost::mpi::environment env(argc, argv);
boost::mpi::communicator world;

boost::shared_ptr<Base> Pointer(new Derived());

boost::mpi::broadcast(world, Pointer, 0);

}

I want to broadcast the derived class that has a member that is a
shared_ptr. When I compile this code with gcc-4.6, intel or clang all
compilers complain, this is the output from gcc-4.6

In file included from Hacks/serialization_mpi.cpp:11:0:
/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:9: 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:5: 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:5:
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:9:
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:5:
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>]’
Hacks/serialization_mpi.cpp:64:3: instantiated from here
/usr/local/include/boost/serialization/shared_ptr.hpp:133:9: error:
‘class boost::mpi::packed_skeleton_iarchive’ has no member named ‘append’
/usr/local/include/boost/serialization/shared_ptr.hpp:139:5: error:
‘class boost::mpi::packed_skeleton_iarchive’ has no member named ‘reset’

If I remove the shared_ptr member, it compiles and runs. If I remove
BOOST_CLASS_EXPORT(Derived) it compiles, but when running it I get

terminate called after throwing an instance of
'boost::archive::archive_exception'
what(): unregistered class - derived class not registered or exported

Is this a bug or am I doing something wrong? A google search shows an
old discussion (2007) that concludes that this problem is fixed in boost
1.45. I see this happening with both 1.48 and 1.49. Any help is appreciated.

Regards

Max


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