Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Allocation inside 'select rank'

CarlB
Beginner
1,329 Views

Hello everyone,

 

I am trying to create a subroutine which reads a netCDF variable and automatically allocates the necessary space. There are many possible combinations of ranks and types, therefore, I want to use an interface which handles the types and an assumed rank array to handle the ranks.
It does work as intended with the GNU Fortran (GCC) 10.2.0, but on the target system I have to use Intel Fortran Version 19.1.3.304 Build 20200925_000000 (Intel/2020.4.304-GCC-9.3.0) and that gives me the following error message:

error #8306: Associate name defined in ASSOCIATE or SELECT TYPE statements doesn't have ALLOCATABLE or POINTER attribute.

 Minimal example which works with gfortran but not with ifort:

module m
contains
        subroutine alloc(var)
                integer, dimension(..), allocatable :: var
                select rank(var)
                rank(1)
                        allocate(var(2))
                rank(2)
                        allocate(var(2, 2))
                ! rank(3) etc...
                end select
        end subroutine alloc
end module

 In this case ifort throws an error for each allocate, but as far as I can tell, 'var' has the allocatable attribute... and gfortran does not complain at all.

 

I think there are two possibilities:

a) this is a bug/missing feature (which may be fixed/added in a more recent version)

b) the code is against the standard an gfortran shouldn't compile it

 

The only workaround I see is to blow up my interface and write a subroutine for every combination of rank and type (I am already using 'include'), but I hope there may be a more elegant way to solve this issue. Maybe I can somehow build this part separately with gfortran, but I never tried something like this.

 

I attached two source files containing the code above and a minimal program which uses the 'alloc' routine. Just to clarify: Like in 'a.f90' the real programm will pass the allocatable array to 'alloc' with the correct number of dimensions.

 

Thank you,
Carl

0 Kudos
1 Solution
Ron_Green
Moderator
1,265 Views

bug ID CMPLRIL0-33797


just a reminder, we don't have any further PSXE releases planned so this fix will go into a future oneAPI HPC Toolkit Ifort


View solution in original post

0 Kudos
8 Replies
FortranFan
Honored Contributor II
1,310 Views

@CarlB ,

If you're able to, please submit a support request at Intel Online Service Center: https://supporttickets.intel.com/servicecenter?lang=en-US

and ask for clarification vis-a-vis the Fortran standard.  Prima facie, gfortran appears conformant, the standard does not include "SELECT RANK" statement in the restriction on the ALLOCATABLE attribute with the `associate-name`:

asc.PNG

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,297 Views

More relevant is this:

11.1.10.3 Attributes of a SELECT RANK associate name

3 The associating entity has the ALLOCATABLE, POINTER, or TARGET attribute if the selector has that attribute. The other attributes of the associating entity are described in 11.1.3.3.

0 Kudos
Ron_Green
Moderator
1,273 Views

I don't have time right now, but have you tried this with the 2021.2 compiler?

0 Kudos
Ron_Green
Moderator
1,269 Views

same behavior in 2021 compilers.  I'll write it up

0 Kudos
Ron_Green
Moderator
1,266 Views

bug ID CMPLRIL0-33797


just a reminder, we don't have any further PSXE releases planned so this fix will go into a future oneAPI HPC Toolkit Ifort


0 Kudos
JohnNichols
Valued Contributor III
1,260 Views

ifort in API is just an extension of the psxe - is it not?

0 Kudos
Steve_Lionel
Honored Contributor III
1,251 Views

Effectively, yes, but it's a new version and there won't be updates to older versions. 

0 Kudos
CarlB
Beginner
1,109 Views

Thank you very much for having a look at it.

So I have to implement a workaround for this... I think I can reduce the amount of subroutines by only implementing the combinations of rank and data type which are needed right now.

0 Kudos
Reply