问题
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!
回答1:
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 not save
.
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 the omp 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").
来源:https://stackoverflow.com/questions/24344608/are-local-variables-in-procedures-automatically-private-when-using-openmp