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

Deallocate doesn't compile inside ASSOCIATE.

Daniel_Dopico
New Contributor I
516 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
516 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

0 Kudos
8 Replies
jimdempseyatthecove
Honored Contributor III
516 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

0 Kudos
Daniel_Dopico
New Contributor I
516 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).

0 Kudos
FortranFan
Honored Contributor II
517 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.

0 Kudos
jimdempseyatthecove
Honored Contributor III
516 Views

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

Jim Dempsey

0 Kudos
Daniel_Dopico
New Contributor I
516 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?

0 Kudos
Steve_Lionel
Honored Contributor III
516 Views

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

0 Kudos
Daniel_Dopico
New Contributor I
516 Views

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

0 Kudos
Steve_Lionel
Honored Contributor III
516 Views

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

0 Kudos
Reply