Boost logo

Boost Users :

Subject: [Boost-users] [MPI] Derived class not properly registered, even if it is.
From: Mathieu Larose (mat087_at_[hidden])
Date: 2009-06-10 11:53:11


Hi,

I'm using MPI and I've come to an strange assertion fail from the
library and I was wondering if it was "normal".

Here is the code.

I've got three files: header.hpp main.cpp other.cpp

- - - - - - - -
header.cpp
- - - - - - - -

#ifndef HEADER_HPP
#define HEADER_HPP

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

// Abstract
class A
{
  friend class boost::serialization::access;

  template <class Archive>
    void serialize(Archive & ar, const unsigned int version) {}

public:
  virtual void foo() = 0;
};

class B : public A
{
  friend class boost::serialization::access;

  template <class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
      ar & boost::serialization::base_object<A>(*this);
    }

public:
  void foo() {}
};

#endif

- - - - - - - -
main.cpp
- - - - - - - -

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

#include "header.hpp"

// #include <boost/serialization/export.hpp>
// BOOST_CLASS_EXPORT(B);

int main(int argc, char * argv[])
{
  boost::mpi::environment env(argc, argv);
  boost::mpi::communicator world;

  if (world.rank() == 0)
    {
      A * a = new B;
      world.send(1,0,a);
      std::cout << "sent" << std::endl;
    }
}

- - - - - - - -
other.cpp
- - - - - - - -

#include "header.hpp"
#include <boost/serialization/export.hpp>

BOOST_CLASS_EXPORT(B);

If I run this code I've got this assertion fail:

a.out: ./boost/archive/impl/archive_pointer_oserializer.ipp:64: static
const boost::archive::detail::basic_pointer_oserializer*
boost::archive::detail::archive_pointer_oserializer<Archive>::find(const
boost::serialization::extended_type_info&) [with Archive =
boost::mpi::packed_oarchive]: Assertion `it !=
boost::serialization::singleton< oserializer_map<Archive>
>::get_const_instance().end()' failed.

I realized that if I uncomment these lines in main.cpp:

#include <boost/serialization/export.hpp>
BOOST_CLASS_EXPORT(B);

My code runs correctly.

It seems that BOOST_CLASS_EXPORT needs to be in the same .cpp file
(i.e main.cpp) where MPI is used. When using serialization only,
BOOST_CLASS_EXPORT could be in any .cpp files.

Is this normal?

Also, if A is no more an abstract class, BOOST_CLASS_EXPORT(B); could
be called from other.cpp and the code runs correctly.

I'm using version 1.39.0.

Thank you,

Mathieu Larose


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