本征线性代数求解器似乎很慢 [英] Eigen linear algebra solvers seem slow

查看:76
本文介绍了本征线性代数求解器似乎很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用本征求解器求解线性代数方程Ax = b.在我的情况下,A是一个复杂的稀疏矩阵(26410 * 26410),b是一个实向量(26410 * 1).

I want to solve a linear algebraic equation Ax = b using Eigen solvers. In my case, A is a complex sparse matrix(26410*26410), b is a real vector (26410*1).

我在MATLAB中使用mex文件将稀疏矩阵A和向量b映射为Eigen接受的格式.我之所以使用Eigen求解器,是希望它比使用 x = A \ b 在MATLAB中直接求解更快.

I use mex file in MATLAB to map the sparse matrix A and vector b to Eigen accepted format. The reason why I use Eigen solver is to hope it would be faster than solving directly in MATLAB using x = A\b.

但是,在尝试了LDLT,SparseLU,CG和BiCGSTAB之后,我发现结果并不令人满意:

However, after tried LDLT, SparseLU, CG and BiCGSTAB, I found the results are not very satisfying:

LDLT耗时1.462s,且 norm(A * x-b)/norm(b)= 331 ;SparseLU以1.5193e-4赢得37.994s;BiCGSTAB成绩为95.217秒,成绩为4.5977e-4;相比之下,直接在MATLAB中使用 x = A \ b 消耗13.992s的标准误差为2.606e-5.

LDLT takes 1.462s with norm(A*x - b)/norm(b) = 331; SparseLU takes 37.994s with 1.5193e-4; BiCGSTAB takes 95.217s with 4.5977e-4; On the contrast, directly use x = A\b in MATLAB consumes 13.992s with norm of the error 2.606e-5.

我知道将MATLAB工作空间中的稀疏矩阵A和向量b映射到Eigen有点愚蠢,也很费时间.但是我想知道我获得的结果是否是Eigen可以提供的最佳结果?有人可以给我一些指示吗?我应该尝试其他线性方程求解器吗?在此先多谢!以下是代码的主要部分.

I know it is a little stupid and also time consuming to map the sparse matrix A and vector b in MATLAB workspace to Eigen. But I am wondering whether the results I got are the best results which Eigen can give? Anyone can give me some pointers? Should I try some other linear equation solvers? Thanks a lot in advance! The following is the main part of codes.

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

    //input vars

    //temp var
    size_t nrows;

    //output vars
    //double *x;

    //GetData
    /* check inputs 
    ...*/

    //"mxArray2SCM" is a sub-function for map the complex sparse matrix in Eigen
    SpCMat A = mxArray2SCM(prhs[0]);
    //SpMat A = mxArray2SM(prhs[0]);

    //"mxArray2ECV" is a sub-function for map the real vector in Eigen
    Eigen::VectorXcd b = mxArray2ECV(prhs[1]);
    //Eigen::VectorXd b = mxArray2EV(prhs[1]);   
    nrows = b.size();
    //Computation
    Eigen::VectorXcd x(nrows);
    //SparseLU<SparseMatrix<CD> > solver;
    BiCGSTAB<SparseMatrix<CD>,IncompleteLUT<CD> > BiCG;
    //BiCG.preconditioner().setDroptol(0.001);
    BiCG.compute(A);
    if(BiCG.info()!=Success){
        //decomposition failed
        return;
    }
    x = BiCG.solve(b);

    //Output results
    plhs[0] = ECV2mxArray(x);   
}

推荐答案

您是否考虑过使用 PetSc 用于Krylov求解器还是 SLEPc 来计算特征值?

Have you considered using PetSc for Krylov solvers or SLEPc to compute eigenvalues?

请确保在使用特定的Krylov求解器之前分析本征谱(CG仅适用于对称正定矩阵).

Make sure you analyze the eigenspectrum before using a specific Krylov solver (CG works only for symmetric positive definite matrices).

PETSc有很多求解器,您可以根据自己的本征进行尝试.

PETSc has quite a few solvers that you can try out based on your eigenspectrum.

您可以检查是.萨阿德(Saad)关于这些求解器如何工作的书.

You can check Y. Saad's book on how these solvers work.

如果矩阵不是对称正定GMRES,则是一个不错的选择.

If your matrix is not symmetric positive definite GMRES is a good option.

这篇关于本征线性代数求解器似乎很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