Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Arcane::HPReal Class Reference

Class implementing a High-Precision real number. More...

#include <arcane/utils/HPReal.h>

Collaboration diagram for Arcane::HPReal:

Public Member Functions

 HPReal ()
 Default constructor without initialization.
 HPReal (double avalue)
 Creates an HP real with the value value and the correction correction.
 HPReal (double avalue, double acorrection)
 Creates an HP real with the value value and the correction correction.
Real value () const
 Internal value. Generally, you must use toReal().
Real correction () const
 Internal correction.
void operator+= (Real v)
 Adds a Real while preserving the error.
void operator+= (HPReal v)
 Adds an HPReal v while preserving the error (reduction).
Real toReal () const
 Converts the instance to a Real.
HPReal reduce (HPReal b) const
 Adds an HPReal v while preserving the error (reduction).
void operator*= (Real v)
 Multiplies a Real while preserving the error.
void operator*= (HPReal v)
 Multiplies an HPReal v while preserving the error (reduction).
void operator/= (Real v)
 Multiplies a Real while preserving the error.
void operator/= (HPReal v)
 Multiplies an HPReal v while preserving the error (reduction).
std::istream & assign (std::istream &i)
 Reads an HPReal from the stream i. The pair is read in the form of two Real type values.
std::ostream & print (std::ostream &o) const
 Writes the instance to the stream o readable by an assign().
std::ostream & printPretty (std::ostream &o) const
 Writes the instance to the stream o in the form (x,y).

Static Public Member Functions

static HPReal zero ()
 Zero value.
static HPReal accumulate (Real a, HPReal b)
static HPReal reduce (HPReal a, HPReal b)
static HPReal product (HPReal a, HPReal b)
static HPReal product (Real a, HPReal b)
static HPReal div2 (HPReal a, HPReal b)
static HPReal div2 (Real b, HPReal a)

Static Private Member Functions

static HPReal _doTwoSum (Real a, Real b)
static HPReal _doQuickTwoSum (Real a1, Real b1)
static HPReal _doTwoProducts (Real a, Real b)
static HPReal SPLIT (Real a)

Private Attributes

Real m_value
Real m_correction

Detailed Description

Class implementing a High-Precision real number.

This class is based on the article:

Obtaining identical results with double precision global accuracy on different numbers of processors in parallel particle Monte Carlo simulations (Mathew A. Cleveland, Thomas A. Brunner, Nicholas A. Gentile, jeffrey A. Keasler) in Journal Of Computational Physics 251 (2013) 223-236.

Possible operations are accumulation (operator+=()), reduction (reduce()) and conversion to a Real (toReal()). Other operations such as division or multiplication are not possible.

To conform to the classic 'Real' type, the default constructor of this class performs no initialization.

The toReal() method allows converting the HPReal into a classic Real. The typical usage is as follows:

HPReal r(0.0);
for( Integer i=0, n=x.size(); i<n; ++i ){
// Accumulates the value
r += x[i];
}
Real final_r = r.toReal();
Modifiable view of an array of type T.
constexpr Integer size() const noexcept
Returns the size of the array.
HPReal()
Default constructor without initialization.
Definition HPReal.h:165
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.

Evolution 12/18/18:

Correction of the base algorithm error for static HPReal _doTwoSum(Real a, Real b)

Real sum_error = (a - (value-approx_b) + (b-approx_b));

became (in accordance with Ref 1)

Real sum_error = (a - (value-approx_b)) + (b-approx_b);

Correction of the error in static HPReal _doQuickTwoSum(Real a,Real b)

it is necessary to test if a>b and invert a and b if this is not the case (see Ref 2, 3, 4)

Modification of Accumulate and Reduce, Accumulate and Reduce were based on Ref 1, which is based on Ref 4

Addition of products as proposed in Ref 2 (in accordance with Ref 5) of HPReal*Real or HPReal*HPReal (we take the same value of p for the SPLIT() function as in Ref 2, 4, 5)

Note that the Real*Real product in Ref 4 (p.4) is not written in the same way as those in Ref 2 (p.2) or 5 (p.3)

+++++++++++++++++

