Skip to content

Commit

Permalink
Reorganize OpenMP algebra and state. #5 #6 #7
Browse files Browse the repository at this point in the history
openmp_range_algebra: parallel for over a random access container.
openmp_nested_algebra: processs parts of a split container in parallel.
openmp_state: a split container based on vector<vector<>>.
openmp_algebra: use a range_algebra on each part of that container.
  • Loading branch information
Pascal Germroth committed Jul 19, 2013
1 parent 53fa449 commit de83cdc
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 256 deletions.
10 changes: 6 additions & 4 deletions boost/numeric/odeint/external/openmp/openmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_HPP_INCLUDED

// level 1: parallel iteration over random access container
#include "openmp_range_algebra.hpp"

// level 2: split range state
#include "openmp_state.hpp"
#include "openmp_algebra.hpp"
#include "openmp_algebra_dispatcher.hpp"
#include "openmp_resize.hpp"
#include "openmp_system.hpp"

// level 3: process a random access container of sub-states in parallel
#include "openmp_nested_algebra.hpp"

#endif
101 changes: 0 additions & 101 deletions boost/numeric/odeint/external/openmp/openmp_algebra.hpp

This file was deleted.

40 changes: 0 additions & 40 deletions boost/numeric/odeint/external/openmp/openmp_algebra_dispatcher.hpp

This file was deleted.

71 changes: 71 additions & 0 deletions boost/numeric/odeint/external/openmp/openmp_nested_algebra.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
[auto_generated]
boost/numeric/odeint/external/openmp/openmp_nested_algebra.hpp
[begin_description]
Nested parallelized algebra for OpenMP.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 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)
*/


#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_NESTED_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_NESTED_ALGEBRA_HPP_INCLUDED

#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
#include <boost/numeric/odeint/util/n_ary_helper.hpp>

namespace boost {
namespace numeric {
namespace odeint {

/** \brief OpenMP-parallelized algebra, wrapping another, non-parallelized algebra.
* The NestedState must be a Random Access Container where the elements are sub-states
* which will be processed in parallel.
*
* Requires a NestedState with `s::value_type`, `s[n]` and `s.size()`.
*/
template< class InnerAlgebra >
struct openmp_nested_algebra
{

// FIXME: _Pragma is C++11.
#define BOOST_ODEINT_GEN_BODY(n) \
const size_t len = s0.size(); \
_Pragma("omp parallel for schedule(runtime)") \
for( size_t i = 0 ; i < len ; i++ ) \
InnerAlgebra::for_each##n( \
BOOST_PP_ENUM_BINARY_PARAMS(n, s, [i] BOOST_PP_INTERCEPT) , \
op \
);
BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
#undef BOOST_ODEINT_GEN_BODY


template< class NestedState >
static typename norm_result_type< typename NestedState::value_type >::type norm_inf( const NestedState &s )
{
using std::max;
using std::abs;
typedef typename norm_result_type< typename NestedState::value_type >::type result_type;
result_type init = static_cast< result_type >( 0 );
# pragma omp parallel for reduction(max: init) schedule(dynamic)
for( size_t i = 0 ; i < s.size() ; i++ )
init = max( init , InnerAlgebra::norm_inf( s[i] ) );
return init;
}

};


}
}
}

#endif
65 changes: 65 additions & 0 deletions boost/numeric/odeint/external/openmp/openmp_range_algebra.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
[auto_generated]
boost/numeric/odeint/external/openmp/openmp_range_algebra.hpp
[begin_description]
Range algebra for OpenMP.
[end_description]
Copyright 2009-2011 Karsten Ahnert
Copyright 2009-2011 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)
*/


#ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_RANGE_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_OPENMP_OPENMP_RANGE_ALGEBRA_HPP_INCLUDED

#include <boost/numeric/odeint/algebra/norm_result_type.hpp>
#include <boost/numeric/odeint/util/n_ary_helper.hpp>

namespace boost {
namespace numeric {
namespace odeint {

/** \brief OpenMP-parallelized range algebra.
*
* Requires a state with `s.size()` and `s[n]`, i.e. a Random Access Container.
*/
struct openmp_range_algebra
{

// FIXME: _Pragma is C++11.
#define BOOST_ODEINT_GEN_BODY(n) \
const size_t len = s0.size(); \
_Pragma("omp parallel for schedule(runtime)") \
for( size_t i = 0 ; i < len ; i++ ) \
op( BOOST_PP_ENUM_BINARY_PARAMS(n, s, [i] BOOST_PP_INTERCEPT) );
BOOST_ODEINT_GEN_FOR_EACH(BOOST_ODEINT_GEN_BODY)
#undef BOOST_ODEINT_GEN_BODY


template< class S >
static typename norm_result_type< S >::type norm_inf( const S &s )
{
using std::max;
using std::abs;
typedef typename norm_result_type< S >::type result_type;
result_type init = static_cast< result_type >( 0 );
# pragma omp parallel for reduction(max: init) schedule(dynamic)
for( size_t i = 0 ; i < s.size() ; ++i )
init = max( init , abs(s[i]) );
return init;
}

};


}
}
}

#endif
87 changes: 0 additions & 87 deletions boost/numeric/odeint/external/openmp/openmp_resize.hpp

This file was deleted.

Loading

0 comments on commit de83cdc

Please sign in to comment.