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

Local Allocatable Arrays

dannycat
New Contributor I
845 Views

I noticed different behavior of allocatable arrays defined in a subroutine or function between CVF and IVF. In CVF a local allocatable array is automatically deallocated upon exit from the routine unless it was declared with a 'save' attribute. However in IVF the array remains allocated. Is this down to a change in standard or is it controlled by a compiler setting?

0 Kudos
1 Solution
Steven_L_Intel1
Employee
845 Views

Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)

View solution in original post

0 Kudos
5 Replies
Steven_L_Intel1
Employee
845 Views

Just based on what you wrote, I'd have to say you are mistaken in your observation. The standard says that local ALLOCATABLE arrays, if they do not have the SAVE attribute, are automatically deallocated on exit and Intel Fortran does that. If you have an example showing otherwise I'd like to see it.

0 Kudos
dannycat
New Contributor I
845 Views

Just based on what you wrote, I'd have to say you are mistaken in your observation. The standard says that local ALLOCATABLE arrays, if they do not have the SAVE attribute, are automatically deallocated on exit and Intel Fortran does that. If you have an example showing otherwise I'd like to see it.


Hi Steve,

I have the All variables SAVE/QSave set but from your reply this directive should not affect the allocatable array. I have to deallocate the array before allocating it again.

When I turn the "All variables SAVE/QSave" directive off the array is deallocatedas expected.

IsQSave supposed to behave like this with respect to allocatable arrays?

0 Kudos
Steven_L_Intel1
Employee
846 Views

Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)

0 Kudos
dannycat
New Contributor I
845 Views

Yes. /Qsave says to make all local variables SAVE and it is doing that. If that is not what you want, then don't use that switch (which I consider a Band-Aid for incorrect code.)


Thanks Steve,

You answered my original question regarding the QSave switch. I agree with your approach and I'm using the save attribute only where required in new code. The problem arose because during the project conversion from CVF to IVF the QSave attribute was automatically set up because CVF did not conform to the standard by assuming all variables (except allocatable) are saved.

0 Kudos
Steven_L_Intel1
Employee
845 Views

CVF conformed to the standard - your program did not. The standard, in most cases, specifies the rules for a standard-conforming program. A program that does not conform to the standard - for example, it references a non-SAVEd variable before definition, could do anything. CVF's behavior to apply assumed SAVE semantics to non-allocatable variables is an extension, but is allowed by the standard.

0 Kudos
Reply