How to pass a vector to the constructor of a thrust-based odeint observer, such that it can be read within the functor

后端 未结 1 1308
一整个雨季
一整个雨季 2021-01-05 21:02

I am extending the parameter study example from boost\'s odeint used with thrust, and I do not know how to pass a vector of values to the constructor of the observer, such t

相关标签:
1条回答
  • 2021-01-05 21:42

    You can pass a thrust vector to the functor, but you can not easily store it here. But you can store the underlying raw pointer form this vector:

    struct minPerturbFunctor
    {
        state_type::value_type* m_ptr;
        size_t m_len;
        minPerturbFunctor( state_type const& x )
        : m_ptr( thrust::raw_pointer_cast(&x[0]) )
        , m_len( x.size() )
        { }
    
        template< class T >
        __host__ __device__
        void operator()( T t ) const
        {
            // now you can access m_ptr like m_ptr[i] 
        }
    };
    

    This is pretty much the suggestion from Robert Crovella.

    0 讨论(0)
提交回复
热议问题