state_test.cpp 1.8 KB

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