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