Search code examples
c++visual-studiogcceigeneigen3

Eigen library: eigenvalue computation performance, gcc vs visual studio 2015


I am trying to increase the performance of eigenvalue and eigenvector calculation using the Eigen library using the following piece of code:

MatrixXd eigMat =m.ToMatrixXd(); //internal conversion to MatrixXd
EigenSolver<MatrixXd> es(eigMat,ShouldComputeEigenVectors);

Initially I was using an older version of Eigen with tdm-gcc 4.8 and compiled the code using the optimization at O2 level. The calculation of eigenvalues and vectors for a 1000 by 1000 matrix was taking around 5.4 seconds.

A few months ago I have switched to Visual Studio Community 2015 and upgraded the Eigen library to Eigen 3.3.2. Now the same calculation takes around 18.7 seconds. Why am I getting a worse performance compared with gcc 4.8? Is there anything I can do to go back to 5.4 seconds (needless to say the goal is to catch Matlab which performs in 0.8 seconds).

The settings for VS 2015:

/GS /Qpar /GL /analyze- /W3 /Gy /Zc:wchar_t /I"C:\wxWidgets-3.1.0\lib\vc_dll\mswu" /Zi /Gm- /O2 /Ob2 /sdl /Fd"Release\vc140.pdb" /Zc:inline /fp:precise /D "_CRT_SECURE_NO_WARNINGS" /D "WIN32" /D "_UNICODE" /D "__WXMSW__" /D "UNICODE" /D "WXUSINGDLL" /D "NDEBUG" /D "EIGEN_NO_DEBUG" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /arch:SSE2 /Gd /Oy- /Oi /MD /openmp /Fa"Release\" /EHsc /nologo /Fo"Release\" /Ot /Fp"Release\sciencesuit.pch"

Btw, I tried the following with no or very little (1 second) performance gains:

  1. Different instruction sets, such as AVX2
  2. Floating model point, to Fast
  3. OpenMP and No OpenMP options
  4. Optimization, full optimization Ox

Thanks in advance.


Solution

  • The short answer is that cl (the Visual Studio compiler) doesn't do as good a job as gcc when it comes to performance, especially when it comes to template libraries such as Eigen.

    That being said, try using the older version of Eigen with Visual Studio. There were some changes in Eigen that created drops in performance with Visual Studio (e.g. this).