It's a large code. When I applied the debugging mode to debug the code, I can obtain a reasonable number. However, when I applied the releasing mode, the numbers are NaN. Does anyone know why for the same code, these two mode would reach two totally different results? What are the probable reasons? If you need some part of the code, I can post. Thanks!
This could be a symptom of variables that are not properly initialised. Then their value can be anything - under the debugger it is (in my experience) more likely that the value is zero, whereas outside the debugger such values are much more likely to be rubbish.
You should check that all the variables have a proper value before they are used. Unfortunately that is a lot of work if you have a large program. the option /Qtrapuv (trap uninitialized variables) might help, though I have no experience with it. Another one you can try is: /check:all
The usual source of this symptom is your the coding error of using uninitialized variables. Debug mode may (stressed) initialize (your code's unitialized) variables to 0.0, whereas release mode does not. GIGO (garbage in - garbage out)
To rectify, first start using IMPLICIT NONE.
Then after you correct for potential implicit variable errors, run a Debug run with all runtime checks enabled (including use of uninitialized variables).
Note, the runtime check for use of uninitialized variables will catch many, but not all, instances of referencing uninitialized variables.
If the suggestions about finding undefined variables don't pan out, you may need to explore some of the compiler options which default differently in debug and release mode. Note that you can add release optimizations to your debug build and run under debug in an attempt to locate the difference.
I had a project recently where it was necessary to set gradual underflow explicitly under recent ifort (e.g. USE IEEE_arithmetic, call ieee_set_underflow_mode(gradual)...) to avoid generating NaN under optimization. Note that ifort /Qftz- (in main program) should (but may not) over-ride the Windows OS setting, which differs between 32-bit and X64 OS.