Example: Parallel Region in C
#pragma omp threadprivate (x)
#pragma omp parallel default(none)
int j = omp_get_thread_num();
#pragma omp for firstprivate(y)
for(int i=0;ii++)z[i] = y;
} /* end pragma parallel */
x will be made local to each thread
and will keep the value assigned by
each thread in a second parallel reg
Constant c will be propagated inside
j is defined as automatic local var
and assigned to the current #threads
a is defined in void fun(int a)
-> private(a), therefore fresh copy of
int “a” is created in each parallel thread
z[i] = y is illegal because
there is no default scope
int y is global; firstprivate(y)
will create a fresh copy of int “y” and
initialize it to the global value;
i is a local private variable in block
a here is the original int a passed to fun.
There is no access to private variables outside parallel region