On 05/07/2010 04:47 PM, Ian Lance Taylor wrote:
Julian King<jking.phys@xxxxxxxxx> writes:
Previously, I had been running the code with -O2. Fortuitously, I
discovered that compiling with -O made the bug disappear on my test
cases. I realise that this is much more likely to reveal a memory
error than a compiler bug. I am unable to produce a test case due to
the size and complexity of the program.
When a program works at -O1 but fails at -O2, the most common causes
are an aliasing error or a misuse of undefined signed overflow. To be
honest, I'm not sure how those affect Fortran programs. A misuse of
undefined signed overflow is unlikely to cause nondeterministic
behaviour. An aliasing error could. But as far as I know Fortran
does not permit aliasing to occur anyhow.
However, the most common reason for the symptoms you see is using
uninitialiased variables / arrays.
If you go to the "Changes" link below, you'll see that gfortran-4.5.0
contains new options to help you track down a problem like that.
So if at all possible, try to install gfortran-4.5.0 and use those
options (from the man page):
-finit-local-zero
-finit-integer=n
-finit-real=<zero|inf|-inf|nan|snan>
-finit-logical=<true|false>
-finit-character=n
The -finit-local-zero option instructs the compiler to
initialize local "INTEGER", "REAL", and "COMPLEX" variables to zero,
"LOGICAL" variables to false, and "CHARACTER" variables to a
string of null bytes. Finer-grained initialization options
are provided by the -finit-integer=n,
-finit-real=<zero|inf|-inf|nan|snan> (which also initializes the real
and imaginary
parts of local "COMPLEX" variables),
-finit-logical=<true|false>, and -finit-character=n (where n is an ASCII
character value) options. These options do not initialize components of
derived type variables, nor do they initialize variables
that appear in an "EQUIVALENCE" statement. (This limitation may be
removed in future releases).
Note that the -finit-real=nan option initializes "REAL" and
"COMPLEX" variables with a quiet NaN. For a signalling NaN use
-finit-real=snan; note, however, that compile-time
optimizations may convert them into quiet NaN and that
trapping needs to be enabled (e.g. via -ffpe-trap).
Hope this helps,
--
Toon Moene - e-mail: toon@xxxxxxxxx - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/gcc-4.5/changes.html#Fortran