This commit is contained in:
2026-03-23 20:54:41 +08:00
commit e13b3650e9
4596 changed files with 1015768 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust.hpp
[begin_description]
includes all headers required for using odeint with thrust
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
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_THRUST_HPP_DEFINED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_HPP_DEFINED
#include <boost/numeric/odeint/external/thrust/thrust_algebra.hpp>
#include <boost/numeric/odeint/external/thrust/thrust_operations.hpp>
#include <boost/numeric/odeint/external/thrust/thrust_algebra_dispatcher.hpp>
#include <boost/numeric/odeint/external/thrust/thrust_operations_dispatcher.hpp>
#include <boost/numeric/odeint/external/thrust/thrust_resize.hpp>
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_HPP_DEFINED

View File

@@ -0,0 +1,217 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_algebra.hpp
[begin_description]
An algebra for thrusts device_vectors.
[end_description]
Copyright 2010-2013 Mario Mulansky
Copyright 2010-2011 Karsten Ahnert
Copyright 2013 Kyle Lutz
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_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED
#include <thrust/device_vector.h>
#include <thrust/for_each.h>
#include <thrust/iterator/zip_iterator.h>
#include <boost/range.hpp>
namespace boost {
namespace numeric {
namespace odeint {
namespace detail {
// to use in thrust::reduce
template< class Value >
struct maximum
{
template< class Fac1 , class Fac2 >
__host__ __device__
Value operator()( const Fac1 t1 , const Fac2 t2 ) const
{
return ( abs( t1 ) < abs( t2 ) ) ? t2 : t1 ;
}
typedef Value result_type;
};
}
/** ToDO extend until for_each14 for rk78 */
/*
* The const versions are needed for boost.range to work, i.e.
* it allows you to do
* for_each1( make_pair( vec1.begin() , vec1.begin() + 10 ) , op );
*/
struct thrust_algebra
{
template< class StateType , class Operation >
static void for_each1( StateType &s , Operation op )
{
thrust::for_each( boost::begin(s) , boost::end(s) , op );
}
template< class StateType1 , class StateType2 , class Operation >
static void for_each2( StateType1 &s1 , StateType2 &s2 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class Operation >
static void for_each3( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class Operation >
static void for_each4( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 ,
class StateType4 , class StateType5 ,class Operation >
static void for_each5( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 ,
class StateType4 , class StateType5 , class StateType6 , class Operation >
static void for_each6( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class StateType5 , class StateType6 , class StateType7 , class Operation >
static void for_each7( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ,
boost::begin(s7) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ,
boost::end(s7) ) ) ,
op);
}
template< class StateType1 , class StateType2 , class StateType3 , class StateType4 ,
class StateType5 , class StateType6 , class StateType7 , class StateType8 , class Operation >
static void for_each8( StateType1 &s1 , StateType2 &s2 , StateType3 &s3 , StateType4 &s4 ,
StateType5 &s5 , StateType6 &s6 , StateType7 &s7 , StateType8 &s8 , Operation op )
{
thrust::for_each(
thrust::make_zip_iterator( thrust::make_tuple( boost::begin(s1) ,
boost::begin(s2) ,
boost::begin(s3) ,
boost::begin(s4) ,
boost::begin(s5) ,
boost::begin(s6) ,
boost::begin(s7) ,
boost::begin(s8) ) ) ,
thrust::make_zip_iterator( thrust::make_tuple( boost::end(s1) ,
boost::end(s2) ,
boost::end(s3) ,
boost::end(s4) ,
boost::end(s5) ,
boost::end(s6) ,
boost::end(s7) ,
boost::end(s8) ) ) ,
op);
}
template< class S >
static typename S::value_type norm_inf( const S &s )
{
typedef typename S::value_type value_type;
return thrust::reduce( boost::begin( s ) , boost::end( s ) ,
static_cast<value_type>(0) ,
detail::maximum<value_type>() );
}
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_HPP_INCLUDED

View File

@@ -0,0 +1,118 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_algebra_dispatcher.hpp
[begin_description]
algebra_dispatcher specialization for thrust
[end_description]
Copyright 2013 Karsten Ahnert
Copyright 2013 Mario Mulansky
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_THRUST_THRUST_ALGEBRA_DISPATCHER_HPP_DEFINED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_DISPATCHER_HPP_DEFINED
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <boost/numeric/odeint/external/thrust/thrust_algebra.hpp>
#include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
// specializations for the standard thrust containers
namespace boost {
namespace numeric {
namespace odeint {
// specialization for thrust host_vector
template< class T , class A >
struct algebra_dispatcher< thrust::host_vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
// specialization for thrust device_vector
template< class T , class A >
struct algebra_dispatcher< thrust::device_vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
} // namespace odeint
} // namespace numeric
} // namespace boost
// add support for thrust backend vectors, if available
#include <thrust/version.h>
#if THRUST_VERSION >= 101000
#include <thrust/detail/vector_base.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct algebra_dispatcher< thrust::detail::vector_base< T , A > >
{
typedef thrust_algebra algebra_type;
};
} } }
#elif THRUST_VERSION >= 100600
// specialization for thrust cpp vector
#include <thrust/system/cpp/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct algebra_dispatcher< thrust::cpp::vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
} } }
// specialization for thrust omp vector
#ifdef _OPENMP
#include <thrust/system/omp/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct algebra_dispatcher< thrust::omp::vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
} } }
#endif // _OPENMP
// specialization for thrust tbb vector
#ifdef TBB_VERSION_MAJOR
#include <thrust/system/tbb/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct algebra_dispatcher< thrust::tbb::vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
} } }
#endif // TBB_VERSION_MAJOR
// specialization for thrust cuda vector
#ifdef __CUDACC__
#include <thrust/system/cuda/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct algebra_dispatcher< thrust::cuda::vector< T , A > >
{
typedef thrust_algebra algebra_type;
};
} } }
#endif // __CUDACC__
#endif // THRUST_VERSION >= 100600
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_ALGEBRA_DISPATCHER_HPP_DEFINED

