Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
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.
29280 Discussions

Initialize local variables to NaN

sfcaustx
Beginner
1,624 Views
I found that if "Initialize local variables to NaN" is set to "No" and "Initialize Local Saved Scalars to Zero" to "Yes", some local variables will be set to a extremely small number and some will be set to extremely large number. Why? Is there any way I can set local variable to zero?
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,624 Views

Do not use the "initialize local variables to NaN". (That is an old description - it should be called something different in current versions.) That option doesn't do anything useful.

For zero initialization, you must also change the "local variable allocation" to "All variables SAVE".

0 Kudos
sfcaustx
Beginner
1,624 Views

To my understanding, "All variables SAVE" is to variables having static storage. How would I doif I just need to set local variables using automatic storage to be initialized to zero? Thanks for your help.

0 Kudos
Steven_L_Intel1
Employee
1,624 Views
By adding assignment statements to your code - which is what you should be doing anyway. Relying on the compiler to initialize your data is just going to get you into trouble later. Take the time now and fix your code. The Intel compiler does not offer an option to zero-initialize non-static data.
0 Kudos
sfcaustx
Beginner
1,624 Views

Yes, I agree with you that initializing variables using assignment. But it will be better having a catch-all situation that if anything is missed. In the Properties dialog box, I tried to use default setting with little modifications to itfor project settings. But I know the default settings may not be the best settings. Do you have any suggestions about how to set the properties?

Willthe settings"All variables SAVE" + setting "Initialize local saved scalar top zero" to "YES"cause any problems with COMMOM block? Is this the better settings for catch-all situation?

0 Kudos
Steven_L_Intel1
Employee
1,624 Views

That setting has no effect on common blocks - note that the description says local saved scalar - COMMON is not "local".

I'd suggest you try enabling uninitialized variable checking under "Run-Time" in your debug configuration. It doesn't catch all cases but it's better than nothing. I also recommend using "Warn for undeclared variables" if you're not in the habit of putting in IMPLICIT NONE everywhere.

0 Kudos
Intel_C_Intel
Employee
1,624 Views

Hello,

For arrys defined locally, the following trick is useful I think. Atleast in our software we are happy with this way of detecting unitiliazied arrays.

http://softwareforums.intel.com/en-us/forums//topic/42123

http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/c7d7ca8a2d10a17/ce6c64fd09a4977b?lnk=st&q=for_alloc_allocatable&rnum=1&hl=en#ce6c64fd09a4977b

Hope this is useful for you!

Lars Petter

0 Kudos
Reply