[eigen] slow adjoint sparse dense product

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

I am working on iterative solvers for large sparse matrices and I am
thinking about switching from uBLAS to Eigen. But the one thing that
keeps me from changing the library is that the product of the adjoint of
a sparse matrix with a vector is about half the speed of multiplying
directly with the non-adjoint matrix. I attached a small simple test
file that measures the time for an example matrix.

I figured out that for the product y=Ax in class SparseTimeDenseProduct
the case "if(Rhs::ColsAtCompileTime==1)" is chosen and the computation
is quite fast.
But for y=A^{H}x there is no optimized case that can be chosen. Is there
a way to speed up the multiplication with an adjoint sparse matrix?

Sebastian
#include <Eigen/Core>
#include <Eigen/Sparse>
#include <iostream>
#include <complex>

#include <boost/timer.hpp>

using namespace std;

int main()
{
    const int size = 100000;
    const int nnzpc = 100;
    const int iter = 1000;
    boost::timer time;

    Eigen::VectorXcd x(size),y(size);
    Eigen::SparseMatrix<complex<double>,Eigen::ColMajor> A(size,size);

    A.reserve(size*nnzpc);
    for (int n = 0; n < size; ++n)
        for (int m = 0; m < nnzpc; ++m)
            A.insert((m*nnzpc+n)%size,n) = complex<double>(m,n);
    A.finalize();

    time.restart();
    for (int i = 0; i < iter; ++i)
        y = A*x;
    cout << "time y=Ax: " << time.elapsed() << endl;

    time.restart();
    for (int i = 0; i < iter; ++i)
        y = A.adjoint()*x;
    cout << "time y=A^{H}x: " << time.elapsed() << endl;
}

// time y=Ax: 46.46
// time y=A^{H}x: 85.69

Attachment: signature.asc
Description: OpenPGP digital signature



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/