On Fri, Jun 11, 2004 at 12:26:24AM -0400, Aleksandar Donev wrote:
> I am observing weird compiler behavior, likely from a bug. When I
> compile with a WRITE statement in, the code gives the correct result.
> If I remove the WRITE, suddenly NaN's appear. Another compiler works
> fine without the WRITE.
As other people mention, it usually means a subtle bug in the user
program. The write statement inhibits optimization, and it also causes
a bunch of subroutine calls, which changes what is on the stack, and
can change which memory you get for allocatable arrays. Different
stuff on the stack means you'll get different values for automatic
variables that you erroneously haven't initialized. Different locations
in the heap means that allocatable arrays that you forget to initialize
get different contents.
1) Try -O0 and -O1. If the problem happens there, it's very likely
your program, as the compiler will do highly different stuff at -O2
and higher.
2) If your compiler has flags to initialize all variables to zero, use
them. Really good compilers can do this for automatic variables, too.
3) If you use allocatable arrays, see if your compiler has switches to
initialize these arrays, and check for overwriting the beginning and
end.
Unfortunately, a lot of compilers don't have great flags for (2) and
(3).
4) If you're using x86 under Linux, tools such as valgrind are good
for finding unitialized variables. Ah, if only the Opteron/EMT64
version were done...
-- greg
|