Documentation for module kahan_sum

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]).

source: kahan_sum.F
Loading...

Generic procedures:

accurate_dot_product
accurate_sum

Generic procedure accurate_dot_product

...

REAL(dp),
INTENT(in)
:: array1(:) ×
REAL(sp),
INTENT(in)
:: array1(:,:) ×
REAL(dp),
INTENT(in)
:: array1(:,:) ×
REAL(dp),
INTENT(in),
POINTER
:: array1(:,:,:) ×
REAL(dp),
INTENT(in)
:: array2(:) ×
REAL(sp),
INTENT(in)
:: array2(:,:) ×
REAL(dp),
INTENT(in)
:: array2(:,:) ×
REAL(dp),
INTENT(in),
POINTER
:: array2(:,:,:) ×
REAL(dp),
INTENT(in),
POINTER
:: mask(:,:,:) ×
REAL(dp),
INTENT(in)
:: th ×

Generic procedure accurate_sum

...

REAL(sp),
INTENT(in)
:: array(:) ×
REAL(dp),
INTENT(in)
:: array(:) ×
COMPLEX(sp),
INTENT(in)
:: array(:) ×
COMPLEX(dp),
INTENT(in)
:: array(:) ×
REAL(sp),
INTENT(in)
:: array(:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:) ×
REAL(sp),
INTENT(in)
:: array(:,:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:,:) ×
REAL(sp),
INTENT(in)
:: array(:,:,:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:,:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:) ×
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:) ×
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:,:) ×
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ×
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ×
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ×
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:) × × × ×
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:,:) × × × ×

FUNCTIONkahan_dot_product_d1(array1, array2)

computes the accurate sum of an array that is the element wise product of two input arrays.

Return Value ::
REAL(dp)
the result of the summation
Arguments:
REAL(dp),
INTENT(in)
:: array1(:) the first input array to compute the product array
REAL(dp),
INTENT(in)
:: array2(:) the second input array to compute the product array

FUNCTIONkahan_dot_product_s2(array1, array2)

computes the accurate sum of an array that is the element wise product of two input arrays.

Return Value ::
REAL(dp)
the result of the summation
Arguments:
REAL(sp),
INTENT(in)
:: array1(:,:) the first input array to compute the product array
REAL(sp),
INTENT(in)
:: array2(:,:) the second input array to compute the product array

FUNCTIONkahan_dot_product_d2(array1, array2)

computes the accurate sum of an array that is the element wise product of two input arrays.

Return Value ::
REAL(dp)
the result of the summation
Arguments:
REAL(dp),
INTENT(in)
:: array1(:,:) the first input array to compute the product array
REAL(dp),
INTENT(in)
:: array2(:,:) the second input array to compute the product array

FUNCTIONkahan_dot_product_masked_d3(array1, array2, mask, th)

computes the accurate sum of an array that is the element wise product of two input arrays. a mask array determines which product array points to include in the sum

Return Value ::
REAL(dp)
the result of the summation
Arguments:
REAL(dp),
INTENT(in),
POINTER
:: array1(:,:,:) the first input array to compute the product array
REAL(dp),
INTENT(in),
POINTER
:: array2(:,:,:) the second input array to compute the product array
REAL(dp),
INTENT(in),
POINTER
:: mask(:,:,:) the mask array
REAL(dp),
INTENT(in)
:: th screening threshold: only array points where the value of mask is greater than th are included in the sum

FUNCTIONkahan_sum_s1(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:) ...

FUNCTIONkahan_sum_d1(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:) ...

FUNCTIONkahan_sum_c1(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:) ...

FUNCTIONkahan_sum_z1(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:) ...

FUNCTIONkahan_sum_s2(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:) ...

FUNCTIONkahan_sum_d2(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:) ...

FUNCTIONkahan_sum_c2(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:) ...

FUNCTIONkahan_sum_z2(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:) ...

FUNCTIONkahan_sum_s3(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:) ...

FUNCTIONkahan_sum_d3(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:) ...

FUNCTIONkahan_sum_c3(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:) ...

FUNCTIONkahan_sum_z3(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:) ...

FUNCTIONkahan_sum_s4(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:) ...

FUNCTIONkahan_sum_d4(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:) ...

FUNCTIONkahan_sum_c4(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:) ...

FUNCTIONkahan_sum_z4(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:) ...

FUNCTIONkahan_sum_s5(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:) ...

FUNCTIONkahan_sum_d5(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:) ...

FUNCTIONkahan_sum_c5(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:) ...

FUNCTIONkahan_sum_z5(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:) ...

FUNCTIONkahan_sum_s6(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:) ...

FUNCTIONkahan_sum_d6(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:) ...

FUNCTIONkahan_sum_c6(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:) ...

FUNCTIONkahan_sum_z6(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:) ...

FUNCTIONkahan_sum_s7(array, mask)

...

Return Value ::
REAL(sp)
Arguments:
REAL(sp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:,:) ...

FUNCTIONkahan_sum_d7(array, mask)

...

Return Value ::
REAL(dp)
Arguments:
REAL(dp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:,:) ...

FUNCTIONkahan_sum_c7(array, mask)

...

Return Value ::
COMPLEX(sp)
Arguments:
COMPLEX(sp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:,:) ...

FUNCTIONkahan_sum_z7(array, mask)

...

Return Value ::
COMPLEX(dp)
Arguments:
COMPLEX(dp),
INTENT(in)
:: array(:,:,:,:,:,:,:) ...
LOGICAL,
INTENT(in),
OPTIONAL
:: mask(:,:,:,:,:,:,:) ...

private Parameters/Types:

Parameters:

INTEGER
:: dp = kind(0.0d0)
INTEGER
:: dp = kind(0.0d0)
INTEGER
:: dp = kind(0.0d0)
INTEGER
:: sp = kind(0.0)
INTEGER
:: sp = kind(0.0)
INTEGER
:: sp = kind(0.0)