在使用OpenMP时,程序中的局部变量是否自动保密? [英] Are local variables in procedures automatically private when using OpenMP?

查看:343
本文介绍了在使用OpenMP时,程序中的局部变量是否自动保密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用OpenMP和Fortran 90时相对比较新。我知道使用并行do循环时,调用子例程中的局部变量是自动私有的。对于从并行do循环中调用的函数是否也是如此?主程序中定义的外部函数和函数之间是否有区别?



我假设外部函数的行为与子程序相同,但我特别好奇主程序中的函数。谢谢!

解决方案

如果过程是过程,则OpenMP并行区域中调用的过程(函数或子例程)的局部变量是私有的如果变量不是 save ,或者启用了等效的编译器选项(主要是在启用OpenMP时自动执行) 。

如果它具有 save 属性(从初始化中显式或隐式),它将在所有调用之间共享。从工作共享结构( omp do omp节,...)调用它无关紧要。或直接来自 omp parallel 区域。



这个过程是否是外部的也不重要,一个模块程序或内部(您在主程序中混淆地称呼)。

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

这篇关于在使用OpenMP时,程序中的局部变量是否自动保密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