Re: [eigen] Problem with g++-4.4 -O2 and Eigen3 |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Problem with g++-4.4 -O2 and Eigen3
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 7 Apr 2011 18:04:28 +0200
- Cc: hauke strasdat <strasdat@xxxxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=kP0PqkCmV+csfVyUi4pDVZBTZhfpiAVGnLaSZyA8oC0=; b=uTwZNvVyZMK3hpSEmyPmtB99JIFQkKixKt8N29EamsiwertVtVaTfXbaMtHYWCEX+D /PDariXKlsoBGqYI1guKBAk5StvmeIK/gy0UHbNCLI/U9xaiKYARrDwksh8gzsSYpIiC xISemztTnqp872KmvUvUEoCN1WIQfJVOI2k0Y=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=vJxDzfhe7Z9RtcUgqp4kliGIGGfek5zHVns5UxVOWZJ8V1Ady0qnIIEuHQa1D6bKSM 3HSuaq/hykabhA1GGvTuWTj+tS3hl8WiucAB63kFpUhxGUBTwgP+XceJGTsjO4Iq6Yad rW1/Wi6imP5EH+BquJ96gqf6LEjQbm0r/QKaw=
the fix is very obvious, change the last line of your CMakeLists.txt to:
ADD_EXECUTABLE(test foo.cpp main.cpp foo.h)
(reverse foo.cpp and main.cpp). The effect is to change the order of
the .o files at linking stage, and here that does the trick.
btw, I was kidding, this makes no sense to me :) But at least we know
that something very strange happens during the linking.
gael
On Thu, Apr 7, 2011 at 5:30 PM, hauke strasdat <strasdat@xxxxxxxxx> wrote:
> Hi all,
>
> I think I found a bug related to g++-4.4 and Eigen3.
>
> If I multiply two matrices A=[1 1;0 0] and B=[1 0; 1 0] to each other,
> the sign of the result is flipped: [-2 0; 0 0] instead of [2 0; 0 0].
> A.row(0).dot(B.col(0)) always provides the correct result 2.
>
> What triggers the bug:
> - Apply lu().inverse() on a random matrix,
> - and A*B is calculated in a member function of a separate class.
> - and the program is complied using g++-4.4 with optimisation O2 or O3.
>
> The bug does not happen if I compile the program with O0/O1 or with
> g++-4.3/g++-4.5.
>
> g++-4.4 is the standard compiler for Ubuntu 10.04 (v 4.4.3) and 10.10
> (v 4.4.5) and I could reproduce the bug on both operating systems
> (both 64 bit).
> I tried the Eigen3 release version as well as a very recent version
> from the hg repository.
>
> This could be a regression in g++-4.4, but I thought it is a good idea
> to contact you guys first.
> It would be awesome, if somebody would know a work-around, since it
> would be very difficult for me
> to switch to g++-4.3 or g++-4.5.
>
> A small test case is attached below.
>
> Cheers,
> Hauke S.
>
>
>
> --- FILE foo.cpp:
>
> #include "foo.h"
> #include <iostream>
>
> using namespace std;
>
> double Foo::method()
> {
> Matrix<double, 2,2> A;
> A << 1,1,
> 0,0;
> MatrixXd B(2,2);
> B <<1,0,
> 1,0;
> MatrixXd C = (A*B);
> cerr << "A*B = " << C << endl;
> cerr << "a*b = " << A.row(0).dot(B.col(0)) << endl;
>
> return 0;
> }
>
> -- FILE foo.h:
>
> #ifndef FOO_H
> #define FOO_H
>
> #include <Eigen/Core>
> #include <Eigen/LU>
> using namespace Eigen;
>
> class Foo
> {
> public:
> double method();
> };
>
> #endif
>
> -- FILE main.cpp:
>
> #include "foo.h"
>
> int main()
> {
> MatrixXd X(1,1);
> X << 2;
> X.lu().inverse();
>
> Foo foo;
> foo.method();
> }
>
> --- FILE CMakeLists.txt:
>
> SET (PROJECT_NAME TEST)
>
> PROJECT(${PROJECT_NAME})
> CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
> SET (CMAKE_VERBOSE_MAKEFILE ON)
>
> SET(CMAKE_CXX_COMPILER /usr/bin/g++-4.4)
>
> SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -Werror -Wall")
> SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -Werror -Wall")
>
> # override by appending -DCMAKE_BUILD_TYPE=Debug to cmake argument list
> IF( NOT CMAKE_BUILD_TYPE )
> SET( CMAKE_BUILD_TYPE Release )
> ENDIF()
>
> SET (INCLUDE_DIRS "eigen3/" )
> INCLUDE_DIRECTORIES( ${INCLUDE_DIRS})
>
> ADD_EXECUTABLE(test main.cpp foo.cpp foo.h)
>
>
>