Overall, reduction algorithms or errors accumulated only with addition are less good

Algorithm 6 of DD_TWOSUM [Ref 2] is also less good:

static HPReal accumulate(Real a,MYHPReal b)
{
HPReal x(_doTwoSum(a,b.value()));
Real d= x.correction() + b.correction();
HPReal u(_doQuickTwoSum(x.value(),d));
return _doQuickTwoSum(u.value(),u.correction());
}

or

{
HPReal x(_doTwoSum(a.value(),b.value()));
HPReal y(_doTwoSum(a.correction(),b.correction()));
Real d= x.correction() + y.value();
HPReal u(_doQuickTwoSum(x.value(),d));
Real w=y.correction()+u.correction();
return _doQuickTwoSum(u.value(),w);
}
HPReal reduce(HPReal b) const
Adds an HPReal v while preserving the error (reduction).
Definition HPReal.h:204
Real correction() const
Internal correction.
Definition HPReal.h:183
Real value() const
Internal value. Generally, you must use toReal().
Definition HPReal.h:180

Tests on millions of positive as well as negative values have been performed for addition, multiplication, and division in different orders.

I have not managed to show a difference in results in a simple case between the proposed algorithm for the sum and the one initially coded.

References

Ref 1 Obtaining identical results with double precision global accuracy on different numbers of processors in parallel particle Monte Carlo simulations (Mathew A. Cleveland, Thomas A. Brunner, Nicholas A. Gentile, jeffrey A. Keasler) in Journal Of Computational Physics 251 (2013) 223-236.

Ref 2 Automatic Source-to-Source error compensation of floating-point programs L.Thevenoux, Ph langlois, Mathieu Martel HAL Id: hal-01158399

Ref 3 Numerical validation of compensated summation algorithms withs stochastic arithmetic S.Gaillat, F.Jézéquel , R.Picot Published in Electronic Notes in Theoritical Computer Science

or

Numerical validation of compensated algorithms withs stochastic arithmetic S.Gaillat, F.Jézéquel , R.Picot Published in Applied Mathematics and Computation 329 (2018)339-363

Ref 4 Library for Double-Double and Quad-Double Arithmetic December 29, 2007 Yozo Hida Xiaoye Li D.H.Bailey

Ref 5 Accurate floating point Product and exponentation S.Graillat HAL ID: hal-00164607

Ref 6 A floating point technique for extending the avaible precision T.J.Dekker Numeri.Math 18, 224-242 (1971)

Definition at line 158 of file HPReal.h.

Constructor & Destructor Documentation

◆ HPReal() [1/3]

Arcane::HPReal::HPReal ( )
inline

Default constructor without initialization.

Definition at line 165 of file HPReal.h.

Referenced by operator*=(), operator+=(), operator/=(), reduce(), and zero().

Here is the caller graph for this function:

◆ HPReal() [2/3]

Arcane::HPReal::HPReal ( double avalue)
inlineexplicit

Creates an HP real with the value value and the correction correction.

Definition at line 168 of file HPReal.h.

◆ HPReal() [3/3]

Arcane::HPReal::HPReal ( double avalue,
double acorrection )
inline

Creates an HP real with the value value and the correction correction.

Definition at line 174 of file HPReal.h.

Member Function Documentation

◆ _doQuickTwoSum()

HPReal Arcane::HPReal::_doQuickTwoSum ( Real a1,
Real b1 )
inlinestaticprivate

Definition at line 316 of file HPReal.h.

◆ _doTwoProducts()

HPReal Arcane::HPReal::_doTwoProducts ( Real a,
Real b )
inlinestaticprivate

Definition at line 329 of file HPReal.h.

◆ _doTwoSum()

HPReal Arcane::HPReal::_doTwoSum ( Real a,
Real b )
inlinestaticprivate

Definition at line 308 of file HPReal.h.

◆ accumulate()

HPReal Arcane::HPReal::accumulate ( Real a,
HPReal b )
inlinestatic

Definition at line 250 of file HPReal.h.

◆ assign()

std::istream & Arcane::HPReal::assign ( std::istream & i)

Reads an HPReal from the stream i. The pair is read in the form of two Real type values.

