Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26750 Discussions

Deallocate doesn't compile inside ASSOCIATE.

Daniel_Dopico
Novice
145 Views

Is there any reason why this small code doesn't compile in Intel Parallel Studio XE 2018 and 2019? It seems that the ASSOCIATE alias is not recognized as ALLOCATABLE. I attach the code and Cmakefile.

    MODULE SOLIDOS
    
    IMPLICIT NONE

    !   Tipo sólido fijo: suelo
    TYPE SOLIDOBASE
    END TYPE SOLIDOBASE

    TYPE elementlista_SOLIDOS
        CLASS(SOLIDOBASE),POINTER::SLD
    END TYPE elementlista_SOLIDOS

    !> Tipo de lista de sólidos.
    TYPE typelista_SOLIDOS
        TYPE(elementlista_SOLIDOS),ALLOCATABLE,DIMENSION(:)::SLDS
    END TYPE typelista_SOLIDOS

    TYPE(typelista_SOLIDOS) lista_SOLIDOS

    TYPE,EXTENDS(SOLIDOBASE)::SOLIDO3D
    END TYPE SOLIDO3D
    CONTAINS

    SUBROUTINE dealloc_SOLIDOS
    INTEGER::i=1

    SELECT TYPE(SLD=>lista_SOLIDOS%SLDS(i)%SLD)
    TYPE IS(SOLIDO3D)
        DEALLOCATE(SLD) ! It doesn't compile
        DEALLOCATE(lista_SOLIDOS%SLDS(i)%SLD) ! It compiles
    END SELECT

    ASSOCIATE(SLD=>lista_SOLIDOS%SLDS(i)%SLD)
        DEALLOCATE(SLD) ! It doesn't compile
        DEALLOCATE(lista_SOLIDOS%SLDS(i)%SLD) ! It compiles
    END ASSOCIATE
    END SUBROUTINE dealloc_SOLIDOS

    END MODULE SOLIDOS

0 Kudos
1 Solution
FortranFan
Honored Contributor II
145 Views

gfortran does not conform to the standard with the code in the original post.

Fortran standard states, "the associate name is associated with the data object and does not have the ALLOCATABLE attribute." and that "the associate name is associated with the target of the pointer and does not have the POINTER attribute."  Thus SLD cannot be used in a DEALLOCATE statement.

View solution in original post

8 Replies
jimdempseyatthecove
Black Belt
145 Views

The ASSOCIATE is creating a pointer to the allocatable target of lista_SOLIDOS%SLDS(i)%SLD and not a reference to the pointer within the array SLDS. Try

 ASSOCIATE(pSLD=>lista_SOLIDOS%SLDS(i))
...
DEALLOCATE(pSLD%SLD)

Jim Dempsey

Daniel_Dopico
Novice
145 Views

Thank you Jim.

It doesn't compile because what you mention is valid for the ASSOCIATE construct, but not for the SELECT TYPE construct, since the lista_SOLIDOS%SLDS(i) is not polymorphic. For the ASSOCIATE it should work.

The standard says that the ASSOCIATE is an association with a variable or an expression (I understand that it is like an ALIAS, not like a regular fortran pointer). Finally, the original code compiles in gFortran, so my question is: Should it compile according to the standard? (my guess is yes).

FortranFan
Honored Contributor II
146 Views

gfortran does not conform to the standard with the code in the original post.

Fortran standard states, "the associate name is associated with the data object and does not have the ALLOCATABLE attribute." and that "the associate name is associated with the target of the pointer and does not have the POINTER attribute."  Thus SLD cannot be used in a DEALLOCATE statement.

View solution in original post

jimdempseyatthecove
Black Belt
145 Views

Thank you FF in being more explicit than my attempt in #2.

Jim Dempsey

Daniel_Dopico
Novice
145 Views

Thank you very much FF. I had a closer look to the ASSOCIATE documentation and it is exactly as you said. Since the gfortran behavior seemed more logical to me, I thought it was another bug!

Thank you both for the fast solution on this.

PS: How did you guys get that fancy belts you wear?

Steve_Lionel
Black Belt Retired Employee
145 Views

Belts are determined by points accumulated for participation. The "Black Belt" label is by invitation.

Daniel_Dopico
Novice
145 Views

Thank you Steve! I should push more in order to be upgraded, haha.

Steve_Lionel
Black Belt Retired Employee
145 Views

Daniel, participate more and belts shall be yours....

Reply