簡體   English   中英

在odeint中使用openmp

[英]Using openmp with odeint

我試圖使用openmp通過odeint和openmp來並行化我的代碼,但是當我更改線程數時,並行性不起作用,完成執行的時間不會增加。 我做錯了什么?

這是代碼的基本部分:

using namespace boost::numeric::odeint;
using namespace std;
typedef std::vector< double > state_type;

struct ode {
  void operator()( const state_type &XY , state_type &dUdt , double t ) {

    const size_t N = XY.size();

    #pragma omp parallel for schedule(runtime)
    for (size_t aux = 0; aux <= N; aux++) {

      dUdt[0] = XY[1];
      dUdt[1] = 2 * w * XY[3] + 3 * (w * w) * XY[0];

    }
  }
};

main() {

  typedef runge_kutta4<
              state_type , double ,
              state_type , double ,
              openmp_range_algebra
            > rk4;

  state_type XY(2);

  int number_threads = 1;

  omp_set_num_threads(number_threads);
  int chunk_size = omp_get_max_threads();
  omp_set_schedule( omp_sched_static , chunk_size );

  integrate_n_steps( rk4() , ode() , XY , 0.0 , 0.00001 , 200);  

}

我希望我已經足夠清楚了,我只希望能夠在我的代碼中使用openMP。

非常感謝您的幫助。

您的狀態的大小為2。這太小了,無法期望並行化帶來任何改善。 嘗試使用約1000個變量的示例,看看是否發現了一些改進...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM