This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Benchmark: slow sparse matrix - dense vector multiplication

Tags: None
(comma "," separated)
idji
Registered Member
Posts
2
Karma
0
Hi,

I've done some benchmark on sparse matrix - dense vector multiplication with Eigen2 and Gmm++. Performance of this operation is very important to me because I have to do this lots of times in my project.

It turns out that Eigen2 is twice slower than Gmm++. Of course, there is no reason for Eigen2 to supposedly be faster than Gmm++, but I am just wondering here if I got this done correctly in my code, or if there's some possible improvements with Eigen2 for this matrix-vector operation.

TEST CODE:

#include <iostream>
#include <Eigen/Eigen>
#include <gmm/gmm.h>

const int N=30000;

int main() {

std::clock_t start;
double diff;

Eigen::DynamicSparseMatrix<double> m1(N,N);
Eigen::VectorXd v1(N), vv1(N);
gmm::col_matrix< gmm::rsvector<double> > m2(N,N);
std::vector<double> v2(N), vv2(N);

for (int i=0;i<N;i++) {
for (int j=0;j<N;j++) {
double r=drand48();
if (r<0.05) {
m1.coeffRef(i,j)=r;
m2(i,j)=r;
}
}
}

gmm::fill_random(v2);
for (int i=0;i<N;i++) v1[i]=v2[i];

start=std::clock();
for (int i=0;i<100;i++) vv1=m1*v1;
diff=(std::clock()-start)/(double)CLOCKS_PER_SEC;
std::cout << "EIGEN2: " << diff << std::endl;

start=std::clock();
for (int i=0;i<100;i++) gmm::mult(m2,v2,vv2);
diff=(std::clock()-start)/(double)CLOCKS_PER_SEC;
std::cout << "GMM++: " << diff << std::endl;

}

RESULT:

EIGEN2: 44.06
GMM++: 19.54

The code was compiled with g++ 4.1.2 and -O2 -msse2 optimization switches.

Regards,

DH
Andre
Registered Member
Posts
90
Karma
1
Have you tried using SparseMatrix instead of DynamicSparseMatrix? Don't know if it makes a difference, but I'd guess so.


'And all those exclamation marks, you notice? Five? A sure sign of someone who wears his underpants on his head.' ~Terry Pratchett

'It's funny. All you have to do is say something nobody understands and they'll do practically anything you want them to.' ~J.D. Salinger
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hi,

indeed, I confirm the issue, and I'm pretty sure that wasn't the case when I implemented this product because I always bench against gmm (e.g., see what is in the bench/ folder). I'll see what's going wrong...
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
ok, the problem was that GCC generated poor code for some unknown reasons... the workaround was to split the function into two smaller one. Now Eigen is as fast as gmm for that product
idji
Registered Member
Posts
2
Karma
0
Thanks for quick response and fix! Now I can see that eigen2-devel performs as fast as gmm++ does on that product.


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]