Re: Print statement within If-Then block changes output!!!????
- From: Brooks Moses <bmoses-nospam@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 18 Mar 2007 18:53:11 -0700
watsteel wrote:
I have a pair of If-then blocks to store a minimum residual.
While debugging, I noticed that a 'Print' statement placed within the
second block would change the program's output. I've tried 'Print *',
Write(both to * and to unit=2, which was opened.), and I've changed
the location of the 'Print' statement within the block, but all to no
avail. If the 'Print' statement is in the block, the output changes.
There are two sets of output, depending on whether the 'Print'
statement exists in the block or not.
The program is only 195 lines of code. The input file if 15 lines of
code.
I will happily e-mail them to anyone who can spare the time to look
this over--I'm stumped.
I'm using GNU G77, on a Dell laptop, running XP Home.
And my forehead is getting bruised from banging it on my desk, so any
help would be greatly appreciated.
Presuming that Colin's conclusion that this isn't the usual sort of out-of-bounds error causing that problem, and that it is in fact a compiler bug, I think I've got a fair guess which exactly compiler bug it is, because I've run into it in exactly this situation: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323.
The short version is of the bug this: The Intel floating-point system has 80-bit floating-point registers, but has only 64-bit floating-point storage. Thus, there are cases where, if a value is stored in memory, its value will be slightly different (due to removing the last 16 bits) than if its kept in a register.
How this hit me is that I had two numbers where A was supposed to be greater than or equal to B, but when the comparison was done, one of them had been stored in memory and the other was still in the register where it had been calculated, and as a result A.GE.B was false. Printing out something in the middle of this caused all of the variables to be shunted out of registers into 64-bit memory slots, and thus made the bug go away.
One recommended fix for this in GCC/g77/gfortran is the -ffloat-store option, which forces all floating-point values to go through a memory store before being used, thereby assuring that they're consistently truncated to 64 bits. It's worth a try to see if using that flag causes your problem to disappear. (It does slow down the program a bit, though.)
- Brooks
--
The "bmoses-nospam" address is valid; no unmunging needed.
.
- Follow-Ups:
- Re: Print statement within If-Then block changes output!!!????
- From: e p chandler
- Re: Print statement within If-Then block changes output!!!????
- From: watsteel
- Re: Print statement within If-Then block changes output!!!????
- References:
- Print statement within If-Then block changes output!!!????
- From: watsteel
- Print statement within If-Then block changes output!!!????
- Prev by Date: Re: Print statement within If-Then block changes output!!!????
- Next by Date: Re: Aren't the fuddy-duddies in the group going to comment on Fortress
- Previous by thread: Re: Print statement within If-Then block changes output!!!????
- Next by thread: Re: Print statement within If-Then block changes output!!!????
- Index(es):
Relevant Pages
|