c++ - `boost::numeric::odeint::runge_kutta-X`模板参数兼容CUDA/OpenMP

标签 c++ boost cuda odeint

此处总结了我正在使用的类步进器的类型签名:

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;

我遵循了 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_algebrathrust_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/

相关文章:

c++ - 无法找到错误,但编译器给出以下消息:

c++ - 映射动态纹理导致 "Already Mapped Error"

c++ - 如何在 Rust 中将绑定(bind)传递给 sqlite3?

c++ - boost python 问题

c++ - async_connect 在 boost::asio 中阻塞 io_service::run_one()

c++ - 使用 size_t 索引以相反的顺序枚举数组

c++ - Boost 测试因命名空间内的枚举类而失败

cuda - nvcc 和 NVIDIA-smi 显示的不同 CUDA 版本

c++ - CUDA/CUBLAS : Accessing elements in an array

cuda - CUDA中二维共享内存是如何排列的