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
#include
// 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
#include "header.hpp"
// #include
// 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_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_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