zhong-yy/GraSphInv

Compilation with g++ 11.3 compiler on Ubuntu 22.04 may cause severe floating point error

zhong-yy opened this issue · 0 comments

Originally, GraSphInv was tested with compilers g++ 9.3 and Intel oneAPI 2021/2022 on Ubuntu 20.04. However, the program compiled by a newer version of g++ (11.3.0) on Ubuntu 22.04 is found to produce sporadic large errors. Thanks to Keying Zhu for pointing out this.

For example, in Examples/Tibet50kmH_0_25x0_25/data/Crust_Correction/crystalline_crust_g_r calculated by the program compiled by g++ 11.3 on ubuntu 22.04, there are 5082 extremely large values which are inconsistent with the original file. It looks like
image

Then I tested Intel oneAPI 2023 compiler on Ubuntu 22.04 to see if this problem is specific to g++ compilers. In the Crust_Correction example, 1077 out of 20905 data points in file moho_g_r are different from the original file with a maximum absolute difference of 1.76 mGal and the rest of the data points are the same as the original files. I think this difference is still within an acceptable range in view of different implementation of C++ compilers and the inherent numerical inaccuracy of Gaussian Legendre quadrature. For the rest of files, e.g crystalline_crust_g_r, sediments_g_r, rm_sedim_cryst_g_r, rm_sedim_g_r, mantle_g_r are exactly the same as the original file (with maximum difference less than 1e-12).

I suspect that the large error caused by g++ 11.3.0 is due to compiler optimization. I will get around to test a lower level of compiler optimization by adding a statement set(CMAKE_BUILD_TYPE Debug) to file cmake.config.