隐式私有控制循环变量

Implicit private control loop variable

我有疑问,但在 OpenMP 文档中没有找到正确的答案。 如果我有这样的循环:

int i;

#pragma omp parallel for
for(i=0;i<10;i++)
    //do some stuff

变量i是隐式私有的吗?或者我必须定义为 private ,比如 #pragma omp parallel for private(i)?

相反,如果我有这样的循环:

int i,j;

#pragma omp parallel for
for(i=0;i<10;i++)
    for(j=i+1;j<10;j++)
        //do some stuff

只有变量 i 是隐式私有的,变量 j 是共享的,因为默认情况下 OpenMP“强制”仅底层循环的控制循环变量是私有的,我是吗对吗?

我可以参考一些资料来证实这些假设吗?

Is the variable i implicit private, am I right? Or i have to define as private , like #pragma omp parallel for private(i)?

是的,OpenMP 标准确保此类变量隐式 私有

int i,j;

#pragma omp parallel for
for(i=0;i<10;i++)
    for(j=i+1;j<10;j++)

Only the variable i will be implicit private, and the variable j will be shared because by default OpenMP "forces" as private only the control loop variable of the underlying loop, am I right?

是的,你是对的。但是,如果您使用 #pragma omp parallel for collapse(2),变量 ij 都是私有的。

Can I have some references to confirm these assumptions?

OpenMP 5.1 standard 部分 2.11.9 Loop Transformation Constructs:

Loop iteration variables of generated loops are always private in the enclosing teams, parallel, simd, or task generating construct.

还有 2.21.1.1 Variables Referenced in a Construct

The loop iteration variable in any associated loop of a for, parallel for, taskloop, or distribute construct is private.