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

Adding debugging 'print' statements changes variable values

howard75
Beginner
1,040 Views
Hello,

I'm having a frustrating time debugging a problem with a fortran 77 code that I'm working on. I observe a certain array 'grad' is filled with large values of order 1.0E+154. When I add debugging statements to print the values of varibles used in the the calculation of 'grad', the problem disappears!, i.e. the array 'grad' contains the values I expect to see. I could just leave the debugging print statements in the code and move on, but this behaviour is unsettling and makes me think there is a more serious problem lurking just beneath the surface.

Here are some details:

- It is a parallel code written in fortran 77 and uses MPI for the parallel stuff
- code is compiled using mpif90 to be run on intel itanium 2 processors
- Linux Redhat Fedora OS

Any help with this problem would be greatly appreciated

Thanks,

Howard
0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
1,040 Views

Are you bypassing initialization of your data? (i.e. incorrectly assuming variables default to initialization to 0.0)

print statements indirectly insert a critical section into the code. This may affect code that has data race conditions.

Also, inserting print statements will change optimizations (i.e. varible may need to be saved from register to memory across call to print).

You might experiment by enclosing the questionable section of code in a critical section, then move the begin/end of critical section closer together. When you transition from good results to bad results this may disclose the source of the problem.

Jim Dempsey
0 Kudos
Ron_Green
Moderator
1,040 Views
I'd turn on all error checks:

-check all -g -traceback -fp-stack-check -fpe0

use these on your compile and link (assuming you use ifort for the link step)

What optimization options have you tried? O0, O2, O3?
0 Kudos
roddur
Beginner
1,040 Views

Are you bypassing initialization of your data? (i.e. incorrectly assuming variables default to initialization to 0.0)

Jim Dempsey
hi Jim,
Is not true that ifort initializes all uninitialized variable to zero? I guess i read it somwhere! If not, is there any other way of initializing them(those are not initialized) in one go to zero and keep the values for those who are initialized?
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,040 Views

/Qzero[-]
enable/disable(DEFAULT) implicit initialization to zero of local
scalar variables of intrinsic type INTEGER, REAL, COMPLEX, or
LOGICAL that are saved and not initialized

That is for local variables not global nor module
You may need to explicitly initialize global and module data.
What you see in Debug build is not necessarily what you will get in release mode.

Steve could answer if the FORTRAN spec requires initialization global and module data to 0 (when not otherwise initialized).

Program load time and file image size can be reduced by NOT having implicit initializaton to 0.

Jim
0 Kudos
Steven_L_Intel1
Employee
1,040 Views
Steve could answer if the FORTRAN spec requires initialization global and module data to 0 (when not otherwise initialized).


No, it does not. If you don't explicitly initialize any variable, it has an undefined initial value. This includes module variables and COMMON.
0 Kudos
Reply