Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / numeric / odeint / test_external / mpi / norm_test.cpp
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 #include <cstdlib>
14
15 #define BOOST_TEST_MODULE odeint_mpi
16 #include <boost/test/unit_test.hpp>
17
18 #include <boost/numeric/odeint/external/mpi/mpi.hpp>
19
20 using namespace boost::numeric::odeint;
21
22 boost::mpi::environment env;
23
24 BOOST_AUTO_TEST_SUITE( norm_test_suite )
25
26 BOOST_AUTO_TEST_CASE( norm_test )
27 {
28     boost::mpi::communicator world;
29
30     int ref_value = 0;
31     std::vector<int> in_data;
32     mpi_state< std::vector<int> > state(world);
33
34     // generate data and reference value on master
35     if(world.rank() == 0) {
36         for(size_t i = 0 ; i < 400 ; i++)
37             in_data.push_back( rand() % 10000 );
38         ref_value = *std::max_element(in_data.begin(), in_data.end());
39     }
40     boost::mpi::broadcast(world, ref_value, 0);
41
42     // copy to nodes
43     split( in_data, state );
44
45     int value = mpi_nested_algebra< range_algebra >::norm_inf( state );
46
47     {
48         std::ostringstream ss;
49         ss << "state[" << world.rank() << "]"
50            << " local:" << range_algebra::norm_inf( state() )
51            << " global:" << value
52            << " ref:" << ref_value << "\n";
53         std::clog << ss.str() << std::flush;
54     }
55
56     BOOST_REQUIRE_EQUAL( value, ref_value );
57 }
58
59
60 BOOST_AUTO_TEST_SUITE_END()
61
62