Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/external/thrust/thrust_algebra.hpp Chris@16: Chris@16: [begin_description] Chris@16: An algebra for thrusts device_vectors. Chris@16: [end_description] Chris@16: Chris@101: Copyright 2010-2013 Mario Mulansky Chris@101: Copyright 2010-2011 Karsten Ahnert Chris@101: Copyright 2013 Kyle Lutz Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENSE_1_0.txt or Chris@16: copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: Chris@16: #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace odeint { Chris@16: Chris@101: namespace detail { Chris@101: Chris@101: // to use in thrust::reduce Chris@101: template< class Value > Chris@101: struct maximum Chris@101: { Chris@101: template< class Fac1 , class Fac2 > Chris@101: __host__ __device__ Chris@101: Value operator()( const Fac1 t1 , const Fac2 t2 ) const Chris@101: { Chris@101: return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ; Chris@101: } Chris@101: Chris@101: typedef Value result_type; Chris@101: }; Chris@101: Chris@101: } Chris@101: Chris@101: Chris@16: Chris@16: Chris@16: /** ToDO extend until for_each14 for rk78 */ Chris@16: Chris@16: /* Chris@16: * The const versions are needed for boost.range to work, i.e. Chris@16: * it allows you to do Chris@16: * for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op ); Chris@16: */ Chris@16: Chris@16: struct thrust_algebra Chris@16: { Chris@16: template< class StateType , class Operation > Chris@16: static void for_each1( StateType &s , Operation op ) Chris@16: { Chris@101: thrust::for_each( boost::begin(s) , boost::end(s) , op ); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class Operation > Chris@16: static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , class Operation > Chris@16: static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , Chris@16: class Operation > Chris@16: static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , Chris@16: Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) , Chris@16: boost::begin(s4) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) , Chris@16: boost::end(s4) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , Chris@16: class StateType4 , class StateType5 ,class Operation > Chris@16: static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , Chris@16: StateType5 &s5 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) , Chris@16: boost::begin(s4) , Chris@16: boost::begin(s5) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) , Chris@16: boost::end(s4) , Chris@16: boost::end(s5) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , Chris@16: class StateType4 , class StateType5 , class StateType6 , class Operation > Chris@16: static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , Chris@16: StateType5 &s5 , StateType6 &s6 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) , Chris@16: boost::begin(s4) , Chris@16: boost::begin(s5) , Chris@16: boost::begin(s6) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) , Chris@16: boost::end(s4) , Chris@16: boost::end(s5) , Chris@16: boost::end(s6) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , Chris@16: class StateType5 , class StateType6 , class StateType7 , class Operation > Chris@16: static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , Chris@16: StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) , Chris@16: boost::begin(s4) , Chris@16: boost::begin(s5) , Chris@16: boost::begin(s6) , Chris@16: boost::begin(s7) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) , Chris@16: boost::end(s4) , Chris@16: boost::end(s5) , Chris@16: boost::end(s6) , Chris@16: boost::end(s7) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@16: template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , Chris@16: class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation > Chris@16: static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , Chris@16: StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op ) Chris@16: { Chris@16: thrust::for_each( Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , Chris@16: boost::begin(s2) , Chris@16: boost::begin(s3) , Chris@16: boost::begin(s4) , Chris@16: boost::begin(s5) , Chris@16: boost::begin(s6) , Chris@16: boost::begin(s7) , Chris@16: boost::begin(s8) ) ) , Chris@16: thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , Chris@16: boost::end(s2) , Chris@16: boost::end(s3) , Chris@16: boost::end(s4) , Chris@16: boost::end(s5) , Chris@16: boost::end(s6) , Chris@16: boost::end(s7) , Chris@16: boost::end(s8) ) ) , Chris@16: op); Chris@16: } Chris@16: Chris@101: template< class S > Chris@101: static typename S::value_type norm_inf( const S &s ) Chris@16: { Chris@101: typedef typename S::value_type value_type; Chris@101: return thrust::reduce( boost::begin( s ) , boost::end( s ) , Chris@101: static_cast(0) , Chris@101: detail::maximum() ); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: } // odeint Chris@16: } // numeric Chris@16: } // boost Chris@16: Chris@16: Chris@16: Chris@16: #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED