TRIQS / nda

C++ library for multi-dimensional arrays
https://triqs.github.io/nda
Other
13 stars 11 forks source link

nda::algorithms:all (probably fold) silent failure on gcc 12.2 with -Ofast #57

Open HugoStrand opened 7 months ago

HugoStrand commented 7 months ago

Description

The nda::algorithms test breaks when using all and any when compiling nda 1.2.x at 6c71ef7 using gcc 12.2 with -Ofast. I suspect that some loop is silently optimised away in the fold algorithm.

Steps to Reproduce

  1. Compile nda with gcc 12.2 and -Ofast
  2. Run the tests

Actual behavior:

> ctest -V -R nda_algorithms
Test project /.../nda/cbuild
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 46
    Start 46: nda_algorithms

46: Test command: /.../nda/cbuild/test/c++/nda_algorithms
46: Test timeout computed to be: 10000000
46: [==========] Running 4 tests from 1 test suite.
46: [----------] Global test environment set-up.
46: [----------] 4 tests from NDA
46: [ RUN      ] NDA.any_all
46: /.../nda/test/c++/nda_algorithms.cpp:31: Failure
46: Value of: all(isnan(A))
46:   Actual: false
46: Expected: true
46: 
46: /.../nda/test/c++/nda_algorithms.cpp:37: Failure
46: Value of: any(isnan(A))
46:   Actual: false
46: Expected: true
46: 
46: [  FAILED  ] NDA.any_all (0 ms)
46: [ RUN      ] NDA.any_all_cplx
46: /.../nda/test/c++/nda_algorithms.cpp:51: Failure
46: Value of: all(isnan(A))
46:   Actual: false
46: Expected: true
46: 
46: /.../nda/test/c++/nda_algorithms.cpp:57: Failure
46: Value of: any(isnan(A))
46:   Actual: false
46: Expected: true
46: 
46: [  FAILED  ] NDA.any_all_cplx (0 ms)
46: [ RUN      ] NDA.Algo1
46: [       OK ] NDA.Algo1 (0 ms)
46: [ RUN      ] NDA.AlgoMat
46: [       OK ] NDA.AlgoMat (0 ms)
46: [----------] 4 tests from NDA (0 ms total)
46: 
46: [----------] Global test environment tear-down
46: [==========] 4 tests from 1 test suite ran. (0 ms total)
46: [  PASSED  ] 2 tests.
46: [  FAILED  ] 2 tests, listed below:
46: [  FAILED  ] NDA.any_all
46: [  FAILED  ] NDA.any_all_cplx
46: 
46:  2 FAILED TESTS
1/1 Test #46: nda_algorithms ...................***Failed    0.05 sec

0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.08 sec

The following tests FAILED:
     46 - nda_algorithms (Failed)
Errors while running CTest

Versions

nda 1.2.x at 6c71ef7

hmenke commented 2 months ago

This is expected. -Ofast implies -ffast-math which in turn implies -ffinite-math-only, i.e. it assumes that all floating point math is finite and there will never be any inf or nan. Therefore any instance of isnan will simply be optimized out as false. Generally the recommendation is to not use -ffast-math at all, see https://simonbyrne.github.io/notes/fastmath/

HugoStrand commented 2 months ago

This was discussed at the triqs updates meeting 2024-06-27 and the agreement was to catch -Ofast at CMake level and refuse to build.