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
새로운 기여자 I
1,267 조회수

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 포인트
1 솔루션
FortranFan
명예로운 기여자 III
1,267 조회수

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 포인트
8 응답
jimdempseyatthecove
명예로운 기여자 III
1,267 조회수

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 포인트
Daniel_Dopico
새로운 기여자 I
1,267 조회수

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 포인트
FortranFan
명예로운 기여자 III
1,268 조회수

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 포인트
jimdempseyatthecove
명예로운 기여자 III
1,267 조회수

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

Jim Dempsey

0 포인트
Daniel_Dopico
새로운 기여자 I
1,267 조회수

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 포인트
Steve_Lionel
명예로운 기여자 III
1,267 조회수

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

0 포인트
Daniel_Dopico
새로운 기여자 I
1,267 조회수

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

0 포인트
Steve_Lionel
명예로운 기여자 III
1,267 조회수

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

0 포인트
응답