#include #include #include // the next two headers are critical for compilation/linking //#include //#include namespace mpi = boost::mpi; class Base { public: virtual int get() const { return 1; } private: friend class boost::serialization::access; template void serialize(TArchive& archive, const unsigned int version) {} }; class Derived : public Base { public: virtual int get() const { return 2; } private: // grant Boost.serialize access to this class friend class boost::serialization::access; template void serialize(TArchive& archive, const unsigned int version) { // serialize base class archive & boost::serialization::base_object(*this); } }; BOOST_CLASS_EXPORT(Derived) int main(int argc, char* argv[]) { mpi::environment env(argc, argv); mpi::communicator world; if (world.rank() == 0) { // send a Derived Base* b = new Derived; std::cout << "Process " << world.rank() << " sends object with b->get() = " << b->get() << std::endl; world.send(1, 0, b); delete b; // receive a Base world.recv(1, 1, b); std::cout << "Process " << world.rank() << " got object with b->get() = " << b->get() << std::endl; delete b; } else { // receive a Derived Base* b; world.recv(0, 0, b); std::cout << "Process " << world.rank() << " got object with b->get() = " << b->get() << std::endl; delete b; // send a Base b = new Base; std::cout << "Process " << world.rank() << " sends object with b->get() = " << b->get() << std::endl; world.send(0, 1, b); delete b; } return 0; }