• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  Copyright 2013 Karsten Ahnert
3  Copyright 2013 Mario Mulansky
4  Copyright 2013 Pascal Germroth
5 
6  Distributed under the Boost Software License, Version 1.0.
7  (See accompanying file LICENSE_1_0.txt or
8  copy at http://www.boost.org/LICENSE_1_0.txt)
9  */
10 
11 #include <iostream>
12 #include <sstream>
13 
14 #define BOOST_TEST_MODULE odeint_mpi
15 #include <boost/test/unit_test.hpp>
16 
17 #include <boost/numeric/odeint/external/mpi/mpi.hpp>
18 
19 using namespace boost::numeric::odeint;
20 
21 boost::mpi::environment env;
22 
23 BOOST_AUTO_TEST_SUITE( state_test_suite )
24 
BOOST_AUTO_TEST_CASE(state_test)25 BOOST_AUTO_TEST_CASE( state_test )
26 {
27     boost::mpi::communicator world;
28 
29     std::vector<size_t> in_data1, in_data2;
30     mpi_state< std::vector<size_t> > state1(world), state2(world);
31 
32     // generate data on master
33     if(world.rank() == 0) {
34         in_data1.resize(31);
35         in_data2.resize(33);
36         for(size_t i = 0 ; i < in_data2.size() ; i++)
37             in_data2[i] = i;
38     }
39 
40     // copy to nodes
41     split( in_data1, state1 );
42     split( in_data2, state2 );
43 
44     {
45         std::ostringstream ss;
46         ss << "state[" << world.rank() << "] {"
47            << state1().size() << ", "
48            << state2().size() << "}\n";
49         std::clog << ss.str() << std::flush;
50     }
51 
52     // compare size
53     BOOST_REQUIRE( !same_size( state1, state2 ) );
54 
55     // resize state1 to match state2.
56     resize( state1, state2 );
57 
58     {
59         std::ostringstream ss;
60         ss << "state[" << world.rank() << "] 1:"
61            << state1().size() << " 2:"
62            << state2().size() << "\n";
63         std::clog << ss.str() << std::flush;
64     }
65 
66     // compare size
67     BOOST_REQUIRE( same_size( state1, state2 ) );
68 
69     // copy state2 to state1
70     copy( state2, state1 );
71 
72     BOOST_REQUIRE_EQUAL_COLLECTIONS(state1().begin(), state1().end(),
73         state2().begin(), state2().end());
74 }
75 
76 
77 BOOST_AUTO_TEST_SUITE_END()
78 
79