|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72290 - in sandbox/odeint/branches/karsten: boost/numeric/odeint/algebra boost/numeric/odeint/stepper boost/numeric/odeint/stepper/detail libs/numeric/odeint/ideas/fusion_runge_kutta libs/numeric/odeint/ideas/fusion_runge_kutta/performance
From: mario.mulansky_at_[hidden]
Date: 2011-05-30 11:37:07
Author: mariomulansky
Date: 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
New Revision: 72290
URL: http://svn.boost.org/trac/boost/changeset/72290
Log:
added algebra_caller and operations_caller for the generic stepper
added performance tests for odeint_generic
Added:
sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp (contents, props changed)
sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp (contents, props changed)
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp (contents, props changed)
Text files modified:
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp | 47 ----------------------------------
sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/range_algebra.hpp | 55 ----------------------------------------
sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp | 14 +++++++--
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp | 4 +-
sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile | 5 +++
5 files changed, 17 insertions(+), 108 deletions(-)
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/default_operations.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -227,53 +227,6 @@
typedef void result_type;
};
-
- /*
- * For generic case
- */
-
- template< size_t n , class Fac = double >
- struct scale_sumn
- {
-// BOOST_STATIC_ASSERT( false );
- };
-
- template< class Fac >
- struct scale_sumn< 1 , Fac > : public scale_sum2< Fac >
- {
- scale_sumn( const boost::array<Fac,1> &a , const Fac &dt ) : scale_sum2< Fac >( 1.0 , a[0]*dt )
- { }
-
- typedef void result_type;
- };
-
- template< class Fac >
- struct scale_sumn< 2 , Fac > : public scale_sum3< Fac >
- {
- scale_sumn( const boost::array<Fac,2> &a , const Fac &dt ) : scale_sum3< Fac >( 1.0 , a[0]*dt , a[1]*dt )
- { }
-
- typedef void result_type;
- };
-
- template< class Fac >
- struct scale_sumn< 3 , Fac > : public scale_sum4< Fac >
- {
- scale_sumn( const boost::array<Fac,3> &a , const Fac &dt ) : scale_sum4< Fac >( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt )
- { }
-
- typedef void result_type;
- };
-
- template< class Fac >
- struct scale_sumn< 4 , Fac > : public scale_sum5< Fac >
- {
- scale_sumn( const boost::array<Fac,4> &a , const Fac &dt ) : scale_sum5< Fac >( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt , a[3]*dt )
- { }
-
- typedef void result_type;
- };
-
/*
* for usage in for_each2
*
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/range_algebra.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/range_algebra.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/algebra/range_algebra.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -82,61 +82,6 @@
return detail::reduce( boost::begin( s ) , boost::end( s ) , red , init );
}
-
- /* for the generic stepper
- */
- template< size_t n , class S1 , class S2 , class S3 , class S4 , class Op >
- inline static void for_eachn( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[n] , Op op )
- {
- for_eachn_fw( s1 , s2 , s3 , s4_array , op , boost::mpl::size_t< n-1 >() );
- }
-
- template< class S1 , class S2 , class S3 , class S4 , class Op >
- inline static void for_eachn_fw( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[0] , Op op ,
- boost::mpl::size_t< 0 > c )
- {
- detail::for_each3( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) ,
- boost::begin( s3 ) , op );
- }
-
- template< class S1 , class S2 , class S3 , class S4 , class Op >
- inline static void for_eachn_fw( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[1] , Op op ,
- boost::mpl::size_t< 1 > c )
- {
- detail::for_each4( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) ,
- boost::begin( s3 ) , boost::begin( s4_array[0] ) , op );
- }
-
- template< class S1 , class S2 , class S3 , class S4 , class Op >
- inline static void for_eachn_fw( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[2] , Op op ,
- boost::mpl::size_t< 2 > c )
- {
- detail::for_each5( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) ,
- boost::begin( s3 ) , boost::begin( s4_array[0] ) ,
- boost::begin( s4_array[1] ) , op );
- }
-
- template< class S1 , class S2 , class S3 , class S4 , class Op >
- inline static void for_eachn_fw( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[3] , Op op ,
- boost::mpl::size_t< 3 > c )
- {
- detail::for_each6( boost::begin( s1 ) , boost::end( s1 ) , boost::begin( s2 ) ,
- boost::begin( s3 ) , boost::begin( s4_array[0] ) ,
- boost::begin( s4_array[1] ) , boost::begin( s4_array[2] ) , op );
- }
-
- /*template< size_t n , class StateOut , class StateIn , class DerivIn , typename T >
- inline static void foreach( StateOut &x_tmp ,
- const boost::array< T , n > &a ,
- const DerivIn &dxdt , const StateIn k_vector[n] , const T dt )
- {
- for( size_t i=0 ; i<x.size() ; ++i )
- {
- x_tmp[i] = a[0]*dt*dxdt[i];
- for( size_t j = 1 ; j<n ; ++j )
- x_tmp[i] += a[j]*dt*k_vector[j-1][i];
- }
- }*/
};
} // odeint
Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -0,0 +1,77 @@
+/*
+ * generic_rk_call_algebra.hpp
+ *
+ * Created on: May 30, 2011
+ * Author: mario
+ */
+
+#ifndef GENERIC_RK_CALL_ALGEBRA_HPP_
+#define GENERIC_RK_CALL_ALGEBRA_HPP_
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+namespace detail {
+
+template< size_t StageNumber , class Algebra >
+struct generic_rk_call_algebra;
+
+template< class Algebra >
+struct generic_rk_call_algebra< 1 , Algebra >
+{
+ template< class S1 , class S2 , class S3 , class S4 , class Op>
+ void operator()( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[0] , Op op ) const
+ {
+ Algebra::for_each3( s1 , s2 , s3 , op );
+ }
+};
+
+template< class Algebra >
+struct generic_rk_call_algebra< 2 , Algebra >
+{
+ template< class S1 , class S2 , class S3 , class S4 , class Op>
+ void operator()( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[1] , Op op ) const
+ {
+ Algebra::for_each4( s1 , s2 , s3 , s4_array[0] , op );
+ }
+};
+
+
+template< class Algebra >
+struct generic_rk_call_algebra< 3 , Algebra >
+{
+ template< class S1 , class S2 , class S3 , class S4 , class Op>
+ void operator()( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[2] , Op op ) const
+ {
+ Algebra::for_each5( s1 , s2 , s3 , s4_array[0] , s4_array[1] , op );
+ }
+};
+
+
+template< class Algebra >
+struct generic_rk_call_algebra< 4 , Algebra >
+{
+ template< class S1 , class S2 , class S3 , class S4 , class Op>
+ void operator()( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[3] , Op op ) const
+ {
+ Algebra::for_each6( s1 , s2 , s3 , s4_array[0] , s4_array[1] , s4_array[2] , op );
+ }
+};
+
+
+template< class Algebra >
+struct generic_rk_call_algebra< 5 , Algebra >
+{
+ template< class S1 , class S2 , class S3 , class S4 , class Op>
+ void operator()( S1 &s1 , S2 &s2 , S3 &s3 , S4 s4_array[4] , Op op ) const
+ {
+ Algebra::for_each7( s1 , s2 , s3 , s4_array[0] , s4_array[1] , s4_array[2] , s4_array[3] , op );
+ }
+};
+
+}
+}
+}
+}
+
+#endif /* GENERIC_RK_CALL_ALGEBRA_HPP_ */
Added: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -0,0 +1,76 @@
+/*
+ * generic_rk_operations.hpp
+ *
+ * Created on: May 30, 2011
+ * Author: mario
+ */
+
+#ifndef GENERIC_RK_OPERATIONS_HPP_
+#define GENERIC_RK_OPERATIONS_HPP_
+
+namespace boost {
+namespace numeric {
+namespace odeint {
+namespace detail {
+
+template< size_t StageNumber , class Operations , class Fac >
+struct generic_rk_scale_sum;
+
+template< class Operations , class Fac >
+struct generic_rk_scale_sum< 1 , Operations , Fac > : public Operations::template scale_sum2< Fac >
+{
+ generic_rk_scale_sum( const boost::array<Fac,1> &a , const Fac &dt ) : Operations::template scale_sum2< Fac >( 1.0 , a[0]*dt )
+ { }
+
+ typedef void result_type;
+};
+
+
+template< class Operations , class Fac >
+struct generic_rk_scale_sum< 2 , Operations , Fac > : public Operations::template scale_sum3< Fac >
+{
+ generic_rk_scale_sum( const boost::array<Fac,2> &a , const Fac &dt )
+ : Operations::template scale_sum3< Fac >( 1.0 , a[0]*dt , a[1]*dt )
+ { }
+
+ typedef void result_type;
+};
+
+template< class Operations , class Fac >
+struct generic_rk_scale_sum< 3 , Operations , Fac > : public Operations::template scale_sum4< Fac >
+{
+ generic_rk_scale_sum( const boost::array<Fac,3> &a , const Fac &dt )
+ : Operations::template scale_sum4< Fac >( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt )
+ { }
+
+ typedef void result_type;
+};
+
+template< class Operations , class Fac >
+struct generic_rk_scale_sum< 4 , Operations , Fac > : public Operations::template scale_sum5< Fac >
+{
+ generic_rk_scale_sum( const boost::array<Fac,4> &a , const Fac &dt )
+ : Operations::template scale_sum5< Fac >( 1.0 , a[0]*dt , a[1]*dt , a[2]*dt , a[3]*dt )
+ { }
+
+ typedef void result_type;
+};
+
+template< class Operations , class Fac >
+struct generic_rk_scale_sum< 5 , Operations , Fac > : public Operations::template scale_sum6< Fac >
+{
+ generic_rk_scale_sum( const boost::array<Fac,5> &a , const Fac &dt )
+ : Operations::template scale_sum6< Fac >( 1.0 , a[0]*dt , a[0]*dt , a[1]*dt , a[2]*dt , a[3]*dt , a[4]*dt )
+ { }
+
+ typedef void result_type;
+};
+
+
+}
+}
+}
+}
+
+
+#endif /* GENERIC_RK_OPERATIONS_HPP_ */
Modified: sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp (original)
+++ sandbox/odeint/branches/karsten/boost/numeric/odeint/stepper/explicit_generic_rk.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -29,6 +29,8 @@
#include <boost/numeric/odeint/stepper/detail/macros.hpp>
#include <boost/numeric/odeint/algebra/range_algebra.hpp>
#include <boost/numeric/odeint/algebra/default_operations.hpp>
+#include <boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp>
+#include <boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp>
//#include "fusion_foreach_performance.hpp"
#include <iostream>
@@ -196,11 +198,15 @@
//std::cout << stage_number-2 << ", t': " << t + stage.c * dt << std::endl;
if( stage_number < StageCount )
- algebra_type::template for_eachn<stage_number>( x_tmp , x , dxdt , F ,
- typename operations_type::template scale_sumn< stage_number , time_type >( stage.a , dt ) );
+ detail::template generic_rk_call_algebra< stage_number , algebra_type >()( x_tmp , x , dxdt , F ,
+ detail::generic_rk_scale_sum< stage_number , operations_type , time_type >( stage.a , dt) );
+// algebra_type::template for_eachn<stage_number>( x_tmp , x , dxdt , F ,
+// typename operations_type::template scale_sumn< stage_number , time_type >( stage.a , dt ) );
else
- algebra_type::template for_eachn<stage_number>( x_out , x , dxdt , F ,
- typename operations_type::template scale_sumn< stage_number , time_type >( stage.a , dt ) );
+ detail::template generic_rk_call_algebra< stage_number , algebra_type >()( x_out , x , dxdt , F ,
+ detail::generic_rk_scale_sum< stage_number , operations_type , time_type >( stage.a , dt) );
+// algebra_type::template for_eachn<stage_number>( x_out , x , dxdt , F ,
+// typename operations_type::template scale_sumn< stage_number , time_type >( stage.a , dt ) );
}
};
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/fusion_algebra.hpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -53,7 +53,7 @@
* Update: It increases performance on msvc 9.0 by about 30%, so it is activated for MSVC
*/
-#ifdef BOOST_MSVC
+//#ifdef BOOST_MSVC
template<>
struct fusion_algebra< 1 >
@@ -192,6 +192,6 @@
};
-#endif /* BOOST_MSVC */
+//#endif /* BOOST_MSVC */
#endif /* FUSION_ALGEBRA_HPP_ */
Modified: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile
==============================================================================
--- sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile (original)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/Jamfile 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -26,6 +26,11 @@
: generic_rk4_lorenz.cpp
: <toolset>intel:<cxxflags>-inline-forceinline
;
+
+exe generic_odeint_rk4_lorenz
+ : generic_odeint_rk4_lorenz.cpp
+ : <toolset>intel:<cxxflags>-inline-forceinline
+ ;
#exe odeint_rk4
# : odeint_rk4.cpp
Added: sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp
==============================================================================
--- (empty file)
+++ sandbox/odeint/branches/karsten/libs/numeric/odeint/ideas/fusion_runge_kutta/performance/generic_odeint_rk4_lorenz.cpp 2011-05-30 11:37:06 EDT (Mon, 30 May 2011)
@@ -0,0 +1,66 @@
+#include <boost/array.hpp>
+
+#include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
+#include <boost/numeric/odeint/algebra/array_algebra.hpp>
+
+#include "rk_performance_test_case.hpp"
+
+#include "lorenz.hpp"
+
+using namespace boost::numeric::odeint;
+
+typedef boost::array< double , 3 > state_type;
+typedef explicit_generic_rk< 4 , 4 , state_type , double , state_type , double , array_algebra > rk4_type;
+
+typedef rk4_type::coef_a_type coef_a_type;
+typedef rk4_type::coef_b_type coef_b_type;
+typedef rk4_type::coef_c_type coef_c_type;
+
+const boost::array< double , 1 > a1 = {{ 0.5 }};
+const boost::array< double , 2 > a2 = {{ 0.0 , 0.5 }};
+const boost::array< double , 3 > a3 = {{ 0.0 , 0.0 , 1.0 }};
+
+const coef_a_type a = fusion::make_vector( a1 , a2 , a3 );
+const coef_b_type b = {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }};
+const coef_c_type c = {{ 0.0 , 0.5 , 0.5 , 1.0 }};
+
+class rk4_wrapper
+{
+
+public:
+
+ rk4_wrapper() : m_stepper( a , b , c )
+ { }
+
+ void reset_init_cond()
+ {
+ m_x[0] = 10.0 * rand() / RAND_MAX;
+ m_x[1] = 10.0 * rand() / RAND_MAX;
+ m_x[2] = 10.0 * rand() / RAND_MAX;
+ m_t = 0.0;
+ }
+
+ inline void do_step( const double dt )
+ {
+ m_stepper.do_step( lorenz(), m_x , m_t , dt );
+ }
+
+ double state( const size_t i ) const
+ { return m_x[i]; }
+
+private:
+ state_type m_x;
+ double m_t;
+ rk4_type m_stepper;
+};
+
+
+
+int main()
+{
+ srand( 12312354 );
+
+ rk4_wrapper stepper;
+
+ run( stepper );
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk