私は、パラメーターを体系的に変化させ、効果を観察する推力 + odeint の例 [コード、ドキュメント]の拡張/変更に取り組んできました。
変更可能な特定の変数を変更しようとすると (例では変更されています)、奇妙なエラーが発生します。次のエラーが表示されます。
main.cu: error: expression must be a modifiable lvalue
以下は、実行しようとしているオブザーバー構造体のソース コードで、エラーの原因となった行を示すコメントが付いています。
このエラーは、代入演算子 の左側の式が=
変更可能な値ではないことを意味していると理解しています。しかし、上記のソース例にある同じ名前の変数とまったく同じように見えます (問題なく動作します)。
//// Observes the system to detect if it ever dies during the trial
struct death_observer {
// CONSTRUCTOR
death_observer( size_t N, size_t historyBufferLen = 1)
: m_N( N ), m_count( 0 ) { }
template< class State , class Deriv >
void operator()(State &x , Deriv &dxdt , value_type t ) const
{
++m_count; // <-- This line causes the error.
}
// variables
size_t m_N;
size_t m_count;
};
...そして、参考までに、インテグレーターとこのオブザーバーを実行する main() のコードを次に示します。
parallel_initial_condition_problem init_con_solver( N_ICS );
death_observer obs( N_ICS );
//////////////////////////////// // // integrate
typedef runge_kutta_dopri5< state_type , value_type , state_type , value_type, thrust_algebra, thrust_operations > stepper_type;
const value_type abs_err = 1.0e-6;
const value_type rel_err = 1.0e-6;
double t = t_0;
while( t < t_final ) {
integrate_adaptive( make_controlled( abs_err, rel_err, stepper_type() ) ,
init_con_solver ,
std::make_pair( x.begin() , x.begin() + N_VARS*N_ICS ),
t , t + 1.0 , init_dt );
t += 1.0;
obs( x, *(&x+N_VARS*N_ICS), t); // not sure about middle arg here, but I don't think it is the cause of the error.
}
コードを最も単純なケースに絞り込もうとしました。上記の 3 行目から最後の行をコメントアウトすると、プログラムが正常に実行されます。
私は一体何を間違っているのですか?私の m_count と上記にリンクされているサンプル コードの m_count の違いは何ですか? どうもありがとう!