Registered Member
|
Hi,
I had some Matlab code that I was trying to speed up, so I rewrote it in C++/Eigen. To my surprise, it's slower ... a lot slower. Here's a test program I wrote, using Eigen 2.0.15. All it does is matrix multiplication two hundred times:
On my Ubuntu 9.10/duo Xeon 5130 2Ghz system that supports SSE2, it takes around 1.18 seconds to run:
Here's how I compiled it:
And here's the version information for g++:
If I run this code in r2010a Matlab (using the -singlethread option to keep the comparison fair):
I get this:
I'm stumped! If I'm doing something wrong here, I don't know what it is. What am I missing? What can I try to track down the problem? Thanks in advance, Polly |
Registered Member
|
Something must be wrong with your compiler switches. On my macbock (2.4 GHz core2duo) your c++ code takes 0.28 sec to run:
test$ g++ -Wall -O2 -I/usr/local/include/eigen3 eigenBench.cpp -o eigenBench eigenBench.cpp: In function ‘int main(int, char**)’: eigenBench.cpp:55: warning: deprecated conversion from string constant to ‘char*’ test$ ./eigenBench eigen vectorize is ENABLED main: : elapsed time: 0.282082 secs adding -msse2 or -msse3 doesn't change the game at all: test$ g++ -Wall -O2 -msse2 -I/usr/local/include/eigen3 eigenBench.cpp -o eigenBench eigenBench.cpp: In function ‘int main(int, char**)’: eigenBench.cpp:55: warning: deprecated conversion from string constant to ‘char*’ test$ ./eigenBench eigen vectorize is ENABLED main: : elapsed time: 0.281478 secs mocart03:test$ g++ -Wall -O2 -msse3 -I/usr/local/include/eigen3 eigenBench.cpp -o eigenBench eigenBench.cpp: In function ‘int main(int, char**)’: eigenBench.cpp:55: warning: deprecated conversion from string constant to ‘char*’ test$ ./eigenBench eigen vectorize is ENABLED main: : elapsed time: 0.283794 secs g++ version: test$ g++ -v Using built-in specs. Target: i686-apple-darwin10 Configured with: /var/tmp/gcc/gcc-5664~38/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 Thread model: posix gcc version 4.2.1 (Apple Inc. build 5664) |
Moderator
|
move to Eigen3 with is 3 time faster on that example ?
Now on that example Eigen2 and 3 should be equally fast and at least as fast than MatLab since we have the fastest matrix-vector products ... |
Moderator
|
oops, actually the problem is that you are using MatrixXd to represent vectors while you should use VectorXd. After this change this much faster (0.12s on my 2GHz core2), and you can even mark that your product does not alias:
Eigen2 : C = (A*B).lazy(); Eigen3 : C.noalias() = A * B; (=> 0.11s) |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]