View File

@@ -0,0 +1,233 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_operations.hpp
[begin_description]
Operations of thrust zipped iterators. Is the counterpart of the thrust_algebra.
[end_description]
Copyright 2010-2013 Mario Mulansky
Copyright 2010-2012 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_THRUST_THRUST_OPERATIONS_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_HPP_INCLUDED
namespace boost {
namespace numeric {
namespace odeint {
#include <thrust/tuple.h>
#include <thrust/iterator/zip_iterator.h>
/**ToDo extend to scale_sum13 for rk78 */
struct thrust_operations
{
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum2( const Fac1 alpha1 , const Fac2 alpha2 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 >
struct scale_sum_swap2
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
scale_sum_swap2( const Fac1 alpha1 , const Fac2 alpha2 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
typename thrust::tuple_element<0,Tuple>::type tmp = thrust::get<0>(t);
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) + m_alpha2 * thrust::get<2>(t);
thrust::get<1>(t) = tmp;
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 >
struct scale_sum3
{
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 Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 >
struct scale_sum4
{
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 Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 ,
class Fac4 = Fac3 , class Fac5 = Fac4 >
struct scale_sum5
{
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 Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 ,
class Fac4 = Fac3 , class Fac5 = Fac4 , class Fac6 = Fac5 >
struct scale_sum6
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
scale_sum6( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 ,
const Fac4 alpha4 , const Fac5 alpha5 , const Fac6 alpha6 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) ,
m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t) +
m_alpha6 * thrust::get<6>(t);
}
};
template< class Fac1 = double , class Fac2 = Fac1 , class Fac3 = Fac2 , class Fac4 = Fac3 ,
class Fac5 = Fac4 , class Fac6 = Fac5 , class Fac7 = Fac6 >
struct scale_sum7
{
const Fac1 m_alpha1;
const Fac2 m_alpha2;
const Fac3 m_alpha3;
const Fac4 m_alpha4;
const Fac5 m_alpha5;
const Fac6 m_alpha6;
const Fac7 m_alpha7;
scale_sum7( const Fac1 alpha1 , const Fac2 alpha2 , const Fac3 alpha3 ,
const Fac4 alpha4 , const Fac5 alpha5 , const Fac6 alpha6 , const Fac7 alpha7 )
: m_alpha1( alpha1 ) , m_alpha2( alpha2 ) , m_alpha3( alpha3 ) ,
m_alpha4( alpha4 ) , m_alpha5( alpha5 ) , m_alpha6( alpha6 ) , m_alpha7( alpha7 ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
thrust::get<0>(t) = m_alpha1 * thrust::get<1>(t) +
m_alpha2 * thrust::get<2>(t) +
m_alpha3 * thrust::get<3>(t) +
m_alpha4 * thrust::get<4>(t) +
m_alpha5 * thrust::get<5>(t) +
m_alpha6 * thrust::get<6>(t) +
m_alpha7 * thrust::get<7>(t) ;
}
};
template< class Fac1 = double >
struct rel_error
{
const Fac1 m_eps_abs , m_eps_rel , m_a_x , m_a_dxdt;
rel_error( const Fac1 eps_abs , const Fac1 eps_rel , const Fac1 a_x , const Fac1 a_dxdt )
: m_eps_abs( eps_abs ) , m_eps_rel( eps_rel ) , m_a_x( a_x ) , m_a_dxdt( a_dxdt ) { }
template< class Tuple >
__host__ __device__
void operator()( Tuple t ) const
{
using std::abs;
thrust::get< 0 >( t ) = abs( thrust::get< 0 >( t ) ) /
( m_eps_abs + m_eps_rel * ( m_a_x * abs( thrust::get< 1 >( t ) + m_a_dxdt * abs( thrust::get< 2 >( t ) ) ) ) );
}
typedef void result_type;
};
};
} // odeint
} // numeric
} // boost
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_HPP_INCLUDED

View File

@@ -0,0 +1,118 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_operations_dispatcher.hpp
[begin_description]
operations_dispatcher specialization for thrust
[end_description]
Copyright 2013-2014 Karsten Ahnert
Copyright 2013-2014 Mario Mulansky
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_THRUST_THRUST_OPERATIONS_DISPATCHER_HPP_DEFINED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_DISPATCHER_HPP_DEFINED
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <boost/numeric/odeint/external/thrust/thrust_operations.hpp>
#include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
// support for the standard thrust containers
namespace boost {
namespace numeric {
namespace odeint {
// specialization for thrust host_vector
template< class T , class A >
struct operations_dispatcher< thrust::host_vector< T , A > >
{
typedef thrust_operations operations_type;
};
// specialization for thrust device_vector
template< class T , class A >
struct operations_dispatcher< thrust::device_vector< T , A > >
{
typedef thrust_operations operations_type;
};
} // namespace odeint
} // namespace numeric
} // namespace boost
// add support for thrust backend vectors, if available
#include <thrust/version.h>
#if THRUST_VERSION >= 101000
#include <thrust/detail/vector_base.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct operations_dispatcher< thrust::detail::vector_base< T , A > >
{
typedef thrust_operations operations_type;
};
} } }
#elif THRUST_VERSION >= 100600
// specialization for thrust cpp vector
#include <thrust/system/cpp/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct operations_dispatcher< thrust::cpp::vector< T , A > >
{
typedef thrust_operations operations_type;
};
} } }
// specialization for thrust omp vector
#ifdef _OPENMP
#include <thrust/system/omp/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct operations_dispatcher< thrust::omp::vector< T , A > >
{
typedef thrust_operations operations_type;
};
} } }
#endif // _OPENMP
// specialization for thrust tbb vector
#ifdef TBB_VERSION_MAJOR
#include <thrust/system/tbb/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct operations_dispatcher< thrust::tbb::vector< T , A > >
{
typedef thrust_operations operations_type;
};
} } }
#endif // TBB_VERSION_MAJOR
// specialization for thrust cuda vector
#ifdef __CUDACC__
#include <thrust/system/cuda/vector.h>
namespace boost { namespace numeric { namespace odeint {
template< class T , class A >
struct operations_dispatcher< thrust::cuda::vector< T , A > >
{
typedef thrust_operations operations_type;
};
} } }
#endif // __CUDACC__
#endif // THRUST_VERSION >= 100600
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_OPERATIONS_DISPATCHER_HPP_DEFINED

