• 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( split_test_suite )
24 
BOOST_AUTO_TEST_CASE(split_test)25 BOOST_AUTO_TEST_CASE( split_test )
26 {
27     boost::mpi::communicator world;
28 
29     const size_t total_size = 31;
30 
31     std::vector<size_t> in_data, out_data;
32     mpi_state< std::vector<size_t> > state(world);
33 
34     // generate data on master
35     if(world.rank() == 0)
36         for(size_t i = 0 ; i < total_size ; i++) in_data.push_back(i);
37 
38     // copy to nodes
39     split( in_data, state );
40 
41     BOOST_REQUIRE((state().size() == total_size / world.size())
42                || (state().size() == total_size / world.size() + 1));
43 
44     {
45         std::ostringstream ss;
46         ss << "state[" << world.rank() << "].data = {";
47         std::copy(state().begin(), state().end(), std::ostream_iterator<size_t>(ss, ", "));
48         ss << "}\n";
49         std::clog << ss.str() << std::flush;
50     }
51 
52     // copy back to master
53     if(world.rank() == 0) out_data.resize(in_data.size());
54     unsplit( state, out_data );
55 
56     if(world.rank() == 0)
57         BOOST_REQUIRE_EQUAL_COLLECTIONS(in_data.begin(), in_data.end(), out_data.begin(), out_data.end());
58 }
59 
60 
61 BOOST_AUTO_TEST_SUITE_END()
62