forked from headmyshoulder/odeint-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Pascal Germroth
committed
Jul 21, 2013
1 parent
7a709f7
commit 1ffb155
Showing
5 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<library>/boost/test//boost_unit_test_framework | ||
<library>/boost//mpi | ||
<link>static | ||
<define>BOOST_ALL_NO_LIB=1 | ||
<include>../../../../.. | ||
; | ||
|
||
# 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 ] | ||
; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
#include <cstdlib> | ||
|
||
#define BOOST_TEST_MODULE odeint_mpi | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <boost/numeric/odeint/external/mpi/mpi.hpp> | ||
|
||
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<int> in_data; | ||
mpi_state< std::vector<int> > 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() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
#define BOOST_TEST_MODULE odeint_mpi | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <boost/numeric/odeint/external/mpi/mpi.hpp> | ||
|
||
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<size_t> in_data, out_data; | ||
mpi_state< std::vector<size_t> > 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<size_t>(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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
#define BOOST_TEST_MODULE odeint_mpi | ||
#include <boost/test/unit_test.hpp> | ||
|
||
#include <boost/numeric/odeint/external/mpi/mpi.hpp> | ||
|
||
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<size_t> in_data1, in_data2; | ||
mpi_state< std::vector<size_t> > 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() | ||
|