0

I am using Ubuntu 14.04 on a core i5 machine. The following code was tested on different computers with a very fast run time (3258 ms) but on my system it takes 112921 ms. I use g++ as compiler.

#include <iostream>
#include <chrono>
#include <Eigen/Core>
#include <Eigen/Cholesky>

using namespace std;

using namespace std::chrono;

using namespace Eigen;


int main()

{

const MatrixXd::Index size = 4200;
MatrixXd m = MatrixXd::Random(size, size);
m = (m + m.transpose()) / 2.0 + 10000 * MatrixXd::Identity(size, size);

LLT<MatrixXd> llt;
auto start = high_resolution_clock::now();
llt.compute(m);
if (llt.info() != Success)
    cout << "Cholesky decomposition failed!" << endl;
auto stop = high_resolution_clock::now();

cout << "Cholesky decomposition in "
     << duration_cast<milliseconds>(stop - start).count()
     << " ms." << endl;

return 0;

}
gsamaras
  • 71,951
  • 46
  • 188
  • 305
Mostafa Ghafoori
  • 187
  • 2
  • 3
  • 13

2 Answers2

0

I assume you are compiling in Debug mode without optimization.

If you are using CMake, build with cmake -DCMAKE_BUILD_TYPE=Release or cmake -DCMAKE_BUILD_TYPE=ReleaseWithDebugInfo. Otherwise try to add the optimization flag -O3 to you g++ compiler.

cassinaj
  • 1,043
  • 7
  • 13
0

When you compile a program in debug mode (like g++ -std=c++11 for example), a lot of things happen under the hood. Recall what information you can see when a crash occurs. All this information and the housekeeping takes time.

For that reason, when your program is tested and it works fine, you do not need the housekeeping no more, you want performance to come into play.

Use optimization flags, like O1, O2 or O3 (there are more). Which one to use? Heavily depends on your application, so experiment with at least these three options.


Note: Make sure you use a capital Omikron, otherwise (if you type a lowercase omikron or a zero) you will think you compiled your code with optimization enabled, but it would still compiled in debug mode.

Sourcing the Gcc tutorial:

Generate symbolic information for gdb and many warning messages.

g++ -g -Wall myprog.C -o myprog

Generate optimized code on a Solaris machine with warnings. The -O is a capital o and not the number 0!

g++ -Wall -O1 -mv8 myprog.C -o myprog
Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305