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

Unexpected NaN output

Claudio_C_
Beginner
801 Views

I am writing to signal the following problem that I have bumped into. I am trying to run a program that I wrote some time ago and the following happens:

 

  1. Before purchasing the Intel compiler I was using a Lahey Fujitsu compiler and the program ran fine producing correct results
  2. Now that I am using the same program (with the necessary changes to link the IMSL subroutines) with Ifort the prgram still compiles correctly
  3. It also runs correctly until the last two subroutines
  4. The last subroutines produce unexpectedly some NaN output.
  5. The program uses large arrays and I have noticed that if I increase the size of the stack memory the problem with the “NaN” output gets milder, but it does not vanish altogether (with this I mean that there are fewer instances where the final two subroutines produce an “NaN” output)

 

Given the above I suspect that the problem may be that I am using more memory than Intel fortran can handle but since I don’t know much about its inner working I don’t know if my diagnosis is correct and I know even less regarding how I could fix the problem.

0 Kudos
6 Replies
Arjen_Markus
Honored Contributor I
801 Views

I doubt memory size is the problem. I suggest you look for variables that have not been initialised or incorrect argument lists for the routines (unless all are contained in modules - then the number and types of arguments can be checked of course). Increasing the stack means that the memory layout changes, which could affect the memory location and the contents thereof for uninitialised variables. If memory size was a problem, you would have seen messages about access violation and the like, not so much NaNs.

0 Kudos
andrew_4619
Honored Contributor II
801 Views

As Arjen suggest it is probable that your code has some bugs that remained hidden with the old compiler. Compile with /traceback /check:uninit which will throw errors if you use variables that have not been given a value. You can then locate and fix them.

0 Kudos
Claudio_C_
Beginner
801 Views

Thanks, indeed some of the elements in an array were not initialized. I believe the old compiler simply initialized to 0 everything that was not explicitely initialized and that's why I had not realized of the problem.

0 Kudos
Arjen_Markus
Honored Contributor I
801 Views

That is a well-known problem :). Fortran very explicitly guarantees no automatic initialisation will occur. Of course, memory management and compiler options may change that - as you have experienced - but the essence is that no such thing occurs, unless you explicitly do so. You can therefore not rely on variables having a value zero, they can in fact have any odd value, but it can be tricky to find the location in the code. Or even realise there is a problem.

0 Kudos
andrew_4619
Honored Contributor II
801 Views

You can use compiler flag /Qinit:zero which might 'fix' the problem. IMO this is just a quick bandage to apply whilst the proper cure is worked on.

 

0 Kudos
Steve_Lionel
Honored Contributor III
801 Views

Note that you also have to set /Qinit:arrays for arrays to be zero-initialized with /Qinit:zero.

0 Kudos
Reply