Initialisation of allocated arrays

Initialisation of allocated arrays

Hi,

I have a f90 code containing a loop. I need to set a relatively large array to zero at the start of the loop. I found that this takes a surprisingly long time (~3 seconds per call and I have ~100000 iterations). I found that it is quicker to de-allocate the memory (coming up as 0 ms in profile) and then reallocate it but the arrays are only intialised to zero on the first allocation.

Is there a way to force allocated memory to have an assigned value? I tried the -zero compiler flag but this doesn't work

I know that, in a perfect world, is should assign a value to each declared variable/array but I am looking for a rough and ready way to save myself 300000 seconds...

Thanks in advance

TJT

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

No, there is no way to do this automatically. The initialization has to happen somewhere. It should be fast to just assign the array to 0 if you enable vectorization - be sure to use the appropriate -x switch for best results.

You might also want to think of a different approach that doesn't require such a large array to be reset each iteration.

Retired 12/31/2016

Hi Steve,

Many thanks for the response. I will give the vectorisation a shot but can't do anything about the size of the array. The joy of scientific computing...

Tim.

Leave a Comment

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