I am studying the simple multiplication of two large matrices using the Eigen library. This multiplication is apparently noticeably slower than Matlab and Python for matrices of the same size.
Is there anything to make Eigen surgery faster?
Problem Details
X: 1000 x 50,000 random matrix
Y: random matrix 50,000 x 300
Experiment Dates (on my last MacBook Pro at the end of 2011)
Using Matlab: X * Y takes ~ 1.3 s
Using Enthought Python: numpy.dot (X, Y) takes ~ 2.2 sec
Using Eigen: X * Y takes ~ 2.7 sec
Own information
You can get the Eigen code (as a MEX function): https://gist.github.com/michaelchughes/4742878
This MEX function is read in two matrices from Matlab and returns their product.
Performing this MEX function without an operation with a matrix product (i.e., just performing an IO) is not expensive, so the IO between the function and Matlab does not explain the big difference in performance. This is clearly a valid matrix product operation.
I am compiling with g ++ with these optimization flags: "-O3 -DNDEBUG"
I use the latest stable Eigen header files (3.1.2).
Any suggestions on how to improve Eigen's performance? Can someone reproduce the gap that I see?
UPDATE The compiler really seems important. The initial Eigen time was done using Apple's version of Xcode g ++: llvm-g ++ - 4.2.
When I use g ++ - 4.7, loaded via MacPorts (same CXXOPTIMFLAGS), I get 2.4 sec instead of 2.7.
Any other compilation suggestions would be better appreciated.
You can also get the C ++ source code for this experiment: https://gist.github.com/michaelchughes/4747789
./MatProdEigen 1000 50,000 300
reports 2.4 seconds under g ++ - 4.7