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

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

问题描述

您好,
我在OpenMP中有很长的共享变量列表,因此我必须在fortran中拆分行,并使用& - 语法来确保行结合在一起!



类似于:

 !$ OMP PARALLEL DEFAULT(private )共享(vars ....,
& more_vars ...,
& more_vars ...
&)
pre>

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

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

,因为它不能与OpenMP一起编译......但是我想支持这两种编译方式,只需要一个代码......任何有关如何执行它的建议?

解决方案

您没有使用正确的语法。如果您查看OpenMP V3.0规范,第2.1.2节免费源表单指令,​​您将看到以下内容:


标记可以出现在任何列中,只要它的前面只有空格
(空格和制表符)。它必须显示为一个没有中间
字符的单词。 Fortran自由表单行长度,空白空间和延续规则适用于
指令行。初始指令行必须在标记之后有一个空格。续
指令行必须包含&符号作为行中的最后一个非空字符,之前的
位于该指令内的任何注释。




<继续指令行可以在
&符号之前和之后的可选空白处指令标记之后具有
符号。所以正确的形式应该是:

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

对于固定格式,它是相同类型的东西。你用OMP哨兵开始每一行,并确保第6栏中的连续行有非空白和非零字符。


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?

解决方案

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.

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

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