此处总结了我正在使用的类步进器的类型签名:
可以实例化如下:
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;
我遵循了 this problem 的解决方案但这不编译。
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 上运行的高级线性代数库(如 VexCL 或 ViennaCL),你可以使用上面的声明并且只更改 state_type
到正确的类型,例如 vexcl::vector< double >
. vector_space_algebra
假设您的 state_type
可以处理类似 y = a1*x1 + a2*x2
的操作,由于使用了表达式模板,VexCL 和 ViennaCL 就是这种情况。你也可以看看here .
关于c++ - `boost::numeric::odeint::runge_kutta-X`模板参数兼容CUDA/OpenMP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36564285/