1 /* 2 [auto_generated] 3 boost/numeric/odeint/external/thrust/thrust_algebra.hpp 4 5 [begin_description] 6 An algebra for thrusts device_vectors. 7 [end_description] 8 9 Copyright 2010-2013 Mario Mulansky 10 Copyright 2010-2011 Karsten Ahnert 11 Copyright 2013 Kyle Lutz 12 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) 16 */ 17 18 19 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED 20 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED 21 22 23 #include <thrust/device_vector.h> 24 #include <thrust/for_each.h> 25 #include <thrust/iterator/zip_iterator.h> 26 27 #include <boost/range.hpp> 28 29 namespace boost { 30 namespace numeric { 31 namespace odeint { 32 33 namespace detail { 34 35 // to use in thrust::reduce 36 template< class Value > 37 struct maximum 38 { 39 template< class Fac1 , class Fac2 > 40 __host__ __device__ operator ()boost::numeric::odeint::detail::maximum41 Value operator()( const Fac1 t1 , const Fac2 t2 ) const 42 { 43 return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ; 44 } 45 46 typedef Value result_type; 47 }; 48 49 } 50 51 52 53 54 /** ToDO extend until for_each14 for rk78 */ 55 56 /* 57 * The const versions are needed for boost.range to work, i.e. 58 * it allows you to do 59 * for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op ); 60 */ 61 62 struct thrust_algebra 63 { 64 template< class StateType , class Operation > for_each1boost::numeric::odeint::thrust_algebra65 static void for_each1( StateType &s , Operation op ) 66 { 67 thrust::for_each( boost::begin(s) , boost::end(s) , op ); 68 } 69 70 template< class StateType1 , class StateType2 , class Operation > for_each2boost::numeric::odeint::thrust_algebra71 static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op ) 72 { 73 thrust::for_each( 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) , 77 boost::end(s2) ) ) , 78 op); 79 } 80 81 template< class StateType1 , class StateType2 , class StateType3 , class Operation > for_each3boost::numeric::odeint::thrust_algebra82 static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op ) 83 { 84 thrust::for_each( 85 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 86 boost::begin(s2) , 87 boost::begin(s3) ) ) , 88 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 89 boost::end(s2) , 90 boost::end(s3) ) ) , 91 op); 92 } 93 94 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , 95 class Operation > for_each4boost::numeric::odeint::thrust_algebra96 static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , 97 Operation op ) 98 { 99 thrust::for_each( 100 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 101 boost::begin(s2) , 102 boost::begin(s3) , 103 boost::begin(s4) ) ) , 104 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 105 boost::end(s2) , 106 boost::end(s3) , 107 boost::end(s4) ) ) , 108 op); 109 } 110 111 template< class StateType1 , class StateType2 , class StateType3 , 112 class StateType4 , class StateType5 ,class Operation > for_each5boost::numeric::odeint::thrust_algebra113 static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , 114 StateType5 &s5 , Operation op ) 115 { 116 thrust::for_each( 117 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 118 boost::begin(s2) , 119 boost::begin(s3) , 120 boost::begin(s4) , 121 boost::begin(s5) ) ) , 122 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 123 boost::end(s2) , 124 boost::end(s3) , 125 boost::end(s4) , 126 boost::end(s5) ) ) , 127 op); 128 } 129 130 template< class StateType1 , class StateType2 , class StateType3 , 131 class StateType4 , class StateType5 , class StateType6 , class Operation > for_each6boost::numeric::odeint::thrust_algebra132 static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , 133 StateType5 &s5 , StateType6 &s6 , Operation op ) 134 { 135 thrust::for_each( 136 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 137 boost::begin(s2) , 138 boost::begin(s3) , 139 boost::begin(s4) , 140 boost::begin(s5) , 141 boost::begin(s6) ) ) , 142 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 143 boost::end(s2) , 144 boost::end(s3) , 145 boost::end(s4) , 146 boost::end(s5) , 147 boost::end(s6) ) ) , 148 op); 149 } 150 151 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , 152 class StateType5 , class StateType6 , class StateType7 , class Operation > for_each7boost::numeric::odeint::thrust_algebra153 static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , 154 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op ) 155 { 156 thrust::for_each( 157 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 158 boost::begin(s2) , 159 boost::begin(s3) , 160 boost::begin(s4) , 161 boost::begin(s5) , 162 boost::begin(s6) , 163 boost::begin(s7) ) ) , 164 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 165 boost::end(s2) , 166 boost::end(s3) , 167 boost::end(s4) , 168 boost::end(s5) , 169 boost::end(s6) , 170 boost::end(s7) ) ) , 171 op); 172 } 173 174 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 , 175 class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation > for_each8boost::numeric::odeint::thrust_algebra176 static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 , 177 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op ) 178 { 179 thrust::for_each( 180 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) , 181 boost::begin(s2) , 182 boost::begin(s3) , 183 boost::begin(s4) , 184 boost::begin(s5) , 185 boost::begin(s6) , 186 boost::begin(s7) , 187 boost::begin(s8) ) ) , 188 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) , 189 boost::end(s2) , 190 boost::end(s3) , 191 boost::end(s4) , 192 boost::end(s5) , 193 boost::end(s6) , 194 boost::end(s7) , 195 boost::end(s8) ) ) , 196 op); 197 } 198 199 template< class S > norm_infboost::numeric::odeint::thrust_algebra200 static typename S::value_type norm_inf( const S &s ) 201 { 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>() ); 206 } 207 208 }; 209 210 211 } // odeint 212 } // numeric 213 } // boost 214 215 216 217 #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED 218