【发布时间】:2017-03-26 09:25:36
【问题描述】:
我正在尝试用 C++ 求解一个非常大且稀疏的线性方程组。目前,我正在使用来自 eigen 的 BiCGSTAB。它适用于小矩阵,但对于我需要的大小为 40804x40804 的矩阵(未来可能更大)花费了太多时间。
我有一个很长的脚本,但我只是使用了以下格式:
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);
这需要的时间太长了!是的,解决方案确实存在。 matlab 中的稀疏函数似乎可以很好地处理这个问题,但我需要在 C++ 中使用它才能连接到服务器。
如果你能帮助我,我将不胜感激!
【问题讨论】:
-
如果 matlab 为您做得好,为什么不在 c++ 中使用它。 Link
-
如果连接到服务器至关重要,也许你应该尝试使用 pari/gp...
-
确保在编译器优化开启的情况下进行编译,然后您也可以尝试使用像
Eigen::SparseLU这样的直接求解器(只需将BiCGSTAB替换为SparseLU)或使用IncompleteLUTBICGSTAB 中的预处理器。
标签: c++ sparse-matrix linear-algebra eigen large-data