OpenMP 几个“共享"指令? [英] OpenMP Several "shared"-directives?

查看:20
本文介绍了OpenMP 几个“共享"指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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!

类似的东西:

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

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

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...
!     & )

因为它不再使用 OpenMP 编译...但我想在一个代码中同时支持这两种编译...关于如何做到这一点的任何建议?

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?

推荐答案

您使用的语法不正确.如果您查看 OpenMP V3.0 规范,第 2.1.2 节 Free Source Form Directives,您将看到以下内容:

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:

标记可以出现在任何列中,只要它前面只有一个空格(空格和制表符).它必须显示为一个没有干预的单词特点.Fortran 自由格式行长度、空格和延续规则适用于指示线.初始指令行必须在标记后有一个空格.继续指令行必须有一个&符号作为该行的最后一个非空白字符,之前放置在指令内的任何注释.延续指令行可以有指令标记后的 & 符号,前后可选空格和号.

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& )

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

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.

这篇关于OpenMP 几个“共享"指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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