OpenMP 几个“共享”指令?

发布于 2024-11-01 02:04:20 字数 539 浏览 3 评论 0原文

嘿, 我在 OpenMP 中有一个很长的共享变量列表,所以我必须在 fortran 中分割行并使用“&”语法来确保这些行粘在一起!

类似这样的事情:

!$OMP PARALLEL DEFAULT(private) SHARED(vars....,
     & more_vars...,
     & more_vars...
     & )

在没有 OpenMP 的情况下编译时,这会给我带来错误,因为只有第一个赞才会被识别为评论!现在的问题是我不能添加“!”在这些行前面有一个“&”前面支持不使用 OpenMP 进行编译:

!$OMP PARALLEL DEFAULT(private) SHARED(vars....,
!     & more_vars...,
!     & more_vars...
!     & )

因为它不再使用 OpenMP 进行编译...但我想在一个代码中支持两种编译...关于如何做到这一点有什么建议吗?

Hey there,
I have a very long list of shared variables in OpenMP so I have to split lines in fortran and use the "&"-syntax to make sure the lines stick together!

Something like that:

!$OMP PARALLEL DEFAULT(private) SHARED(vars....,
     & more_vars...,
     & more_vars...
     & )

That gives me errors when compiling without OpenMP, since only the first like is recognized as a comment! The problem now is that I can't add a "!" in front of those lines with a "&" in front to support compiling without OpenMP:

!$OMP PARALLEL DEFAULT(private) SHARED(vars....,
!     & more_vars...,
!     & more_vars...
!     & )

because than it doesn't compile with OpenMP anymore... But I want to support both sorts of compiling in just one code... Any advices on how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

谁的年少不轻狂 2024-11-08 02:04:20

您没有使用正确的语法。如果您查看 OpenMP V3.0 规范的第 2.1.2 节“自由源形式指令”,您将看到以下内容:

哨兵可以出现在任何列中,只要其前面只有空格即可
(空格和制表符)。它必须以单个单词的形式出现,中间没有任何插入物
特点。 Fortran 自由格式行长度、空格和连续规则适用于
指令线。初始指令行在标记之后必须有一个空格。持续
指令行必须有一个 & 符号作为该行的最后一个非空白字符,优先
指令内的任何注释。延续指令行可以有一个
指令哨兵后的 & 符号,前后有可选的空格
&符号。

所以正确的形式应该是:

!$OMP PARALLEL DEFAULT(private) SHARED(vars...., &
!$OMP& more_vars..., &
!$OMP& more_vars...  &
!$OMP& )

对于固定形式来说,是同一类型的东西。您以 OMP 标记开始每一行,并确保后续行在第 6 列中具有非空白和非零字符。

You are not using the correct syntax. If you look at the OpenMP V3.0 specification, section 2.1.2 Free Source Form Directives, you will see the following:

The sentinel can appear in any column as long as it is preceded only by white space
(spaces and tab characters). It must appear as a single word with no intervening
character. Fortran free form line length, white space, and continuation rules apply to the
directive line. Initial directive lines must have a space after the sentinel. Continued
directive lines must have an ampersand as the last nonblank character on the line, prior
to any comment placed inside the directive. Continuation directive lines can have an
ampersand after the directive sentinel with optional white space before and after the
ampersand.

So the correct form should be:

!$OMP PARALLEL DEFAULT(private) SHARED(vars...., &
!$OMP& more_vars..., &
!$OMP& more_vars...  &
!$OMP& )

For fixed form, it is the same type of thing. You start each line with the OMP sentinel and make sure continuation lines have a non-blank and non-zero character in column 6.

不气馁 2024-11-08 02:04:20

好吧,伙计们......我找到了解决方案:循环标识符(我的意思是以下代码中的 i:do i=1,end)必须共享,因为我正在使用 DEFAULT(private) 我必须将其写入共享变量列表中:)希望有一天这对某人有帮助:)

Okay guys... I found out the solution: The loop-identifier (I mean i in the following code: do i=1,end) has to be shared and as I am using DEFAULT(private) I had to write this into the list of shared vars :) Hope this helps somebody someday :)

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