Warning, file /include/boost/numeric/odeint/external/thrust/thrust_algebra.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
0021
0022
0023 #include <thrust/device_vector.h>
0024 #include <thrust/for_each.h>
0025 #include <thrust/iterator/zip_iterator.h>
0026
0027 #include <boost/range.hpp>
0028
0029 namespace boost {
0030 namespace numeric {
0031 namespace odeint {
0032
0033 namespace detail {
0034
0035
0036 template< class Value >
0037 struct maximum
0038 {
0039 template< class Fac1 , class Fac2 >
0040 __host__ __device__
0041 Value operator()( const Fac1 t1 , const Fac2 t2 ) const
0042 {
0043 return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ;
0044 }
0045
0046 typedef Value result_type;
0047 };
0048
0049 }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 struct thrust_algebra
0063 {
0064 template< class StateType , class Operation >
0065 static void for_each1( StateType &s , Operation op )
0066 {
0067 thrust::for_each( boost::begin(s) , boost::end(s) , op );
0068 }
0069
0070 template< class StateType1 , class StateType2 , class Operation >
0071 static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
0072 {
0073 thrust::for_each(
0074 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0075 boost::begin(s2) ) ) ,
0076 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0077 boost::end(s2) ) ) ,
0078 op);
0079 }
0080
0081 template< class StateType1 , class StateType2 , class StateType3 , class Operation >
0082 static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
0083 {
0084 thrust::for_each(
0085 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0086 boost::begin(s2) ,
0087 boost::begin(s3) ) ) ,
0088 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0089 boost::end(s2) ,
0090 boost::end(s3) ) ) ,
0091 op);
0092 }
0093
0094 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
0095 class Operation >
0096 static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
0097 Operation op )
0098 {
0099 thrust::for_each(
0100 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0101 boost::begin(s2) ,
0102 boost::begin(s3) ,
0103 boost::begin(s4) ) ) ,
0104 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0105 boost::end(s2) ,
0106 boost::end(s3) ,
0107 boost::end(s4) ) ) ,
0108 op);
0109 }
0110
0111 template< class StateType1 , class StateType2 , class StateType3 ,
0112 class StateType4 , class StateType5 ,class Operation >
0113 static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
0114 StateType5 &s5 , Operation op )
0115 {
0116 thrust::for_each(
0117 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0118 boost::begin(s2) ,
0119 boost::begin(s3) ,
0120 boost::begin(s4) ,
0121 boost::begin(s5) ) ) ,
0122 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0123 boost::end(s2) ,
0124 boost::end(s3) ,
0125 boost::end(s4) ,
0126 boost::end(s5) ) ) ,
0127 op);
0128 }
0129
0130 template< class StateType1 , class StateType2 , class StateType3 ,
0131 class StateType4 , class StateType5 , class StateType6 , class Operation >
0132 static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
0133 StateType5 &s5 , StateType6 &s6 , Operation op )
0134 {
0135 thrust::for_each(
0136 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0137 boost::begin(s2) ,
0138 boost::begin(s3) ,
0139 boost::begin(s4) ,
0140 boost::begin(s5) ,
0141 boost::begin(s6) ) ) ,
0142 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0143 boost::end(s2) ,
0144 boost::end(s3) ,
0145 boost::end(s4) ,
0146 boost::end(s5) ,
0147 boost::end(s6) ) ) ,
0148 op);
0149 }
0150
0151 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
0152 class StateType5 , class StateType6 , class StateType7 , class Operation >
0153 static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
0154 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op )
0155 {
0156 thrust::for_each(
0157 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0158 boost::begin(s2) ,
0159 boost::begin(s3) ,
0160 boost::begin(s4) ,
0161 boost::begin(s5) ,
0162 boost::begin(s6) ,
0163 boost::begin(s7) ) ) ,
0164 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0165 boost::end(s2) ,
0166 boost::end(s3) ,
0167 boost::end(s4) ,
0168 boost::end(s5) ,
0169 boost::end(s6) ,
0170 boost::end(s7) ) ) ,
0171 op);
0172 }
0173
0174 template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
0175 class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
0176 static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
0177 StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
0178 {
0179 thrust::for_each(
0180 thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
0181 boost::begin(s2) ,
0182 boost::begin(s3) ,
0183 boost::begin(s4) ,
0184 boost::begin(s5) ,
0185 boost::begin(s6) ,
0186 boost::begin(s7) ,
0187 boost::begin(s8) ) ) ,
0188 thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
0189 boost::end(s2) ,
0190 boost::end(s3) ,
0191 boost::end(s4) ,
0192 boost::end(s5) ,
0193 boost::end(s6) ,
0194 boost::end(s7) ,
0195 boost::end(s8) ) ) ,
0196 op);
0197 }
0198
0199 template< class S >
0200 static typename S::value_type norm_inf( const S &s )
0201 {
0202 typedef typename S::value_type value_type;
0203 return thrust::reduce( boost::begin( s ) , boost::end( s ) ,
0204 static_cast<value_type>(0) ,
0205 detail::maximum<value_type>() );
0206 }
0207
0208 };
0209
0210
0211 }
0212 }
0213 }
0214
0215
0216
0217 #endif