Re: [eigen] Incorrect result when inverting 4x4 Matrix with gcc7.3 and -ffast-math |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Incorrect result when inverting 4x4 Matrix with gcc7.3 and -ffast-math
- From: Dan Čermák <dan.cermak@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Feb 2018 12:50:43 +0100
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=cgc-instruments.com; b=dG7irVp0MRrk4Xz2BNFpnjnTqCsV4mwSjTE8o4QKjMvxGAGJ3eIdiazRLNlWlNygVTohDk3jvufGmb8NVmnwZng9LZKJDMQpDc1Afg2WzVmpIznqnx9Pwrp4lGHzD6XwSPZRYaFZpugWzEagyCmkXq8CMegin625Z9roTd/+4+I=; h=From:To:Subject:In-Reply-To:References:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding;
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