BiCGSTAB 调用猜测时迭代次数错误

发布于 2025-01-14 19:35:39 字数 1088 浏览 3 评论 0原文

我正在使用 C++ 和 Eigen 库来通过 BiCGSTAB 求解器求解系统。

#include <Eigen/IterativeLinearSolvers>

在代码中的某个时刻我初始化了矩阵A和rhs向量rhs

int N = domain.size();
Eigen::SparseMatrix<double, Eigen::RowMajor> M(N, N);
Eigen::VectorXd rhs(N);
rhs.setZero();
M.reserve(storage.supportSizes());

最终创建了求解器并解决了系统

        Eigen::BiCGSTAB<decltype(M), Eigen::IncompleteLUT<double>> solver;
        solver.setMaxIterations(300);
        solver.compute(M);
        auto sol = solver.solveWithGuess(rhs, guess);
        if (debug) {
            print(solver.iterations());
            print(solver.error());
        }

问题

上面代码的问题是输出不合理

solver.iterations() = 94414646480416;
solver.error() = 6.91858e-310;

即使初始猜测是零向量(这是 BiCGSTAB 的默认方式)。我必须在这里指出,解决系统所需的时间大约是(毫)秒,所以我很确定它没有进行 94414646480416 次迭代。

有谁知道当通过猜测获得解决方案时如何获得迭代次数?

I am using the c++ and Eigen library to solve a system with BiCGSTAB solver.

#include <Eigen/IterativeLinearSolvers>

At some point in the code I initialize the matrix A and rhs vector rhs

int N = domain.size();
Eigen::SparseMatrix<double, Eigen::RowMajor> M(N, N);
Eigen::VectorXd rhs(N);
rhs.setZero();
M.reserve(storage.supportSizes());

Finally solver is created and system is solved

        Eigen::BiCGSTAB<decltype(M), Eigen::IncompleteLUT<double>> solver;
        solver.setMaxIterations(300);
        solver.compute(M);
        auto sol = solver.solveWithGuess(rhs, guess);
        if (debug) {
            print(solver.iterations());
            print(solver.error());
        }

Problem

The problem with the above code is that the output is unreasonable

solver.iterations() = 94414646480416;
solver.error() = 6.91858e-310;

even when the initial guess is a vector of zeros (as is the defaulty way for BiCGSTAB). I must point out here, that the the time required to solve the system is a matter of (mili)seconds, so I am quite sure it did not do the 94414646480416 iterations.

Does anybody know how to get the number of iterations when solution is obtained with a guess?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文