Thursday, 15 April 2010

How to speed up this C++ program with eigen library against matlab? -



How to speed up this C++ program with eigen library against matlab? -

i want utilize c++ big linear algebra computation. starting step, these comparing programs created in c++ , matlab. giving astonishing execution time here. can suggest way beat matlab or atleast comparable performance? know c++ uses highly vectorized methods computations. in big scientific programming involving linear algebra, should 1 go matlab instead of c++? think matlab doesn't give performance big computations hence c++ preferred matlab in such cases. programme results go contrary belief.

c++ programme compiled gcc:

#include <iostream> #include <eigen\dense> //eigen library using namespace eigen; using namespace std; int main() { matrixxd a; a.setrandom(1000, 1000); matrixxd b; b.setrandom(1000, 1000); matrixxd c; c=a*b; }

execution time: 24.141 s

here matlab program:

function [ ] = trial( ) clear all; close all; clc; tic; a=rand([1000,1000]); b=rand([1000,1000]); c=a*b; toc end

elapsed time 0.073883 seconds.

it extremely hard beat matlab, optimizations turned on. out of eigen need compile parallel back upwards (-fopenmp in gcc), , turn optimizations on (-o3). in case, matlab faster, because using intel mkl proprietary library out of intel chips, unless purchase don't think able beat it. using eigen project , wasn't able beat matlab (at to the lowest degree not dense matrix multiplication).

for example, a*b a , b 1000 x 1000 complex matrices, best average time can is:

matlab: 0.32 seconds eigen: 0.44 seconds

for 2000 x 2000,

matlab: 2.80 seconds eigen: 3.45 seconds

system: macbookpro 2013, os x.

ps: should create absolutely sure turn optimizations on (-o3) , compile parallel support, -fopenmp. reason you're getting huge difference in running time. should compile programme as:

g++ -o3 -fopenmp <other compiling flags/parameters> main.cpp

c++ matlab eigen

No comments:

Post a Comment