(git:6a2e663)
kahan_sum Module Reference

sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation (or the one found in most compiler's SUM intrinsic) using an implementation of Kahan's algorithm for summing real numbers that can be used instead of the standard Fortran SUM(array[,mask]). More...

Detailed Description

sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation (or the one found in most compiler's SUM intrinsic) using an implementation of Kahan's algorithm for summing real numbers that can be used instead of the standard Fortran SUM(array[,mask]).

see also http://en.wikipedia.org/wiki/Kahan_summation_algorithm

Note
if the compiler optimises away the 'tricky' bit, no accuracy is gained, if the compiler uses extended precision inconsistently even worse results might be obtained. This has not been observed. This algorithm is not fast, and thus not recommended for cases where round-off is not a concern but performance is.

the standard intrinsic sum can be 'replaced' using the following use statement

USE kahan_sum, ONLY: sum => kahan_sum

History
03.2006 [Joost VandeVondele]
Author
Joost VandeVondele