Using asynchronous attribute in derived types

659 views Asked by At

In Fortran2003 program, I want to create a derived type that includes an allocatable array with asynchronous attribute:

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

When I try to compile the code above with GCC, I get the following error message:

$ 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

With NAG Fortran the message is similar:

$ 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]

What is the reason for such restriction? Is it possible to overcome this restriction?

2

There are 2 answers

2
Vladimir F Героям слава On BEST ANSWER

The compiler message is exact and very clear, let me repeat it:

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

So it simply isn't allowed by the standard.

You must put the asynchronous attribute to the variables of type async_in_type.

type(async_in_type), asynchronous :: x
1
francescalus On

I'll add support to Vladimir F's answer with references (and some speculation). Yes, the (Fortran 2008) standard does not allow this use of the asynchronous attribute.

For components of a derived type, look at 4.5.4.1 where the allowed attributes for a component are given (R437). asynchronous is just not listed (dimension and allocatable of the question are).

The asynchronous attribute is described in 5.3.4

An entity with the ASYNCHRONOUS attribute is a variable that may be subject to asynchronous input/output.

This partly motivates the restriction: the defined component is not in itself a variable. Perhaps what you want to say with placing the attribute in the definition is that all variables of this type have components with that attribute.

As Vladimir F says, the attribute is specified (perhaps even implicitly - see 9.6.2.5 - so this explicit confirmation may not be too troublesome a burden) on the derived type object. Even if it weren't, by say

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

then 5.3.4 also says that the base object of the variable with that attribute shall also have that attribute. We further know that sub-objects of an object with that attribute have the attribute - so "siblings" of an asynchronous component must also be asynchronous.

If we come to "why can't we have some components with the attribute and some without?" then we must speculate, but there's at least evidence presented here that the authors of the standard thought about that possibility before rejecting it.

Finally, R427 (in 4.5.2.1) rules out the case type, asynchronous :: async_array