Swietanowski Artur said:
> Van Snyder wrote:
> > (This is, by the way, related to the reason to prohibit REAL loop
> > inductors: the number of "trips" might vary from platform to platform.)
>
> Yes, quite obviously the program might execute differently. So what?
> When I write a numerical algorithm I don't care to much whether
> my program will give identical results on two different machines.
With REAL DO loops the answer is likely to be wildly different.
> Scientific programming requires numerical literacy and handling
> roundoff is just that.
>
> Same arguments for REAL iterators in DO loops.
REAL DO loops are ***NOT*** numerically literate.
There are in fact at least two well-known problems with REAL DO loops:
(1) the iteration count is determined by INT((m2-m1+m3)/m3) instead of
NINT(ditto), so "DO X=0.1,1.0,0.1" could iterate 9, 10 or 11 times.
So you need to add half the step size to the "final" value to be sure
of getting the iteration count desired. (Thus we have the principle
of maximal surprise - to be sure of getting to your desired "final value"
you have to specify something different!)
(2) the loop variable is incremented by the step value each time through
the loop; thus in a long loop a lot of rounding error can have
accumulated.
As the Larmouth report said, the only numerically good way of programming a
"real" DO loop is to go back to using an integer DO and a multiplier (as
the practice pre F77)
E.g. instead of
DO X=0.1,10,0.1
one should use
DO I=1,10
X = I*0.1
etc.
With my numerical analyst's hat on I am fully in agreement with the Larmouth
report's conclusions on this; the REAL DO is badly designed and should never
be used.
Cheers,
--
...........................Malcolm Cohen, NAG Ltd., Oxford, U.K.
([log in to unmask])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|