Are local variables in procedures automatically pr

2019-09-05 17:24发布

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条回答
地球回转人心会变
2楼-- · 2019-09-05 18:21

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").

查看更多
登录 后发表回答