3 boost/numeric/odeint/external/thrust/thrust_algebra.hpp
6 An algebra for thrusts device_vectors.
9 Copyright 2010-2013 Mario Mulansky
10 Copyright 2010-2011 Karsten Ahnert
11 Copyright 2013 Kyle Lutz
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
23 #include <thrust/device_vector.h>
24 #include <thrust/for_each.h>
25 #include <thrust/iterator/zip_iterator.h>
27 #include <boost/range.hpp>
35 // to use in thrust::reduce
36 template< class Value >
39 template< class Fac1 , class Fac2 >
41 Value operator()( const Fac1 t1 , const Fac2 t2 ) const
43 return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ;
46 typedef Value result_type;
54 /** ToDO extend until for_each14 for rk78 */
57 * The const versions are needed for boost.range to work, i.e.
59 * for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op );
64 template< class StateType , class Operation >
65 static void for_each1( StateType &s , Operation op )
67 thrust::for_each( boost::begin(s) , boost::end(s) , op );
70 template< class StateType1 , class StateType2 , class Operation >
71 static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
74 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
75 boost::begin(s2) ) ) ,
76 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
81 template< class StateType1 , class StateType2 , class StateType3 , class Operation >
82 static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
85 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
87 boost::begin(s3) ) ) ,
88 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
94 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
96 static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
100 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
103 boost::begin(s4) ) ) ,
104 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
111 template< class StateType1 , class StateType2 , class StateType3 ,
112 class StateType4 , class StateType5 ,class Operation >
113 static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
114 StateType5 &s5 , Operation op )
117 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
121 boost::begin(s5) ) ) ,
122 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
130 template< class StateType1 , class StateType2 , class StateType3 ,
131 class StateType4 , class StateType5 , class StateType6 , class Operation >
132 static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
133 StateType5 &s5 , StateType6 &s6 , Operation op )
136 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
141 boost::begin(s6) ) ) ,
142 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
151 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
152 class StateType5 , class StateType6 , class StateType7 , class Operation >
153 static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
154 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op )
157 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
163 boost::begin(s7) ) ) ,
164 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
174 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
175 class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
176 static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
177 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
180 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
187 boost::begin(s8) ) ) ,
188 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
200 static typename S::value_type norm_inf( const S &s )
202 typedef typename S::value_type value_type;
203 return thrust::reduce( boost::begin( s ) , boost::end( s ) ,
204 static_cast<value_type>(0) ,
205 detail::maximum<value_type>() );
217 #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED