A.24 private 子句的示例

private 子句 (在第 25 页) 的第2.7.2.1部分 并行区域仅实际上是为该区域的词法区域,则不会为该区域的动态区域。 因此,在下面的示例,在 for 循环中的变量 所有使用该实例 f 引用 私有副本,,而实例 g 的 一种用法引用全局 a。

int a;

void f(int n) 
{
    a = 0;

    #pragma omp parallel for private(a)
    for (int i=1; i<n; i++) 
    {
        a = i;
        g(i, n);
        d(a);     // Private copy of "a"
        ...
    }
    ...

void g(int k, int n) 
{
    h(k,a); // The global "a", not the private "a" in f
}