I am relatively new to using OpenMP with Fortran 90. I know that local variables in called subroutines are automatically private when using a parallel do loop. Is the same true for functions that are called from the parallel do loop? Are there any differences between external functions and functions defined in the main program?
I would assume that external functions behave the same as subroutines, but I am specifically curious about functions in main program. Thanks!
The local variables of a procedure (function or subroutine) called in the OpenMP parallel region are private if the procedure is
recursive
, or an equivalent compiler option is enabled (mostly it is automatic when enabling OpenMP) provided the variable is notsave
.If it has the
save
attribute (explicit or implicit from an initialization) it is shared between all invocations. It doesn't matter if you call it from a worksharing construct (omp do
,omp sections
,...) or directly from theomp parallel
region.It also doesn't matter whether the procedure is external, a module procedure or internal (which you confusingly call "in the main program").