mkl_operations.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/mkl/mkl_operations.hpp
  4. [begin_description]
  5. Wrapper classes for intel math kernel library types.
  6. Get a free, non-commercial download of MKL at
  7. http://software.intel.com/en-us/articles/non-commercial-software-download/
  8. [end_description]
  9. Copyright 2010-2011 Mario Mulansky
  10. Copyright 2011-2013 Karsten Ahnert
  11. Distributed under the Boost Software License, Version 1.0.
  12. (See accompanying file LICENSE_1_0.txt or
  13. copy at http://www.boost.org/LICENSE_1_0.txt)
  14. */
  15. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED
  16. #define BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED
  17. #include <iostream>
  18. #include <mkl_cblas.h>
  19. #include <boost/numeric/odeint/algebra/default_operations.hpp>
  20. /* exemplary example for writing bindings to the Intel MKL library
  21. * see test/mkl for how to use mkl with odeint
  22. * this is a quick and dirty implementation showing the general possibility.
  23. * It works only with containers based on double and sequential memory allocation.
  24. */
  25. namespace boost {
  26. namespace numeric {
  27. namespace odeint {
  28. /* only defined for doubles */
  29. struct mkl_operations
  30. {
  31. //template< class Fac1 , class Fac2 > struct scale_sum2;
  32. template< class F1 = double , class F2 = F1 >
  33. struct scale_sum2
  34. {
  35. typedef double Fac1;
  36. typedef double Fac2;
  37. const Fac1 m_alpha1;
  38. const Fac2 m_alpha2;
  39. scale_sum2( const Fac1 alpha1 , const Fac2 alpha2 ) : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
  40. template< class T1 , class T2 , class T3 >
  41. void operator()( T1 &t1 , const T2 &t2 , const T3 &t3) const
  42. { // t1 = m_alpha1 * t2 + m_alpha2 * t3;
  43. // we get Containers that have size() and [i]-access
  44. const int n = t1.size();
  45. //boost::numeric::odeint::copy( t1 , t3 );
  46. if( &(t2[0]) != &(t1[0]) )
  47. {
  48. cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
  49. }
  50. cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
  51. cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
  52. //daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
  53. }
  54. };
  55. template< class F1 = double , class F2 = F1 , class F3 = F2 >
  56. struct scale_sum3
  57. {
  58. typedef double Fac1;
  59. typedef double Fac2;
  60. typedef double Fac3;
  61. const Fac1 m_alpha1;
  62. const Fac2 m_alpha2;
  63. const Fac3 m_alpha3;
  64. scale_sum3( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 )
  65. : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) { }
  66. template< class T1 , class T2 , class T3 , class T4 >
  67. void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 ) const
  68. { // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4;
  69. // we get Containers that have size() and [i]-access
  70. const int n = t1.size();
  71. //boost::numeric::odeint::copy( t1 , t3 );
  72. if( &(t2[0]) != &(t1[0]) )
  73. {
  74. cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
  75. }
  76. cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
  77. cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
  78. //daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
  79. cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
  80. }
  81. };
  82. template< class F1 = double , class F2 = F1 , class F3 = F2 , class F4 = F3 >
  83. struct scale_sum4
  84. {
  85. typedef double Fac1;
  86. typedef double Fac2;
  87. typedef double Fac3;
  88. typedef double Fac4;
  89. const Fac1 m_alpha1;
  90. const Fac2 m_alpha2;
  91. const Fac3 m_alpha3;
  92. const Fac4 m_alpha4;
  93. scale_sum4( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 , const Fac4 alpha4 )
  94. : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) { }
  95. template< class T1 , class T2 , class T3 , class T4 , class T5 >
  96. void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 ) const
  97. { // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5;
  98. // we get Containers that have size() and [i]-access
  99. const int n = t1.size();
  100. //boost::numeric::odeint::copy( t1 , t3 );
  101. if( &(t2[0]) != &(t1[0]) )
  102. {
  103. cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
  104. }
  105. cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
  106. cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
  107. //daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
  108. cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
  109. cblas_daxpy( n , m_alpha4 , &(t5[0]) , 1 , &(t1[0]) , 1 );
  110. }
  111. };
  112. template< class F1 = double , class F2 = F1 , class F3 = F2 , class F4 = F3 , class F5 = F4 >
  113. struct scale_sum5
  114. {
  115. typedef double Fac1;
  116. typedef double Fac2;
  117. typedef double Fac3;
  118. typedef double Fac4;
  119. typedef double Fac5;
  120. const Fac1 m_alpha1;
  121. const Fac2 m_alpha2;
  122. const Fac3 m_alpha3;
  123. const Fac4 m_alpha4;
  124. const Fac5 m_alpha5;
  125. scale_sum5( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 , const Fac4 alpha4 , const Fac5 alpha5 )
  126. : m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) , m_alpha4( alpha4 ) , m_alpha5( alpha5 ) { }
  127. template< class T1 , class T2 , class T3 , class T4 , class T5 , class T6 >
  128. void operator()( T1 &t1 , const T2 &t2 , const T3 &t3 , const T4 &t4 , const T5 &t5 , const T6 &t6 ) const
  129. { // t1 = m_alpha1 * t2 + m_alpha2 * t3 + m_alpha3 * t4 + m_alpha4 * t5 + m_alpha5 * t6;
  130. // we get Containers that have size() and [i]-access
  131. const int n = t1.size();
  132. //boost::numeric::odeint::copy( t1 , t3 );
  133. if( &(t2[0]) != &(t1[0]) )
  134. {
  135. cblas_dcopy( n , &(t2[0]) , 1 , &(t1[0]) , 1 );
  136. }
  137. cblas_dscal( n , m_alpha1 , &(t1[0]) , 1 );
  138. cblas_daxpy( n , m_alpha2 , &(t3[0]) , 1 , &(t1[0]) , 1 );
  139. //daxpby( &n , &m_alpha2 , &(t3[0]) , &one , &m_alpha1 , &(t1[0]) , &one );
  140. cblas_daxpy( n , m_alpha3 , &(t4[0]) , 1 , &(t1[0]) , 1 );
  141. cblas_daxpy( n , m_alpha4 , &(t5[0]) , 1 , &(t1[0]) , 1 );
  142. cblas_daxpy( n , m_alpha5 , &(t6[0]) , 1 , &(t1[0]) , 1 );
  143. }
  144. };
  145. };
  146. } // odeint
  147. } // numeric
  148. } // boost
  149. #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_MKL_MKL_OPERATIONS_HPP_INCLUDED