MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::math::compensated_accumulator< T > Struct Template Reference

Configuration 2c – compensated accumulator: Ogita, Rump and Oishi's Sum2 and Dot2 ("Accurate sum and dot product", SIAM J. More...

#include <accumulator_traits.hpp>

Public Attributes

T sum = T(0)
T err = T(0)

Detailed Description

template<typename T = double>
requires binary_floating_point<T>
struct mtl::math::compensated_accumulator< T >

Configuration 2c – compensated accumulator: Ogita, Rump and Oishi's Sum2 and Dot2 ("Accurate sum and dot product", SIAM J.

Sci. Comput. 26(6), 2005).

Pass it as the Acc of any accumulator-aware operation. Each m * v is split by two_product into its rounded value and its error, the rounded value is added to sum by two_sum, and both errors are collected in err (error_free.hpp). The round-out is sum + err, so the result is as accurate as if the reduction ran in twice the precision of T and was rounded once: the Dot2 bound

|res - x.y| <= u |x.y| + gamma_n^2 sum |x_i y_i|,   u = eps / 2,

where configuration 1 and 2 have gamma_n sum |x_i y_i|. The error stays at u up to a condition number of about 1/u, then grows linearly with it; configuration 3 (exact_accumulator) stays at u for every condition number.

It sits between configurations 2 and 3 in every other respect too. It is two Ts, not a quire, so a kernel that holds n accumulators holds 2n words. It is about 10 flops per term (2 for two_product, 6 for two_sum, 2 for the errors) and no limb arithmetic. Its merge is a two_sum of the two sums plus the two errors: within the bound, but not exact, so a threaded reduction is deterministic for a given thread count and not bit-identical across thread counts.

Built-in binary floating T only: the error-free transformations have no counterpart for a posit or an LNS. They need strict IEEE semantics as well: no -ffast-math (error_free.hpp).

Member Data Documentation

◆ err

template<typename T = double>
T mtl::math::compensated_accumulator< T >::err = T(0)

◆ sum

template<typename T = double>
T mtl::math::compensated_accumulator< T >::sum = T(0)

The documentation for this struct was generated from the following file: