为什么在模块中声明常量时 omp 函数不起作用?
我为全局变量声明定义了一个模块“gvars”。当我定义 在我的 gvars 模块内部的 integer :: nthreads, max_threads, tid, omp_get_max_threads, omp_get_num_threads, omp_get_thread_num
,在我的主例程中调用 maxthreads = omp_get_max_threads()
给出了以下错误编译时:
maxthreads = omp_get_max_threads()
1
Error: Unclassifiable statement at (1)
但是当我在主例程中包含上面的 integer ::
定义时,它编译得很好并给出了我想要的结果。如果我什至在 gvars 模块中定义 nthreads = -1
,我就能够在主例程中打印出正确的值,这样我就知道它被正确包含和定义,它是只是由于某种原因我不能将它作为 openmp 函数的返回值。
为什么会这样呢?
有没有其他方法可以将这些值保留为全局变量,并仍然在我的主例程而不是模块中定义它们?
如果重要的话,我正在使用 gfortran 进行编译
i have a module 'gvars' defined for my global variable declarations. when i defineinteger :: nthreads, max_threads, tid, omp_get_max_threads, omp_get_num_threads, omp_get_thread_num
inside of my gvars module, the call maxthreads = omp_get_max_threads()
in my main routine gives me the following error upon compilation:
maxthreads = omp_get_max_threads()
1
Error: Unclassifiable statement at (1)
but when i include the integer ::
definitions above inside my main routine, it compiles just fine and gives me the desired results. if i even go as far as to define nthreads = -1
inside my gvars module, i am able to print out the correct value in my main routine so i know it is being included and defined correctly, it's just that for some reason i cannot have it as a return value from openmp functions.
why would this be?
is there any other way to keep these values as global variables and still define them in my main routine instead of a module?
if it matters, i am using gfortran to compile
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题不在于
maxthreads
的声明,而在于同一行上的omp_get_max_threads
的声明。正如 haraldkl 所示,您需要使用 omp_lib 来自动访问这些函数的声明。(如果由于某种原因您确实不想这样做,您还可以将语句
external :: omp_get_max_threads, ...
添加到模块中。)The problem is not with the declaration of
maxthreads
, but with the declaration, on the same line, ofomp_get_max_threads
. As haraldkl showed, you need touse omp_lib
instead, to automatically get access to the declarations of these functions.(If for some reason you really don't want to do it that way, you can also add the statement
external :: omp_get_max_threads, ...
to the module.)不是真正的答案,但我不知道如何将代码放在这里。抱歉...
编译为:
gfortran -fopenmp test.f90
其中 gfotran -v 给出:
海湾合作委员会版本 4.4.5 (GCC)
Not really an answer, but I do not know how else to put the code in here. Sorry...
compiled with:
gfortran -fopenmp test.f90
Where gfotran -v gives:
gcc version 4.4.5 (GCC)