2

在 Fortran2003 程序中,我想创建一个派生类型,其中包含一个具有asynchronous属性的可分配数组:

module async_in_type
  type async_array
    integer, dimension(:), allocatable, asynchronous :: a
  end type async_array
end module async_in_type

当我尝试使用 GCC 编译上面的代码时,我收到以下错误消息:

$ gfortran -c -Wall -Wextra async_in_type.F90
GNU Fortran (GCC) 4.10.0 20140718 (experimental)
async_in_type.F90:3.52:

    integer, dimension(:), allocatable, asynchronous :: a
                                                1
Error: Attribute at (1) is not allowed in a TYPE definition

使用 NAG Fortran 时,消息类似:

$ nagfor -c async_in_type.F90 
NAG Fortran Compiler Release 6.0(Hibiya)
Product NPL6A60NA for x86-64 Linux
Error: async_in_type.F90, line 3: Syntax error
       detected at ,@ASYNCHRONOUS
[NAG Fortran Compiler pass 1 error termination, 1 error]

这种限制的原因是什么?是否有可能克服这个限制?

4

2 回答 2

3

编译器的信息很准确,很清楚,让我重复一遍:

Error: Attribute at (1) is not allowed in a TYPE definition

因此,标准根本不允许这样做。

您必须将asynchronous属性放到 type 的变量中async_in_type

type(async_in_type), asynchronous :: x
于 2014-12-19T11:58:09.103 回答
0

我将通过引用(和一些推测)来支持Vladimir F 的回答。是的,(Fortran 2008)标准不允许使用该asynchronous属性。

对于派生类型的组件,请查看 4.5.4.1,其中给出了组件的允许属性 (R437)。 asynchronous只是没有列出(dimension问题allocatable是)。

asynchronous属性在 5.3.4 中描述

具有 ASYNCHRONOUS 属性的实体是可能受异步输入/输出影响的变量。

这部分地激发了限制:定义的组件本身不是一个变量。将属性放入定义中,您可能想说的是,这种类型的所有变量都具有具有该属性的组件。

正如 Vladimir F 所说,属性是在派生类型对象上指定的(甚至可能是隐式的 - 参见 9.6.2.5 - 因此这种显式确认可能不是太麻烦的负担)。即使不是,说

asynchronous :: x%a ! Using Vladimir F's terminology

然后 5.3.4 还说具有该属性的变量的基础对象也应具有该属性。我们进一步知道具有该属性的对象的子对象具有该属性 - 因此异步组件的“兄弟”也必须是异步的。

如果我们来到“为什么我们不能有一些具有属性的组件而一些没有?” 那么我们必须推测,但这里至少有证据表明该标准的作者在拒绝之前考虑了这种可能性。

最后,R427(在 4.5.2.1 中)排除了这种情况type, asynchronous :: async_array

于 2015-03-13T17:09:36.700 回答