You can make named common blocks private to a thread, but global within the thread, by using the THREADPRIVATE directive.
Each thread gets its own copy of the common block with the result that 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.
You cannot use a thread private variable in any clause other than the following:
COPYIN
COPYPRIVATE
SCHEDULE
NUM_THREADS
IF
In the following example common blocks BLK1 and FIELDS are specified as thread private:
Example |
---|
COMMON /BLK1/ SCRATCH COMMON /FIELDS/ XFIELD, YFIELD, ZFIELD !$OMP THREADPRIVATE(/BLK1/,/FIELDS/) |
For more details on this directive, see OpenMP* Fortran Compiler Directives.