C++ How do I solve very large system of sparse linear system

时间:2016-11-12 05:51:23

标签: c++ sparse-matrix linear-algebra eigen large-data

I am trying to solve a very large and sparse system of linear equations in C++. Currently, I am using BiCGSTAB from eigen. It works fine for small matrix, but it is taking just too much time for matrix of the size I need, which is 40804x40804 (It could be even larger in the future).

I have a very long script, but I simply used the following format:

SparseMatrix<double> sj(40804,40804);
VectorXd c_(40804), sf(40804);
sj.reserve(VectorXi::Constant(40804,36)); //This is a very good estimate of how many non zeros in each column
//...Fill in actual number in sj
sj.makeCompressed();
BiCGSTAB<SparseMatrix<double> > handler;
//...Fill in sj, only in the entries that have been initialized previously
handler.analyzePattern(sj)
handler.factorize(sj);
c_.setZero();
c_=handler.solve(sf);

This takes way too long! And yes, the solution does exist. Sparse function in matlab seems to handle this very well, but I need it in C++ in order to connect to a server.

I would really appreciate it you could help me!

1 个答案:

答案 0 :(得分:1)

您应该考虑使用其中一种高级稀疏直接求解器:CHOLMOD

稀疏直接求解器是计算分析中的基本工具,为几乎任何问题提供了一种非常通用的方法来获得高质量的结果。 CHOLMOD是稀疏Cholesky factorization的高性能库。

我保证这个包装可以帮到你。此外,CHOLMOD自2012年以来一直支持 GPU加速版本4.0.0。在SuiteSparse-4.3.1中,性能得到了进一步提高,为稀疏分解操作提供了3倍或更高的加速比。

如果您的矩阵是图表的表示形式,您还可以METIS结合使用CHOLMOD。这意味着您将能够在图形中执行partition / domainDecomposition,然后使用CHOLMOD进行并行求解。

SuiteSparse是一个强大的工具,支持线性(KLU)和直接求解器。

以下是GitHub linkUserGuideSuiteSparse's home page