The function we compute for atomic and reduction use case is
Where N
is know and M
in in and
u
is the machine epsilon
The upper bound of the Relative error is given in "The Accuracy of Floating Point Summation" (2.6) from Nicholas J. Higham https://doi.org/10.1137/0914050.
Applied to f(N,M)
it give:
import numpy as np
import sys
def sum_dec32(N,M):
inc = np.float32(1) / np.float32(M)
s = np.float32(0)
for i in range(N*M):
s += inc
return abs(N-s)/N
N, M_max = map(int,sys.argv[1:])
m_error,m = max((sum_dec32(N,M),M) for M in range(1,N_max+1))
print (m, f"{m_error:.3%}".format(m_error))
This give for N = 55*55
and M = 55
a error of 0.187%
.