From 9f6fa80f275c32cfa1be0fdf688f7074c4d5c684 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 19 Mar 2024 21:51:11 +0100 Subject: [PATCH] SolverGMRES: Skip work if x is all zero --- include/deal.II/lac/solver_gmres.h | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/include/deal.II/lac/solver_gmres.h b/include/deal.II/lac/solver_gmres.h index 7229f3ce9c..0b7abbf4a9 100644 --- a/include/deal.II/lac/solver_gmres.h +++ b/include/deal.II/lac/solver_gmres.h @@ -1840,14 +1840,25 @@ SolverGMRES::solve(const MatrixType &A, if (left_precondition) { - A.vmult(p, x); - p.sadd(-1., 1., b); - preconditioner.vmult(v, p); + // if the vector is zero, bypass the full computation + if (accumulated_iterations == 0 && x.all_zero()) + preconditioner.vmult(v, b); + else + { + A.vmult(p, x); + p.sadd(-1., 1., b); + preconditioner.vmult(v, p); + } } else { - A.vmult(v, x); - v.sadd(-1., 1., b); + if (accumulated_iterations == 0 && x.all_zero()) + v = b; + else + { + A.vmult(v, x); + v.sadd(-1., 1., b); + } } const double norm_v = @@ -2165,8 +2176,13 @@ SolverFGMRES::solve(const MatrixType &A, do { - A.vmult(v(0, x), x); - v[0].sadd(-1., 1., b); + if (accumulated_iterations == 0 && x.all_zero()) + v(0, x) = b; + else + { + A.vmult(v(0, x), x); + v[0].sadd(-1., 1., b); + } res = arnoldi_process.orthonormalize_nth_vector(0, v); iteration_state = this->iteration_status(accumulated_iterations, res, x); -- 2.39.5