1 /* Boost libs/numeric/odeint/examples/openmp/lorenz_ensemble_nested.cpp
3 Copyright 2013 Karsten Ahnert
4 Copyright 2013 Pascal Germroth
5 Copyright 2013 Mario Mulansky
7 Parallelized Lorenz ensembles using nested omp algebra
9 Distributed under the Boost Software License, Version 1.0.
10 (See accompanying file LICENSE_1_0.txt or
11 copy at http://www.boost.org/LICENSE_1_0.txt)
18 #include <boost/numeric/odeint.hpp>
19 #include <boost/numeric/odeint/external/openmp/openmp.hpp>
20 #include <boost/lexical_cast.hpp>
21 #include "point_type.hpp"
24 using namespace boost::numeric::odeint;
26 typedef point<double, 3> point_type;
27 typedef vector< point_type > state_type;
29 const double sigma = 10.0;
30 const double b = 8.0 / 3.0;
34 const vector<double> &R;
35 sys_func( vector<double> &R ) : R(R) {}
37 void operator()( const state_type &x , state_type &dxdt , double t ) const {
38 # pragma omp parallel for
39 for(size_t i = 0 ; i < x.size() ; i++) {
40 dxdt[i][0] = -sigma * (x[i][0] - x[i][1]);
41 dxdt[i][1] = R[i] * x[i][0] - x[i][1] - x[i][0] * x[i][2];
42 dxdt[i][2] = -b * x[i][2] + x[i][0] * x[i][1];
48 int main(int argc, char **argv) {
50 if(argc > 1) n = boost::lexical_cast<size_t>(argv[1]);
53 const double Rmin = 0.1, Rmax = 50.0;
54 # pragma omp parallel for
55 for(size_t i = 0 ; i < n ; i++)
56 R[i] = Rmin + (Rmax - Rmin) / (n - 1) * i;
58 state_type state( n , point_type(10, 10, 10) );
60 typedef runge_kutta4< state_type, double , state_type , double ,
61 openmp_nested_algebra<vector_space_algebra> > stepper;
63 const double t_max = 10.0, dt = 0.01;
72 std::copy( state.begin(), state.end(), ostream_iterator<point_type>(cout, "\n") );