I am compiling a C++ command line program involving Eigen 3.3.4, using VS 2017 Professional edition.
This is my program:
#include "stdafx.h"
#include <iostream>
#include "Eigen/Dense"
#include <Eigen/Sparse>
#include <Eigen/Eigenvalues>
#include <vector>
using namespace std;
using namespace Eigen;
using Eigen::Dynamic;
using Eigen::Matrix;
using Eigen::SparseMatrix;
typedef SparseMatrix<double, Eigen::RowMajor> SpMat;
int main()
{
try
{
MatrixXd mat(8, 8);
mat << 7, 0, 1, 0, 0, 2, 7, 0,
0, 4, 8, 0, 2, 0, 0, 0,
1, 8, 1, 0, 0, 0, 0, 5,
0, 0, 0, 7, 0, 0, 9, 0,
0, 2, 0, 0, 5, 1, 5, 0,
2, 0, 0, 0, 1, 1, 0, 5,
7, 0, 0, 9, 5, 0, 11, 0,
0, 0, 5, 0, 0, 5, 0, 5;
cout << mat << endl;
Eigen::LLT<Eigen::MatrixXd> lltOfA(mat);
cout << lltOfA.info() << endl;
SpMat sparseMat = mat.sparseView();
cout << "try SimplicialLLT solver" << endl;
SimplicialLLT<SpMat, Eigen::Upper> lltSolver;
lltSolver.compute(sparseMat);
cout << lltSolver.info() << endl;
}
catch (const exception& e)
{
cout << e.what() << endl;
}
return 0;
}
This is my linker option:
/OUT:"D:\TestProjects\LLTSolver\x64\Release\LLTSolver.exe" /MANIFEST /LTCG /NXCOMPAT /PDB:"D:\TestProjects\LLTSolver\x64\Release\LLTSolver.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /PGD:"D:\TestProjects\LLTSolver\x64\Release\LLTSolver.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\LLTSolver.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
And this is my compilation option:
/Yu"stdafx.h" /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc110.pdb" /D "WIN32" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /Fa"x64\Release\" /EHa /nologo /Fo"x64\Release\" /Fp"x64\Release\LLTSolver.pch"
Here are my findings:
- If I compile it with
Release
flag, and with no optimization(/Od
), then the program can work well. The output can be generated when I run my program in command line - If I compile it with
Release
flag, and with optimization ( either/O1
orO/2
), then the program will crash, and it will crash in such a way that not even thecatch
statement can catch the exception.
The only trace I can find, resulted from the crash, is in event viewer:
Faulting module name: LLTSolver.exe, version: 0.0.0.0, time stamp: 0x5a6e9440
Exception code: 0xc0000005
Fault offset: 0x000000000000d4b4
Faulting process id: 0x5004
Faulting application start time: 0x01d398b0e99f62f4
When I compile without the NDEBUG
macro (gcc equivalent of -DNDEBUG
), I will get the following message, sometimes; some other times, no error message at all.
Assertion failed: (m_outerIndex[outer+1]-m_outerIndex[outer]==0 || m_data.index(m_data.size()-1)<inner) && "Invalid ordered insertion (invalid inner index)",
at file
..\eigen\src/SparseCore/SparseMatrix.h, line 393
Not too sure whether the VS compiler optimization is to be blamed, or there is a bug in Eigen 3.3.4. How can I proceed further on this?