From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,cf4ba3d07912d446,start X-Google-Attributes: gid1164f8,public X-Google-Thread: 1094ba,cf4ba3d07912d446,start X-Google-Attributes: gid1094ba,public From: rubber@bounce.com (Keith Refson - real email address in signature) Subject: Mysterious data corruption in Fortran with -automatic Date: 1998/06/04 Message-ID: #1/1 X-Deja-AN: 359521632 Sender: keith@metropolis Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII Organization: Oxford University Newsgroups: comp.sys.dec,comp.lang.fortran 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| ------------------------------------------------------------------------------