LvArray icon indicating copy to clipboard operation
LvArray copied to clipboard

Kahan 2x2 determinant computation reduces numerical imprecision.

Open TotoGaz opened this issue 4 years ago • 1 comments

Related to issue https://github.com/GEOSX/GEOSX/issues/1440: some tests testTensorOpsInverseTwoArgs and testTensorOpsInverseOneArg are failing due to large numerical imprecision.

Using the Kahan method to compute 2x2 determinants brings more precision. 3x3 case still untouched.

Warning, I sometimes get compilation warnings like

../coreComponents/LvArray/unitTests/../src/fixedSizeSquareMatrixOpsImpl.hpp(100): warning: calling a constexpr __host__ function("fma") from a __host__ __device__ function("determinant") is not allowed. The experimental flag '--expt-relaxed-constexpr' can be used to allow this.

which I find surprising since this fma function is supposed to be device friendly. fma also seems pretty standard so one should not need any fallback. So I need to double-check.

Any opinion?

TotoGaz avatar Jul 29 '21 00:07 TotoGaz

Also this modification makes calculating the determinant significantly more costly. I'm not sure you can answer this question but maybe the kind of matrices that pop up in the unit tests aren't representative of the normal use case.

I could spot 3x3 dets in the code (FEM stuff), but only 2x2 in the unit tests. I will double check.

EDIT: no 2x2 dets in the code, only in tests.

TotoGaz avatar Jul 29 '21 17:07 TotoGaz