我使用的类步进器的类型签名总结如下:
http://www.boost.org/doc/libs/1_56_0/libs/numeric/odeint/doc/html/boost/numeric/odeint/runge_kutta_dopri5.html
它可以实例化如下:
boost::numeric::odeint::runge_kutta_dopri5< state_type_ > stepper;
到目前为止还不错。它有效。
我计划将我的程序移植到cuda(使用推力),稍后再移植到openmp。我将声明更改为:
boost::numeric::odeint::runge_kutta_dopri5< state_type_
, double
, state_type_
, double
, boost::numeric::odeint::vector_space_algebra
> stepper;
我遵循了这个问题的解决方案,但这并没有编译。
In file included from /usr/include/boost/numeric/odeint/stepper/euler.hpp:26:
/usr/include/boost/numeric/odeint/algebra/default_operations.hpp:87:27: error: invalid operands to binary expression ('double' and 'const std::vector<double, std::allocator<double> >')
t1 = m_alpha1 * t2 + m_alpha2 * t3;
~~~~~~~~ ^ ~~
我想知道什么是声明步进器的最便携的方法,以便在以后移植到cuda时需要最少的更改。
这取决于你想做什么。如果你想使用Thrust,你需要将声明更改为
boost::numeric::odeint::runge_kutta_dopri5<
state_type , double , state_type , double ,
thrust_algebra , thrust_operations >;
thrust_algebra
和thrust_operations
确保所有计算都重定向到使用压缩迭代器的适当的thrust::for_each
调用。如果你想使用一些在GPU上运行的高级线性代数库(如VecCL或ViennaCL),你可以使用上面的声明,只将state_type
更改为正确的类型,例如vexcl::vector< double >
。vector_space_algebra
假设您的state_type
可以处理类似y = a1*x1 + a2*x2
的操作,由于使用了表达式模板,VexCL和ViennaCL就是这样。你也可以在这里看看。