- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you FF in being more explicit than my attempt in #2.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Belts are determined by points accumulated for participation. The "Black Belt" label is by invitation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Steve! I should push more in order to be upgraded, haha.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Daniel, participate more and belts shall be yours....
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page