Definition at line 27 of file HPReal.cc.

◆ correction()

Real Arcane::HPReal::correction ( ) const
inline

Internal correction.

Definition at line 183 of file HPReal.h.

Referenced by toReal().

Here is the caller graph for this function:

◆ div2() [1/2]

HPReal Arcane::HPReal::div2 ( HPReal a,
HPReal b )
inlinestatic

Definition at line 284 of file HPReal.h.

◆ div2() [2/2]

HPReal Arcane::HPReal::div2 ( Real b,
HPReal a )
inlinestatic

Definition at line 292 of file HPReal.h.

◆ operator*=() [1/2]

void Arcane::HPReal::operator*= ( HPReal v)
inline

Multiplies an HPReal v while preserving the error (reduction).

Definition at line 216 of file HPReal.h.

References HPReal().

Here is the call graph for this function:

◆ operator*=() [2/2]

void Arcane::HPReal::operator*= ( Real v)
inline

Multiplies a Real while preserving the error.

Definition at line 210 of file HPReal.h.

◆ operator+=() [1/2]

void Arcane::HPReal::operator+= ( HPReal v)
inline

Adds an HPReal v while preserving the error (reduction).

Definition at line 192 of file HPReal.h.

References HPReal(), and reduce().

Here is the call graph for this function:

◆ operator+=() [2/2]

void Arcane::HPReal::operator+= ( Real v)
inline

Adds a Real while preserving the error.

Definition at line 186 of file HPReal.h.

◆ operator/=() [1/2]

void Arcane::HPReal::operator/= ( HPReal v)
inline

Multiplies an HPReal v while preserving the error (reduction).

Definition at line 228 of file HPReal.h.

References HPReal().

Here is the call graph for this function:

◆ operator/=() [2/2]

void Arcane::HPReal::operator/= ( Real v)
inline

Multiplies a Real while preserving the error.

Definition at line 222 of file HPReal.h.

◆ print()

std::ostream & Arcane::HPReal::print ( std::ostream & o) const

Writes the instance to the stream o readable by an assign().

Definition at line 37 of file HPReal.cc.

◆ printPretty()

std::ostream & Arcane::HPReal::printPretty ( std::ostream & o) const

Writes the instance to the stream o in the form (x,y).

Definition at line 47 of file HPReal.cc.

◆ product() [1/2]

HPReal Arcane::HPReal::product ( HPReal a,
HPReal b )
inlinestatic

Definition at line 266 of file HPReal.h.

◆ product() [2/2]

HPReal Arcane::HPReal::product ( Real a,
HPReal b )
inlinestatic

Definition at line 273 of file HPReal.h.

◆ reduce() [1/2]

HPReal Arcane::HPReal::reduce ( HPReal a,
HPReal b )
inlinestatic

Definition at line 258 of file HPReal.h.

◆ reduce() [2/2]

HPReal Arcane::HPReal::reduce ( HPReal b) const
inline

Adds an HPReal v while preserving the error (reduction).

Definition at line 204 of file HPReal.h.

References HPReal(), and reduce().

Referenced by operator+=(), and reduce().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPLIT()

HPReal Arcane::HPReal::SPLIT ( Real a)
inlinestaticprivate

Definition at line 337 of file HPReal.h.

◆ toReal()

Real Arcane::HPReal::toReal ( ) const
inline

Converts the instance to a Real.

Definition at line 198 of file HPReal.h.

References correction(), and value().

Here is the call graph for this function:

◆ value()

Real Arcane::HPReal::value ( ) const
inline

Internal value. Generally, you must use toReal().

Definition at line 180 of file HPReal.h.

Referenced by toReal().

Here is the caller graph for this function:

◆ zero()

HPReal Arcane::HPReal::zero ( )
inlinestatic

Zero value.

Definition at line 246 of file HPReal.h.

References HPReal().

Here is the call graph for this function:

Member Data Documentation

◆ m_correction

Real Arcane::HPReal::m_correction
private

Definition at line 303 of file HPReal.h.

◆ m_value

Real Arcane::HPReal::m_value
private

Definition at line 302 of file HPReal.h.


The documentation for this class was generated from the following files: