I am modifying some old, old Fortran code to run with OpenMP directives, and it makes heavy use of COMMON
block. I have found multiple sources that say that using OMP directives to declare COMMON
blocks as THREADPRIVATE
solves the issue of COMMON
blocks residing in global scope by giving each OpenMP thread its own copy. What I'm unsure of though, is whether the THREADPRIVATE
directive needs to be after declaration in every single subroutine, or whether having it in the main (and only) PROGRAM
is enough?
Do COMMON blocks in Fortran have to be declared threadprivate in every subroutine for OpenMP?
364 Views Asked by Frank At
1
Yes, it must be at every occurrence. Quoting from the OpenMP 5.0 standard
As a comment putting OpenMP into a program full of global variables is likely to lead to a life of pain. I would at least give some thought to "do I want to start from here" before I begin such an endeavour - modernisation of the code before you add OpenMP might turn out to be an easier and cheaper option, especially in the long run.