From 1ffb155345fd8b6a8ef7e83ed338d2ecc6332752 Mon Sep 17 00:00:00 2001 From: Pascal Germroth Date: Sun, 21 Jul 2013 04:39:40 +0200 Subject: [PATCH] Unit tests for MPI state #9, resize #11 and reduction #12 --- Jamroot | 1 + .../odeint/test_external/mpi/Jamfile.v2 | 26 +++++++ .../odeint/test_external/mpi/norm_test.cpp | 52 ++++++++++++++ .../odeint/test_external/mpi/split_test.cpp | 53 +++++++++++++++ .../odeint/test_external/mpi/state_test.cpp | 68 +++++++++++++++++++ 5 files changed, 200 insertions(+) create mode 100644 libs/numeric/odeint/test_external/mpi/Jamfile.v2 create mode 100644 libs/numeric/odeint/test_external/mpi/norm_test.cpp create mode 100644 libs/numeric/odeint/test_external/mpi/split_test.cpp create mode 100644 libs/numeric/odeint/test_external/mpi/state_test.cpp diff --git a/Jamroot b/Jamroot index 85103e8e..b2c83b65 100644 --- a/Jamroot +++ b/Jamroot @@ -30,6 +30,7 @@ build-project libs/numeric/odeint/performance/openmp ; # build-project libs/numeric/odeint/test_external/mtl4 ; # build-project libs/numeric/odeint/test_external/thrust ; # build-project libs/numeric/odeint/test_external/vexcl ; +build-project libs/numeric/odeint/test_external/mpi ; # docs: diff --git a/libs/numeric/odeint/test_external/mpi/Jamfile.v2 b/libs/numeric/odeint/test_external/mpi/Jamfile.v2 new file mode 100644 index 00000000..49f05700 --- /dev/null +++ b/libs/numeric/odeint/test_external/mpi/Jamfile.v2 @@ -0,0 +1,26 @@ +# (C) Copyright 2010 : Karsten Ahnert, Mario Mulansky +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +import testing ; +import mpi : mpi-test ; + +use-project boost : $(BOOST_ROOT) ; + +project + : requirements + /boost/test//boost_unit_test_framework + /boost//mpi + static + BOOST_ALL_NO_LIB=1 + ../../../../.. + ; + +# mpi-test name : source : req : np=1 2 3 4 7 8 13 17 +test-suite "odeint-mpi" + : + [ mpi-test split_test ] + [ mpi-test state_test ] + [ mpi-test norm_test ] + ; + diff --git a/libs/numeric/odeint/test_external/mpi/norm_test.cpp b/libs/numeric/odeint/test_external/mpi/norm_test.cpp new file mode 100644 index 00000000..58a521c9 --- /dev/null +++ b/libs/numeric/odeint/test_external/mpi/norm_test.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +#define BOOST_TEST_MODULE odeint_mpi +#include + +#include + +using namespace boost::numeric::odeint; + +boost::mpi::environment env; + +BOOST_AUTO_TEST_SUITE( norm_test_suite ) + +BOOST_AUTO_TEST_CASE( norm_test ) +{ + boost::mpi::communicator world; + + int ref_value = 0; + std::vector in_data; + mpi_state< std::vector > state(world); + + // generate data and reference value on master + if(world.rank() == 0) { + for(size_t i = 0 ; i < 400 ; i++) + in_data.push_back( rand() % 10000 ); + ref_value = *std::max_element(in_data.begin(), in_data.end()); + } + boost::mpi::broadcast(world, ref_value, 0); + + // copy to nodes + copy( in_data, state ); + + int value = mpi_nested_algebra< range_algebra >::norm_inf( state ); + + { + std::ostringstream ss; + ss << "state[" << world.rank() << "]" + << " local:" << range_algebra::norm_inf( state.data ) + << " global:" << value + << " ref:" << ref_value << "\n"; + std::clog << ss.str() << std::flush; + } + + BOOST_REQUIRE_EQUAL( value, ref_value ); +} + + +BOOST_AUTO_TEST_SUITE_END() + + diff --git a/libs/numeric/odeint/test_external/mpi/split_test.cpp b/libs/numeric/odeint/test_external/mpi/split_test.cpp new file mode 100644 index 00000000..85e43355 --- /dev/null +++ b/libs/numeric/odeint/test_external/mpi/split_test.cpp @@ -0,0 +1,53 @@ +#include +#include + +#define BOOST_TEST_MODULE odeint_mpi +#include + +#include + +using namespace boost::numeric::odeint; + +boost::mpi::environment env; + +BOOST_AUTO_TEST_SUITE( split_test_suite ) + +BOOST_AUTO_TEST_CASE( split_test ) +{ + boost::mpi::communicator world; + + const size_t total_size = 31; + + std::vector in_data, out_data; + mpi_state< std::vector > state(world); + + // generate data on master + if(world.rank() == 0) + for(size_t i = 0 ; i < total_size ; i++) in_data.push_back(i); + + // copy to nodes + copy( in_data, state ); + + BOOST_REQUIRE((state.data.size() == total_size / world.size()) + || (state.data.size() == total_size / world.size() + 1)); + + { + std::ostringstream ss; + ss << "state[" << world.rank() << "].data = {"; + std::copy(state.data.begin(), state.data.end(), std::ostream_iterator(ss, ", ")); + ss << "}\n"; + std::clog << ss.str() << std::flush; + } + + // copy back to master + copy( state, out_data ); + + if(world.rank() == 0) { + BOOST_REQUIRE_EQUAL_COLLECTIONS(in_data.begin(), in_data.end(), out_data.begin(), out_data.end()); + } else { + BOOST_REQUIRE(out_data.size() == 0); + } +} + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/numeric/odeint/test_external/mpi/state_test.cpp b/libs/numeric/odeint/test_external/mpi/state_test.cpp new file mode 100644 index 00000000..5d41aab1 --- /dev/null +++ b/libs/numeric/odeint/test_external/mpi/state_test.cpp @@ -0,0 +1,68 @@ +#include +#include + +#define BOOST_TEST_MODULE odeint_mpi +#include + +#include + +using namespace boost::numeric::odeint; + +boost::mpi::environment env; + +BOOST_AUTO_TEST_SUITE( state_test_suite ) + +BOOST_AUTO_TEST_CASE( state_test ) +{ + boost::mpi::communicator world; + + std::vector in_data1, in_data2; + mpi_state< std::vector > state1(world), state2(world); + + // generate data on master + if(world.rank() == 0) { + in_data1.resize(31); + in_data2.resize(33); + for(size_t i = 0 ; i < in_data2.size() ; i++) + in_data2[i] = i; + } + + // copy to nodes + copy( in_data1, state1 ); + copy( in_data2, state2 ); + + { + std::ostringstream ss; + ss << "state[" << world.rank() << "] {" + << state1.data.size() << ", " + << state2.data.size() << "}\n"; + std::clog << ss.str() << std::flush; + } + + // compare size + BOOST_REQUIRE( !same_size( state1, state2 ) ); + + // resize state1 to match state2. + resize( state1, state2 ); + + { + std::ostringstream ss; + ss << "state[" << world.rank() << "] 1:" + << state1.data.size() << " 2:" + << state2.data.size() << "\n"; + std::clog << ss.str() << std::flush; + } + + // compare size + BOOST_REQUIRE( same_size( state1, state2 ) ); + + // copy state2 to state1 + copy( state2, state1 ); + + BOOST_REQUIRE_EQUAL_COLLECTIONS(state1.data.begin(), state1.data.end(), + state2.data.begin(), state2.data.end()); +} + + +BOOST_AUTO_TEST_SUITE_END() +