Although the answer of the question in the title is, in principle, quite clear, I am confused about the scope (shared or private) of variables declared in COMMON blocks inside functions that are not the main function. For example, I am trying to parallelize a MC Code of particle transport on matter using OpenMP, the main part of this program is like the following code:
[Variable initialization, some COMMON blocks, program initialization routines, etc...]
C$OMP PARALLEL NUM_THREADS (4)
WRITE(*,*) "Number of OpenMP threads: ", OMP_GET_NUM_THREADS()
C$OMP TASK FIRSTPRIVATE(ESCORE)
C$OMP END TASK
C$OMP END SINGLE NOWAIT
C$OMP END PARALLEL
So I have a function call SHOWER() that realizes the simulation of the particle cascade. This function call another functions (RANDOM, PHOTON, ELECTR, etc) that realize the transport calculations. SHOWER and this functions declare some COMMON blocks, but they are not present in the main function of the program. For example, SHOWER could have this structure:
IF (( IQ(NP) .EQ. 0 )) THEN
The STACK COMMON block is not declared in the main part of the program. Then, PHOTON an ELECTR make use of this block, i.e.
So, the COMMON block STACK has shared or global scope? (i.e. all the created OpenMP threads see this variables, or have each thread a copy of this block?). Thanks for your help!
common variables are treated as shared, unless you have made a threadprivate copy of the common. Then you must copy data in and out in order to communicate outside the scope of the threadprivate.
If the common is declared inside procedures invoked only in the parallel region, it's conceivable on some implementation that it could be private in effect, but I don't know any such implementation.
This can get ugly enough to support the recommendations of avoiding common in new software design.
A problem frequently seen in applications using common, where OpenMP has been added subsequently, is non-local data on a NUMA platform, due to not taking advantage of the first-touch facilities built into OpenMP libraries
You'd probably get more visibility to experts on this subject by asking in the appropriate Fortran forum.
Thanks for your quick reply, Tim!...
Well, I had the doubt about asking on this forum or the Fortran one, anyway your answer dissipated my doubts about this issue... thanks for your answer!...
By the way, I have read many times the recommendations about avoiding common, but unfortunately I am adapting a quite old code (actually one programs first on MORTRAN and then is pre-compiled to Fortran). Maybe I should do a contribution and adapt the codes to newer standards, hehehe.