From: Martin Kronbichler Date: Tue, 19 Mar 2024 20:51:11 +0000 (+0100) Subject: SolverGMRES: Skip work if x is all zero X-Git-Tag: v9.6.0-rc1~460^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f6fa80f275c32cfa1be0fdf688f7074c4d5c684;p=dealii.git SolverGMRES: Skip work if x is all zero --- 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);