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

Initialization of large derived types

Aaron_S_1
Beginner
641 Views

I am working on porting some code from CVF to IVF and I am running into a problem initializing some derived types. I have a subroutine that is executed inside a loop. The subroutine has a local variable of a type I have defined. In my type definition I have initialized every field to 0, but when the subroutine is executed in the loop I don't get a reinitialized local variable like I would've in CVF. It looks like this is the effect of the /Qsave compiler option. I've done some reading and various sources seem to indicate that intializing a variable in its type definition should override the /Qsave option, but I'm not seeing this. Is there a reason why? Is there a way to quickly reinitialize the variable? It's a very big structure so it would take hundreds of lines to reassign everything to zero. I should note that the /Qzero option has no affect here. 

0 Kudos
4 Replies
Andrew_Smith
Valued Contributor I
641 Views

You could avoid the /Qsave from affecting your local derived type variable by making it an allocatable scaler. Each time you enter, allocate it, then deallocate on exit. Or perhaps overiding by the automatic attribute is simpler

0 Kudos
IanH
Honored Contributor III
641 Views

(In the absence of some other unspecified specification the behaviour of /Qsave looks like it is being consistent with the documentation.)

Or... if you have default initialised every field to zero inside the type definition then you could also assign to the variable to manually initialise it.

[fortran]TYPE(my_type) :: my_var

...

my_var = my_type()[/fortran]

Whatever the solution, putting reasonable effort in to getting rid of the need for /Qsave would be pretty high on my list too.

0 Kudos
Aaron_S_1
Beginner
641 Views

This is exactly what I was looking for. For whatever reason my internet searches didn't turn up anything like this. Thanks for your help!

0 Kudos
jimdempseyatthecove
Honored Contributor III
641 Views

Depending on what is in your my_type, you may consider creating a SAVEed default variable that is initialized on first entry into subroutine then used to copy into your working type.

Jim Dempsey

0 Kudos
Reply