Initialization of large derived types

Initialization of large derived types

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. 

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

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

TYPE(my_type) :: my_var
my_var = my_type()

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

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!

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today