Are local variables in procedures automatically private when using OpenMP?

帅比萌擦擦* 提交于 2020-01-17 03:35:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!