Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.
1696 Discussions

OK to use threadprivate COMMON outside parallel region?

TimP
Honored Contributor III
276 Views
I have been asked this question. I'm not confident about the answer, as applied to Intel -openmp (and KAI guide, for legacy users). Could one of the experts answer?
Adeveloper would like to use the same labeled COMMON both inside and outside a parallel region. It has a
C$OMP THREADPRIVATE
declaration.
Is this usage likely to cause problems? Does it make a difference,if the contents are re-initialized for each instance? I think they simply want to avoid possible increase in working set size, or unnecessary cache misses, on some platforms. So, if the proposed usage actually defeats one of those purposes, that would be useful information.
0 Kudos
1 Reply
ClayB
New Contributor I
276 Views

Tim -

Yes, use of COMMON block data declared to be THREADPRIVATE outside of a parallel region is legal. The OpenMP Fortran Spec 2.0 states, "During serial portions and MASTER sections of the program, accesses are to the master thread's copy of the common block or variable."

A copy of all THREADPRIVATE data is created for each thread upon entrance to the first parallel region. Initially undefined in value, data can be initialized from the master thread copy with a COPYIN clause. Otherwise, any data written to THREADPRIVATE variables will only be visible from the thread that wrote the value.

-- clay
0 Kudos
Reply