c++ - Using openmp with odeint and adaptative step sizes -
i trying use openmp parallelize code. works fine when use constant step sizes, when run same code using adaptative stepper errors don't understand.
here essential parts of code :
using namespace std; using namespace boost::numeric::odeint; const int jmax = 10; typedef double value_type; typedef boost::array<value_type ,2*(jmax+1) > state_type; //the step function void rhs( const state_type , state_type &dadt , const value_type t )
{
value_type rhstemp0; value_type rhstemp1; //we write rhs of equations big sum #pragma omp parallel schedule(runtime) for(int j = 0; j < jmax+1 ; j++ ) //real part { rhstemp0 = value_type(0.0); rhstemp1 = value_type(0.0); (int k = 0; k< jmax+1 ;k++) { (int l = max(0,j+k-jmax); l < 1 + min(jmax,j+k);l++) { rhstemp0 = rhstemp0 + s[j*size_s*size_s + k*size_s + l]*(-a[k+jmax+1]*a[l]*a[j+k-l] + a[k]*a[l+jmax+1]*a[j+k-l] + a[k]*a[l]*a[j+k-l+jmax+1] +a[k+jmax+1]*a[l+jmax+1]*a[j+k-l+jmax+1]); rhstemp1 = rhstemp1 + s[j*size_s*size_s + k*size_s + l]*(a[k]*a[l]*a[j+k-l] - a[k]*a[l+jmax+1]*a[j+k-l+jmax+1] + a[k+jmax+1]*a[l]*a[j+k-l+jmax+1] +a[k+jmax+1]*a[l+jmax+1]*a[j+k-l]); } } dadt[j] = (-1/(value_type((2*(2*j+3)))))*rhstemp0; dadt[j+jmax+1] = (1/(value_type((2*(2*j+3)))))*rhstemp1; }
}
int main() { const state_type initial = loadinitialdata(); //initial condition omp_set_num_threads(jmax+1); int chunk_size = jmax/omp_get_max_threads(); omp_set_schedule( omp_sched_dynamic, chunk_size ); //i define controlled error steppers typedef runge_kutta_fehlberg78< state_type , value_type , state_type , value_type,openmp_range_algebra> error_stepper_type; typedef controlled_runge_kutta< error_stepper_type > controlled_stepper_type; controlled_stepper_type controlled_stepper; int steps = integrate_adaptive( controlled_stepper ,rhs , initial, tinitial , tfinal,initial_step , push_back_state_and_time( a_vec , times ) ); }
i not show definition of variables doubt problem, since works fine if remove openmp_range_algebra option definition of error_stepper_type. works fine if use openmp_range_algebra constant stepper size, runge kutta of order 4.
however, code following errors :
invalid conversion 'boost::range_iterator<const boost::array<double, 22ull>, void>::type {aka const double*}' 'boost::range_iterator<boost::array<double, 22ull>, void>::type {aka double*}' [-fpermissive]|
so seems try allocate sonmething constant. errors appears in file openmp_range_algebra.hpp, in following code :
template< class s > static typename norm_result_type< s >::type norm_inf( const s &s ) { using std::max; using std::abs; typedef typename norm_result_type< s >::type result_type; result_type init = static_cast< result_type >( 0 ); const size_t len = boost::size(s); typename boost::range_iterator<s>::type beg = boost::begin(s); #pragma omp parallel reduction(max: init) schedule(dynamic) for( size_t = 0 ; < len ; ++i ) init = max( init , abs( beg[i] ) ); return init; }
i hope have been clear enough, able use adaptative stepper parallelized code.
thank help.
this bug in odeint, i've filed on github: https://github.com/headmyshoulder/odeint-v2/issues/166 , try fix asap. posting.
edit: fixed, program should compile. also, i've changed example use adaptive stepper: https://github.com/headmyshoulder/odeint-v2/blob/master/examples/openmp/lorenz_ensemble_simple.cpp
Comments
Post a Comment