本征和并行化对共轭梯度没有影响.前提条件也失败 [英] Eigen and parallellization makes no difference for conjugate gradient. Precondition also fails
问题描述
这与此问题.今天,我对共轭梯度进行了一些实验,特别是对max_iterations
和tolerance
进行了实验.它更快但不够快.根据文档,在编译中添加-fopenmp
应该足以启用multi-threading
.
This is related to this question. I have today experimented a bit with Conjugate Gradient, in particular I experimented with max_iterations
and tolerance
. It is faster but not fast enough. According to the documentation it should be enough to add -fopenmp
in the compilation to enable multi-threading
.
我已经同时使用
`omp_set_num_threads(nbrThreads);
Eigen::setNbThreads(nbrThreads);`
使用5个线程或1个线程在时间上没有区别,我认为这有点奇怪.
It makes no difference in time if I use 5 threads or 1 thread, and that I think is a bit strange.
第二,使用pre-conditoning
加快解决方案的另一种方法.当我尝试做时:
Secondly, another way to speed up the solution using pre-conditoning
. When I try to do:
Eigen::ConjugateGradient<Eigen::SparseMatrix<float>, Eigen::Lower, Eigen::IncompleteCholesky<float>> cg;
我得到了错误:
void Eigen::IncompleteCholesky<Scalar, _UpLo, _OrderingType>::_solve_impl(const Rhs&, Dest&) const [with Rhs = Eigen::Matr
ix<float, -1, 1>; Dest = Eigen::Matrix<float, -1, 1>; Scalar = float; int _UpLo = 1; _OrderingType = Eigen::AMDOrdering<int>]: Assertion `m_factorizationIsOk && "factorize() should be called first"' failed.
考虑到Eigen::SimplicialLDLT
是Cholesky因式分解的,那么不完全也应该起作用?
Given that Eigen::SimplicialLDLT
works which is a Cholesky factorization, then the incomplete should also work?
这是我叫cg的方式:
Here is how I call cg:
Eigen::ConjugateGradient<Eigen::SparseMatrix<float>, Eigen::Lower, Eigen::IncompleteCholesky<float>> cg;
cg.setTolerance(0.01);
cg.setMaxIterations(50);
cg.analyzePattern(A_tot);
cg.compute(A_tot);
Eigen::VectorXf opt = cg.solveWithGuess(b_tot, rho_current);
实际上,当您在此处了解有关IterativeSolvers的信息时,则未列出IncompleteCholesky
.尽管在此处中定义了.
Actually when you read about IterativeSolvers here, then IncompleteCholesky
is not listed. Although IncompleCholesky is defined here.
推荐答案
如文档中所述,您需要存储完整的矩阵(上下三角形部分),并将Lower|Upper
传递给ConjugateGradient
以获得与cg多线程.
As explained in the documentation, you need to store the full matrix (both upper and lower triangular part), and pass Lower|Upper
to ConjugateGradient
to get multi-threading with cg.
这篇关于本征和并行化对共轭梯度没有影响.前提条件也失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!