Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_CompensatedSum.H
Go to the documentation of this file.
1#ifndef AMREX_COMPENSATEDSUM_H_
2#define AMREX_COMPENSATEDSUM_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Extension.H>
7
8namespace amrex
9{
10
36template <typename T, typename U>
38void compensatedAdd (T& sum, T& compensation, U value) noexcept
39{
40 T volatile y = static_cast<T>(value) - compensation;
41 T volatile t = sum + y;
42 T volatile c = t - sum;
43 compensation = c - y;
44 sum = t;
45}
46
47}
48
49#endif
Compiler- and backend-specific extension macros (e.g., restrict, SIMD, inline).
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Definition AMReX_Amr.cpp:50
__host__ __device__ void compensatedAdd(T &sum, T &compensation, U value) noexcept
Add a value to a running sum with Kahan compensation.
Definition AMReX_CompensatedSum.H:38