Re: [eigen] Incorrect result when inverting 4x4 Matrix with gcc7.3 and -ffast-math |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Hi Michael,
I am not an Eigen developer, so I cannot give you a definitive answer,
but afaik -ffast-math enables the compiler to aggressively reorder
floating point operation to increase performance. That comes at the cost
of loosing IEEE compliance. I have myself seen numerical code break
spectacularly with -ffast-math because it relies the floating point
operations being precise.
So I my guess is that you are seeing a new optimization that gcc enables
backfiring and if anything is at fault, then maybe gcc.
Cheers,
Dan
Michael Mößner <michael.moessner@xxxxxx> writes:
> Hello
>
> I get incorrect results, when I invert a 4x4 matrix with gcc7.3 and the
> compiler option -ffast-math. Unfortunatly, I don't get access to the bug
> tracker, so I post it here.
>
> Example code: (compile with "g++ test.cpp -O3 -ffast-math")
>
> #include <Eigen/Dense>
> #include <iostream>
> using namespace std;
>
> int main(int argc, char **argv)
> {
> Eigen::Matrix<double,4,4> test;
> test(0,0) = 1.; test(0,1) = 0.; test(0,2) = 0.; test(0,3) = 0.;
> test(1,0) = 0.; test(1,1) = 1.; test(1,2) = 0.; test(1,3) = 0.;
> test(2,0) = 0.; test(2,1) = 0.; test(2,2) = 1.; test(2,3) = 0.;
> test(3,0) = 0.; test(3,1) = 0.; test(3,2) = 0.; test(3,3) = 1.;
>
> cerr << test.inverse() << endl;
> return 1;
> }
>
> ------------------------------
>
> This results in
>
> 1 0 0 0
> -0 -1 -0 -0
> 0 0 1 0
> -0 -0 -0 -1
>
> ------------------------------
>
> The expected result is
>
> 1 0 0 0
> 0 1 0 0
> 0 0 1 0
> 0 0 0 1
>
> ---------------------------------
>
> I also tested this code with gcc4.8.5, gcc5.2 and clang6.0.0 where the
> problem does NOT occur.
>
> I also tested with gcc7.2 where the problem occurs.
>
> The problem does NOT occur when ommitting the -ffast-math or when
> compiling with -O0
>
> My Eigen version:
>
> 3.3.4
>
> My system data:
>
> SUSE Linux Enterprise Desktop 12 SP2
>
> Intel(R) Xeon(R) CPU E3-1276 v3 @ 3.60GHz
>
> ---------------------------
>
> I also tested the following systems where the bug also occurs:
>
> ----------------------------
>
> SUSE Linux Enterprise Desktop 11 SP2
>
> Intel(R) Xeon(R) CPU E3-1276 v3 @ 3.60GHz
>
> ------------------------------
>
> SUSE Linux Enterprise Desktop 12 SP2
>
> Intel(R) Xeon(R) CPU E3-1230 @ 3.20GHz
>
> ------------------------------
>
> Best regards
>
> Michael
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |