Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Annonces
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Local Allocatable Arrays

dannycat
Nouveau contributeur I
864 Visites

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 Compliments
1 Solution
Steven_L_Intel1
Employé
864 Visites

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.)

Voir la solution dans l'envoi d'origine

0 Compliments
5 Réponses
Steven_L_Intel1
Employé
864 Visites

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 Compliments
dannycat
Nouveau contributeur I
864 Visites

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 Compliments
Steven_L_Intel1
Employé
865 Visites

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 Compliments
dannycat
Nouveau contributeur I
864 Visites

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 Compliments
Steven_L_Intel1
Employé
864 Visites

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 Compliments
Répondre