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

"execute ok, debug crash" help

fanqingfuming
Beginner
1,100 Views
A friend of mine come across this problem when he used CVF 6.5.

He had a program that compiles, runs and debugs ok in CVF 6.5

Then he changed almost all the arrays in the program from static to dynamic (allocate at runtime). after that, the program compiles and runs (executes) ok in CVF 6.5. But if he debug it (Go...), it will crash during the process at some point with impossible errors:

Sqrt(a^2+b^2)...

Error: a^2+b^2 becomes negative, So sqrt(negative number) --> crash

Any one has an idea ? any help is highly appreciated.

Thanks
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
1,100 Views
Allocated arrays are not zero-initialized like static arrays in CVF; they contain random garbage (which will be different under Debug and Release). Presumably that is the cause of the behaviour...somewhere. My guess is that a**2 + b**2 is not negative, but contains a NaN.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,100 Views
Static arrays aren't zero-initialized either - at least they're not guaranteed to be. Don't assume any initialization you didn't do yourself.

Steve
0 Kudos
fanqingfuming
Beginner
1,100 Views
Yes, I just initialized the variables and problem solved.

Thank you all very much.

Fanqingfuming
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,100 Views
However, Steve, I think that CVF's extension with zero-initialization of static variables is actually a disservice to users. It encourages bad coding practices. I'd far prefer to have a predefined-garbage-initialization in debug mode, and "whatever was there" in release mode. I realize that default-zero initialization is necessary for old dirty codes, but that should be solved by a compiler switch. (AFAIK now we don't even have a compiler switch for not initializing statics to zero, except not-so-reliable "Variables default to automatic"). Can it be expected in VF7?

Btw, I noticed that ALLOCATEd memory is initialized with 0xCDCDCDCD under debugger at my 6.6/Win2K/Athlon. Do you maybe know where that value comes from? RTL, debugger or something else?

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
1,100 Views
CVF has no such extension - the compiler does not lift a finger to cause variables to be zero-initialized by default. You get whatever the linker and image activator give you. By default, the variables are in a type of image section that has no initialization whatsoever. It just so happens that, most of the time, these end up as zero, but you can't count on it.

The only platform on which Compaq Fortran compilers explicitly zero initialize static variables is OpenVMS.

If you want to have fun, compile with "Variables default to AUTOMATIC" - then you'll definitely have a lot of non-zero values in your uninitialized variables.

Steve
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,100 Views
Sorry, I stand corrected; I thought I had read it somewhere, but that apparently weren't CVF docs :-).

Still, are there any plans for including run-time checks of variables initialization? Compile-time checks are inherently insufficient. I had a hard time recently trying to locate a bug caused by access to a non-initialized member of an allocated array; the crash occurred only under profiler (sigh).

Jugoslav
0 Kudos
micromuni
Beginner
1,100 Views
You cannot take the square root of a negative number. There is no number that when multiplied by itself equals a negative number.

One way to get around the problem is an IF then check around the A^2+B^2. If the result is positive then perform the square root, else zero.
0 Kudos
Reply