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