pointer_test.cpp 921 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2005, 2006 Douglas Gregor.
  2. // Use, modification and distribution is subject to the Boost Software
  3. // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // a test of pointer serialization
  6. #include <boost/mpi.hpp>
  7. #include <boost/serialization/shared_ptr.hpp>
  8. #define BOOST_TEST_MODULE mpi_pointer
  9. #include <boost/test/included/unit_test.hpp>
  10. class A
  11. {
  12. public:
  13. int i;
  14. template<class Archive>
  15. void serialize(Archive & ar, const unsigned int version)
  16. {
  17. ar & i;
  18. }
  19. };
  20. BOOST_AUTO_TEST_CASE(pointer)
  21. {
  22. boost::mpi::environment env;
  23. boost::mpi::communicator world;
  24. if (world.rank() == 0) {
  25. boost::shared_ptr<A> p(new A);
  26. p->i = 42;
  27. world.send(1, 0, p);
  28. } else if (world.rank() == 1) {
  29. boost::shared_ptr<A> p;
  30. world.recv(0, 0, p);
  31. std::cout << p->i << std::endl;
  32. BOOST_CHECK(p->i==42);
  33. }
  34. }