Boost logo

Boost :

Subject: Re: [boost] Boost mpi, serialization and shared_ptr
From: Max Moorkamp (mm489_at_[hidden])
Date: 2012-06-13 05:22:52


On 12/06/12 18:05, Robert Ramey wrote:
> Max Moorkamp wrote:
>>> /usr/local/include/boost/serialization/shared_ptr.hpp:155: error:
>>> ‘class boost::mpi::packed_skeleton_iarchive’ has no member named
>>> ‘reset’
> Here is he key.
>
> The serialization library has some special code to handle boosts
> beloved shared_ptr. This special code is found in
> boost/archive/shared_ptr_helper.hpp.
>
> it is added in at the "last possible moment" via public inheritance.
> see "boost\archive\binary_iarchive.hpp". This adds a special
> function called "reset". It seems that MPI serialization doesn't
> add in this functionality - hence the compile error.
>
> So the fix would be tweak the MPI serialization implementation
> to address this. It's not clear to me what this would entail.
>
> Longer term - some day - would be to add the functionaliy
> of a "generic helper" which any serialization implementation
> could use to permit serialization of otherwise unserializable
> classes.
>
> Robert Ramey
>
I see,

looking at boost/mpi/packed_oarchive.hpp and
boost/mpi/packed_iarchive.hpp I find

class BOOST_MPI_DECL packed_iarchive
   : public iprimitive
   , public archive::detail::common_iarchive<packed_iarchive>
   , public archive::detail::shared_ptr_helper
{

and

class BOOST_MPI_DECL packed_oarchive
   : public oprimitive
   , public archive::detail::common_oarchive<packed_oarchive>
   , public archive::detail::shared_ptr_helper
{

so that seems to be in order. Interestingly this:

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

class MyClass
   {
private:
   double a;
   friend class boost::serialization::access;
   template<class Archive>
   void serialize(Archive & ar, const unsigned int version)
     {
       ar & a;
     }
public:
   void SetA(double value)
     {
       a = value;
     }
   double GetA()
     {
       return a;
     }
   MyClass()
     {
     }
   virtual ~MyClass()
     {
     }
   };

int main(int argc, char *argv[])
   {

     boost::mpi::environment env(argc, argv);
     boost::mpi::communicator world;

     boost::shared_ptr<MyClass> ClassPointer(new MyClass());
     if (world.rank() == 0)
       {
         ClassPointer->SetA(5.0);
       }
     boost::mpi::broadcast(world, ClassPointer, 0);

     std::cout << "Rank: " << world.rank() << " " <<
ClassPointer->GetA() << std::endl;

   }

compiles and works as expected. So it appears that the problem is not
the serialization of shared_ptr as such, but only if it is a member of a
class.

Regards

Max


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