OpenMP and sections

拥有回忆 提交于 2019-12-11 02:41:26

问题


i have the following code :

#pragma omp parallel sections num_threads(2) {
  #pragma omp section
   Function_1;
   #pragma omp section
   Function_2;
}

but within the Function_1 and Function_2, i have a parallel for but just one thread run it. So, how run the Function_1 and Function_2 in parallel and run several threads within these functions?

thx!


回答1:


Having one parallel region inside another is called nesting. By default nested regions are inactive, which means that they execute serially. In order to make them active, you can:

  • set the environment variable OMP_NESTED to true
  • insert the following call before the enclosing parallel region: omp_set_nested(1);

One can also limit the number of levels, where nested parallelism works, by:

  • setting the environment variable OMP_MAX_ACTIVE_LEVELS to num, or
  • calling omp_set_max_active_levels(num);

where num is the desired maximum active level, e.g. a value of 3 would render all parallel regions, nested more than 3 levels deep, inactive.



来源:https://stackoverflow.com/questions/13437782/openmp-and-sections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!