OpenMP和部分 [英] OpenMP and sections
问题描述
我有以下代码:
#pragma omp parallel sections num_threads(2) {
#pragma omp section
Function_1;
#pragma omp section
Function_2;
}
但在Function_1和Function_2中,我有一个并行线程,但只有一个线程运行。
那么,如何并行运行Function_1和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!
推荐答案
在另一个区域内有一个并行
区域称为嵌套。默认情况下,嵌套区域是非活动的,这意味着它们连续执行。为了使其有效,您可以:
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:
- 设置环境变量
OMP_NESTED
到true
- 在
并行
区域之前插入以下调用: code> omp_set_nested(1);
- set the environment variable
OMP_NESTED
totrue
- 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:
- 将环境变量
OMP_MAX_ACTIVE_LEVELS
设置为num
或 - 呼叫
omp_set_max_active_levels(num);
- setting the environment variable
OMP_MAX_ACTIVE_LEVELS
tonum
, or - calling
omp_set_max_active_levels(num);
其中 num
是所需的最大活动级别,例如值 3
会使所有并行
区域,嵌套超过 3
级别深,无效。
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.
这篇关于OpenMP和部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!