This forum has been archived. All content is frozen. Please use KDE Discuss instead.

gcc 4.7.0 sparse matrix crash on printing matrix

Tags: None
(comma "," separated)
mfiers
Registered Member
Posts
8
Karma
0
OS
Hello folks!

I'm a very happy eigen3 user! Recently, I bumped into a very strange problem, which seems to be related to the compiler I use. Below is a contained c++ file that demonstrates the crash, in what looks like very simple code at first sight. The crash occurs when using a GCC 4.7.0 compiler. (when I use GCC 4.9.1, the problem does not appear).

Code: Select all
#include <stdio.h>
#include <complex>
#define dcomplex std::complex<double>

#include "../../contrib/eigen32/eigen/Eigen/Core"
#include "../../contrib/eigen32/eigen/Eigen/LU"
#include "../../contrib/eigen32/eigen/Eigen/Sparse"

int main() {
    printf( "Will try out some things\n");
    dcomplex cnum(1, 1.0);
   
    Eigen::SparseMatrix<dcomplex, Eigen::RowMajor, int> data(6, 6);

    std::stringstream s;
    s << data;
    printf("data: %s", s.str().data());
    s.str("");
   
   
    // Test: inserting / using coeffRef (both crash)
    data.insert(0, 0) = cnum;
    //data.coeffRef(0, 0) += cnum;
   
   
    // Test: using makeCompressed: doesn't change the behavior
    //data.makeCompressed();
   
    // Test: finalizing the matrix: doesn't change the behavior
    //data.finalize();
   
    // It will allow performing operations on the matrix:
    printf("number of nonzeros now: %d\n", data.nonZeros());
    printf("norm: %f\n", data.norm());
   
    // But it will not allow printing the matrix for a second time. Crashes:
    s << data;
    printf("data: %s", s.str().data());
    s.str("");
   
};


Unfortunately, switching to gcc 4.9 is not an option, because other third-party tools / modules that are loaded at runtime, use gcc 4.7. I am using Windows. I tried looking through the issue tracker but could not find anything that could be related.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Could you paste the backtrace. Thanks.

And what about using std::cout << "data:" << std::endl << data << std::endl; instead of C code?
mfiers
Registered Member
Posts
8
Karma
0
OS
Hello,

Thank you for the response!
I just tested it on Linux, using gcc 4.7.0 (I was hoping to then use gdb / valgrind to look for something suspicious). Unfortunately I cannot reproduce it there: the program does not crash. So it's only on Windows, gcc 4.7.0. Here's the full specs of the compiler on Windows:

Code: Select all
> gcc -v                                           
Using built-in specs.                                                                                   
COLLECT_GCC=c:\Users\mfiers\Anaconda\envs\myenv\Scripts\gcc.bat\..\..\MinGW\bin\gcc.exe             
COLLECT_LTO_WRAPPER=c:/users/mfiers/anaconda/envs/myenv/mingw/bin/../libexec/gcc/x86_64-w64-mingw32/4
.7.0/lto-wrapper.exe                                                                                     
Target: x86_64-w64-mingw32                                                                               
Configured with: ../../../build/gcc/src/configure --target=x86_64-w64-mingw32 --prefix=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --with-sysroot=/c/bb/vista64-mingw32/mingw-x86-x86_64/build/build/root --enable-languages=all,obj-c++ --enable-fully-dynamic-string --disable-multilib                     
Thread model: win32                                                                                     
gcc version 4.7.0 20111220 (experimental) (GCC)                                                         


Additional things I tried:
- I've been looking on how to create a backtrace on Windows but it seems to be extremely difficult.
- I tried compiling with -g -O0, but the same problem occurs.
- I tried the code you suggested, but it will crash, too.

Are there compiler options from eigen which I could use that could give me some more information?

I don't think it's really related to the printing: I think the matrix is somehow corrupted. This is because in my production code I don't explicitly print the matrix, and I also get crashes.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Without a backtrace we cannot do anything.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Cannot you upgrade to a non experimental GCC, like gcc-4.7.2-1
mfiers
Registered Member
Posts
8
Karma
0
OS
Upgrading to 4.7.2 seems to be solving the problem. Furthermore, it seems the runtime libstdc++-6.dll is 'compatible' between 4.7.0 and 4.7.2-compiled modules.

Thank you very much for the assistance! I'll accept the answer, but I still have to do some more testing. if anything weird pops up, I'll re-open this topic.

Thanks again!
Martin


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]