Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
25 Views

Deallocate doesn't compile inside ASSOCIATE.

Jump to solution

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

Accepted Solutions
Highlighted
Valued Contributor III
25 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
Highlighted
25 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
Highlighted
25 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
Highlighted
Valued Contributor III
26 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
Highlighted
25 Views

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

Jim Dempsey

0 Kudos
Highlighted
25 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
Highlighted
Black Belt Retired Employee
25 Views

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

0 Kudos
Highlighted
25 Views

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

0 Kudos
Highlighted
Black Belt Retired Employee
25 Views

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

0 Kudos