为什么在模块中声明常量时 omp 函数不起作用?

发布于 2025-01-07 06:42:07 字数 620 浏览 0 评论 0原文

我为全局变量声明定义了一个模块“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 define
integer :: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魔法唧唧 2025-01-14 06:42:07

问题不在于 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, of omp_get_max_threads. As haraldkl showed, you need to use 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.)

两个我 2025-01-14 06:42:07

不是真正的答案,但我不知道如何将代码放在这里。抱歉...

 module gvars
   integer :: maxthreads
 end module gvars

 program test
  use gvars
  use omp_lib

  implicit none

  maxthreads = omp_get_max_threads()
 end program test

编译为:
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...

 module gvars
   integer :: maxthreads
 end module gvars

 program test
  use gvars
  use omp_lib

  implicit none

  maxthreads = omp_get_max_threads()
 end program test

compiled with:
gfortran -fopenmp test.f90

Where gfotran -v gives:
gcc version 4.4.5 (GCC)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文