thrust_algebra.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/thrust/thrust_algebra.hpp
  4. [begin_description]
  5. An algebra for thrusts device_vectors.
  6. [end_description]
  7. Copyright 2009-2011 Karsten Ahnert
  8. Copyright 2009-2011 Mario Mulansky
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
  15. #include <thrust/device_vector.h>
  16. #include <thrust/for_each.h>
  17. #include <thrust/iterator/zip_iterator.h>
  18. #include <boost/range.hpp>
  19. namespace boost {
  20. namespace numeric {
  21. namespace odeint {
  22. /** ToDO extend until for_each14 for rk78 */
  23. /*
  24. * The const versions are needed for boost.range to work, i.e.
  25. * it allows you to do
  26. * for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op );
  27. */
  28. struct thrust_algebra
  29. {
  30. template< class StateType , class Operation >
  31. static void for_each1( StateType &s , Operation op )
  32. {
  33. thrust::for_each( boost::begin(s) , boost::begin(s) , op );
  34. }
  35. template< class StateType1 , class StateType2 , class Operation >
  36. static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
  37. {
  38. thrust::for_each(
  39. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  40. boost::begin(s2) ) ) ,
  41. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  42. boost::end(s2) ) ) ,
  43. op);
  44. }
  45. template< class StateType1 , class StateType2 , class StateType3 , class Operation >
  46. static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
  47. {
  48. thrust::for_each(
  49. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  50. boost::begin(s2) ,
  51. boost::begin(s3) ) ) ,
  52. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  53. boost::end(s2) ,
  54. boost::end(s3) ) ) ,
  55. op);
  56. }
  57. template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
  58. class Operation >
  59. static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
  60. Operation op )
  61. {
  62. thrust::for_each(
  63. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  64. boost::begin(s2) ,
  65. boost::begin(s3) ,
  66. boost::begin(s4) ) ) ,
  67. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  68. boost::end(s2) ,
  69. boost::end(s3) ,
  70. boost::end(s4) ) ) ,
  71. op);
  72. }
  73. template< class StateType1 , class StateType2 , class StateType3 ,
  74. class StateType4 , class StateType5 ,class Operation >
  75. static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
  76. StateType5 &s5 , Operation op )
  77. {
  78. thrust::for_each(
  79. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  80. boost::begin(s2) ,
  81. boost::begin(s3) ,
  82. boost::begin(s4) ,
  83. boost::begin(s5) ) ) ,
  84. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  85. boost::end(s2) ,
  86. boost::end(s3) ,
  87. boost::end(s4) ,
  88. boost::end(s5) ) ) ,
  89. op);
  90. }
  91. template< class StateType1 , class StateType2 , class StateType3 ,
  92. class StateType4 , class StateType5 , class StateType6 , class Operation >
  93. static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
  94. StateType5 &s5 , StateType6 &s6 , Operation op )
  95. {
  96. thrust::for_each(
  97. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  98. boost::begin(s2) ,
  99. boost::begin(s3) ,
  100. boost::begin(s4) ,
  101. boost::begin(s5) ,
  102. boost::begin(s6) ) ) ,
  103. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  104. boost::end(s2) ,
  105. boost::end(s3) ,
  106. boost::end(s4) ,
  107. boost::end(s5) ,
  108. boost::end(s6) ) ) ,
  109. op);
  110. }
  111. template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
  112. class StateType5 , class StateType6 , class StateType7 , class Operation >
  113. static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
  114. StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , 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. boost::begin(s6) ,
  123. boost::begin(s7) ) ) ,
  124. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  125. boost::end(s2) ,
  126. boost::end(s3) ,
  127. boost::end(s4) ,
  128. boost::end(s5) ,
  129. boost::end(s6) ,
  130. boost::end(s7) ) ) ,
  131. op);
  132. }
  133. template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
  134. class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
  135. static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
  136. StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
  137. {
  138. thrust::for_each(
  139. thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
  140. boost::begin(s2) ,
  141. boost::begin(s3) ,
  142. boost::begin(s4) ,
  143. boost::begin(s5) ,
  144. boost::begin(s6) ,
  145. boost::begin(s7) ,
  146. boost::begin(s8) ) ) ,
  147. thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
  148. boost::end(s2) ,
  149. boost::end(s3) ,
  150. boost::end(s4) ,
  151. boost::end(s5) ,
  152. boost::end(s6) ,
  153. boost::end(s7) ,
  154. boost::end(s8) ) ) ,
  155. op);
  156. }
  157. template< class Value , class S , class Red >
  158. Value reduce( const S &s , Red red , Value init)
  159. {
  160. return thrust::reduce( boost::begin( s ) , boost::end( s ) , init , red );
  161. }
  162. };
  163. } // odeint
  164. } // numeric
  165. } // boost
  166. #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED