Intel® Fortran Compiler 16.0 User and Reference Guide
OpenMP* Fortran Compiler Directive: Specifies named common blocks to be private (local) to each thread; they are global within the thread.
!$OMP THREADPRIVATE (/ cb/ [,/ cb/]...)
cb |
Is the name of the common block you want made private to a thread. Only named common blocks can be made thread private. Note that the slashes ( / ) are required. |
Each thread gets its own copy of the common block, so data written to the common block by one thread is not directly visible to other threads.
During serial portions and MASTER sections of the program, accesses are to the master thread copy of the common block. On entry to the first parallel region, data in the THREADPRIVATE common blocks should be assumed to be undefined unless a COPYIN clause is specified in the PARALLEL directive.
When a common block (which is initialized using DATA statements) appears in a THREADPRIVATE directive, each thread copy is initialized once prior to its first use. For subsequent parallel regions, data in THREADPRIVATE common blocks are guaranteed to persist only if the dynamic threads mechanism has been disabled and if the number of threads are the same for all the parallel regions.
A THREADPRIVATE common block or its constituent variables can appear only in a COPYIN clause. They are not permitted in a PRIVATE, FIRSTPRIVATE, LASTPRIVATE, SHARED, or REDUCTION clause. They are not affected by the DEFAULT clause.
On Windows* OS, if you specify option /Qopenmp-threadprivate:compat, the compiler does not generate threadsafe code for common blocks in an !$OMP THREADPRIVATE directive unless at least one element in the common block is explicitly initialized. For more information, see the article titled: /Qopenmp-threadprivate:compat doesn't work with uninitialized threadprivate common blocks, which is located in http://intel.ly/1aHhsjc
In the following example, the common blocks BLK1 and FIELDS are specified as thread private:
COMMON /BLK/ SCRATCH COMMON /FIELDS/ XFIELD, YFIELD, ZFIELD !$OMP THREADPRIVATE(/BLK/,/FIELDS/) !$OMP PARALLEL DEFAULT(PRIVATE) COPYIN(/BLK1/,ZFIELD)