Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
* Mysterious data corruption in Fortran with -automatic
@ 1998-06-04  4:00 Keith Refson - real email address in signature
  1998-06-04  4:00 ` Kevin G. Rhoads
                   ` (3 more replies)
  0 siblings, 4 replies; 39+ messages in thread
From: Keith Refson - real email address in signature @ 1998-06-04  4:00 UTC (permalink / raw)



I have just wasted about 3 days attempting to debug a really
mysterious problem with a FORTRAN program on DU 4.0D.  The original
problem is that the program gives different results when compiled with
the "-automatic" flag to put variables on the stack.

However irrespective of any bugs in the program I have narrowed the
focus to one particular segment of code which is behaving in an
inexplicable manner.  Namely: a computed result is wrong - as deduced
from extra debugging "write" statements"  Yet when I add a "write"
statement to print the disputed value, both it and the final result
are now correct.    The code looks like:

      DO 1100 NI=1,NIONSP(NSP)
      DO 1101 IM=1,3
      POSTMP(IM)=MOD(10.D0+POSION(IM,NI,NSP),1.D0)  
 1101 CONTINUE
c      write(6,9999) postmp
c 9999  format(3f10.5)
      NGRPX=1+NINT(NGX*POSTMP(1))
      NGRPY=1+NINT(NGY*POSTMP(2))
      NGRPZ=1+NINT(NGZ*POSTMP(3))

Using the debugger on the immediately following statement yeilds:

(ladebug) p postmp
(1) 10.033126
(2) 0.0127600000000001
(3) 0.03312599999999932

(ladebug) p posion(1,1,1)
0.009953999999999999
(ladebug) p posion(2,1,1)
0.01276
(ladebug) p posion(3,1,1)
0.033126
(ladebug) next

I should mention that this is compiled with "-g -O2 -automatic" -- the
problem goes away at lower optimization levels. I'm fairly sure
that this erroneous value in postmp(1) IS being stored and used later
on - even if the array postmp is being optimized away since later
results are consistent with use of the erroneous value.

I had to step on a fair way before the optimized code thought it had
finished with that block of code, after which:
 
(ladebug) p ngrpx,ngrpy,ngrpz
503 1 2

The values of NGX,Y,Z=50,32,27 so this is consistent however postmp
has changed suggesting that it is register allocated or otherwise
optimzed away.


(ladebug) p postmp
(1) 0.03312599999999932
(2) 4.940656458412465e-323
(3) 0.03312599658966064

As I mentioned before, uncommenting the "write" statement both prints
out the correct value and fixed the problem.

I can't see any way this could be a bug in the code. Obviously I have
checked for array bounds problems, uninitialized variables and found
nothing.  More mysteriously exactly the same behaviour is observed
when the code is compiled with f90 instead of f77.   This is a verly
large code needing about 300MB of variable space (stack or data) to
run, and of course I have configured the kernel with sufficient
stack/data limits etc for the data.

A Deja news search revealed a 1996 article by Toon Moene 

Subject:      Stack allocation hosed in Digital Unix 3.2C ?
From:         toon@moene.indiv.nluug.nl (Toon Moene)
Date:         1996/02/02
Message-ID:   <1057@moene.indiv.nluug.nl>
and Message-ID:   <1058@moene.indiv.nluug.nl>

where he described a similar-sounding problem caused by a machine
configuration error as shipped by Digital, namely the value of the
"stackinc" kernel symbol.  kdbx reveals it still (in 4.0D) has the
value he thought was wrong, namely 32767.  However upping it has
made no difference.

Has anyone encountered a similar problem and/or know of a fix?

sincerely

Keith Refson


-- 
------------------------------------------------------------------------------
Email: Keith.Refson@  | Tel: +44 1865 272026 | Dr Keith Refson,              |
       earth.ox.ac.uk | Fax: +44 1865 272072 | Dept of Earth Sciences        |
                                             | Parks Road, Oxford OX1 3PR, UK|
------------------------------------------------------------------------------



^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~1998-06-11  4:00 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-06-04  4:00 Mysterious data corruption in Fortran with -automatic Keith Refson - real email address in signature
1998-06-04  4:00 ` Kevin G. Rhoads
1998-06-04  4:00   ` Jeffrey J. Potoff
1998-06-04  4:00     ` Stuart Brook
1998-06-04  4:00       ` Kevin G. Rhoads
1998-06-05  4:00         ` Stuart Brook
1998-06-05  4:00       ` Toon Moene
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` Harald Anlauf
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00       ` Jeffrey J. Potoff
1998-06-05  4:00       ` Robert O'Dowd
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00           ` Jeffrey J. Potoff
1998-06-05  4:00           ` Stuart Brook
1998-06-05  4:00       ` Keith Refson - real email address in signature
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00         ` Robert O'Dowd
1998-06-05  4:00           ` John Appleyard
1998-06-05  4:00             ` Keith Refson - real email address in signature
1998-06-05  4:00           ` Kevin G. Rhoads
1998-06-08  4:00       ` Paul Winalski
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` Catherine Rees Lay
1998-06-04  4:00     ` Kevin G. Rhoads
1998-06-05  4:00       ` William Clodius
1998-06-05  4:00       ` Thorsten Ohl
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00           ` William Clodius
1998-06-05  4:00       ` Ian Chivers
1998-06-05  4:00         ` Kevin G. Rhoads
1998-06-05  4:00       ` Ian Pattie
1998-06-05  4:00         ` Jeffrey J. Potoff
1998-06-05  4:00           ` Kevin G. Rhoads
1998-06-06  4:00           ` Rob Komar
1998-06-04  4:00 ` Thorsten Ohl
1998-06-06  4:00 ` SUMMARY: Code errors which can masquerade as compiler bugs " Kevin G. Rhoads
1998-06-11  4:00   ` Ron Sverdlove x2517
1998-06-08  4:00 ` Steve Lionel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox