accuracy of intrinsic SUM function

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Aug 24 20:12:00 GMT 2012


On Fri, Aug 24, 2012 at 09:28:04PM +0200, Schorsch MCMLX wrote:
> 
> Kahan's or compensated summation requires at least three times the 
> number of additions of the recurrent algo plus the evaluation of an if
> statement in each step (Knuth's/Kahan's three step algo requires the 
> first variable to be the largest in absolute terms...).

There is no if statement in a Kahan summation.  Here's the code
from Kahan's short note in ACM (vol. 8, p. 40, 1965).

 1    S = 0.0
      S2 = 0.0
 2    DO 4 I = I,N
 3    YI . . . .
13    S2 = S2 + YI
      T = S + S2
23    S2 = (S - T) + S2
 4    S = T

where Kahan notes that 'YI = ....' means one has done
some computation that is to be added into the final sum.

The above algorithm probably represents a simple
change to gfortran current in-lining of the naive
algorithm.  Any other algorithm would involve 
a much more complicated change, and would probably
lead to a function call to a library routine.

-- 
Steve



More information about the Fortran mailing list