View File

@@ -0,0 +1,197 @@
/*
[auto_generated]
boost/numeric/odeint/external/thrust/thrust_resize.hpp
[begin_description]
Enable resizing for thrusts device and host_vector.
[end_description]
Copyright 2010-2014 Mario Mulansky
Copyright 2010-2011 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_THRUST_THRUST_RESIZE_HPP_INCLUDED
#define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
#include <type_traits>
#include <boost/range.hpp>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/distance.h>
#include <boost/numeric/odeint/util/resize.hpp>
#include <boost/numeric/odeint/util/same_size.hpp>
#include <boost/numeric/odeint/util/copy.hpp>
namespace boost {
namespace numeric {
namespace odeint {
// some macros that define the necessary utilities
#define ODEINT_THRUST_VECTOR_IS_RESIZEABLE( THRUST_VECTOR ) \
template< class T , class A > \
struct is_resizeable< THRUST_VECTOR<T,A> > \
{ \
struct type : public std::true_type { }; \
const static bool value = type::value; \
}; \
#define ODEINT_TRHUST_VECTOR_RESIZE_IMPL( THRUST_VECTOR ) \
template< class T, class A > \
struct resize_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
{ \
static void resize( THRUST_VECTOR<T,A> &x , \
const THRUST_VECTOR<T,A> &y ) \
{ \
x.resize( y.size() ); \
} \
}; \
template< class T, class A, typename Range > \
struct resize_impl< THRUST_VECTOR<T,A> , Range > \
{ \
static void resize( THRUST_VECTOR<T,A> &x , \
const Range &y ) \
{ \
x.resize( thrust::distance(boost::begin(y), \
boost::end(y))); \
} \
}; \
#define ODEINT_THRUST_SAME_SIZE_IMPL( THRUST_VECTOR ) \
template< class T , class A > \
struct same_size_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
{ \
static bool same_size( const THRUST_VECTOR<T,A> &x , \
const THRUST_VECTOR<T,A> &y ) \
{ \
return x.size() == y.size(); \
} \
}; \
template< class T , class A, typename Range > \
struct same_size_impl< THRUST_VECTOR<T,A> , Range > \
{ \
static bool same_size( const THRUST_VECTOR<T,A> &x , \
const Range &y ) \
{ \
return x.size() == thrust::distance(boost::begin(y), \
boost::end(y)); \
} \
}; \
#define ODEINT_THRUST_COPY_IMPL( THRUST_VECTOR ) \
template< class Container1 , class T , class A > \
struct copy_impl< Container1 , THRUST_VECTOR<T,A> > \
{ \
static void copy( const Container1 &from , THRUST_VECTOR<T,A> &to ) \
{ \
thrust::copy( boost::begin( from ) , boost::end( from ) , \
boost::begin( to ) ); \
} \
}; \
\
template< class T , class A , class Container2 > \
struct copy_impl< THRUST_VECTOR<T,A> , Container2 > \
{ \
static void copy( const THRUST_VECTOR<T,A> &from , Container2 &to ) \
{ \
thrust::copy( boost::begin( from ) , boost::end( from ) , \
boost::begin( to ) ); \
} \
}; \
\
template< class T , class A > \
struct copy_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
{ \
static void copy( const THRUST_VECTOR<T,A> &from , \
THRUST_VECTOR<T,A> &to ) \
{ \
thrust::copy( boost::begin( from ) , boost::end( from ) , \
boost::begin( to ) ); \
} \
}; \
// add support for the standard thrust containers
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::device_vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::device_vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::device_vector )
ODEINT_THRUST_COPY_IMPL( thrust::device_vector )
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::host_vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::host_vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::host_vector )
ODEINT_THRUST_COPY_IMPL( thrust::host_vector )
} // odeint
} // numeric
} // boost
// add support for thrust backend vectors, if available
#include <thrust/version.h>
#if THRUST_VERSION >= 101000
#include <thrust/detail/vector_base.h>
namespace boost { namespace numeric { namespace odeint {
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::detail::vector_base )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::detail::vector_base )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::detail::vector_base )
ODEINT_THRUST_COPY_IMPL( thrust::detail::vector_base )
} } }
#elif THRUST_VERSION >= 100600
#include <thrust/system/cpp/vector.h>
namespace boost { namespace numeric { namespace odeint {
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cpp::vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cpp::vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cpp::vector )
ODEINT_THRUST_COPY_IMPL( thrust::cpp::vector )
} } }
#ifdef _OPENMP
#include <thrust/system/omp/vector.h>
namespace boost { namespace numeric { namespace odeint {
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::omp::vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::omp::vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::omp::vector )
ODEINT_THRUST_COPY_IMPL( thrust::omp::vector )
} } }
#endif // _OPENMP
#ifdef TBB_VERSION_MAJOR
#include <thrust/system/tbb/vector.h>
namespace boost { namespace numeric { namespace odeint {
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::tbb::vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::tbb::vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::tbb::vector )
ODEINT_THRUST_COPY_IMPL( thrust::tbb::vector )
} } }
#endif // TBB_VERSION_MAJOR
#ifdef __CUDACC__
#include <thrust/system/cuda/vector.h>
namespace boost { namespace numeric { namespace odeint {
ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cuda::vector )
ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cuda::vector )
ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cuda::vector )
ODEINT_THRUST_COPY_IMPL( thrust::cuda::vector )
} } }
#endif // __CUDACC__
#endif // THRUST_VERSION >= 100600
#endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED