[Omp] A question about threadprivate

Meadows, Lawrence F lawrence.f.meadows at intel.com
Thu Apr 12 09:26:58 PDT 2007


Now that I re-read the second example, I agree with Dieter that
the result is well-defined by the 2.0 standard:

>>> int i,array(0:3)
>>> threadprivate(i)
>>> !$omp parallel num_threads(4)
>>>     i=omp_get_thread_num()
>>>     !$omp parallel num_threads(2)
>>>                 i=-omp_get_thread_num()
>>>     !$omp end parallel
>>> !$omp end parallel
>>>
>>> !$omp parallel num_threads(4) shared(array)
>>>     array(omp_get_thread_num())=i
>>> !$omp end parallel
>>>

The two outer parallel regions are consecutive, have the
same number of threads, dyn-var is false, and nthreads-var
hasn't changed. The inner region modifying 'i' is not
relevant here, it is a different 'i'.

So I believe that the value of 'i' for the threads in the second
out parallel region is retained in both examples, and that this
behavior is clearly specified by the standard.


More information about the Omp mailing list