]> https://gitweb.dealii.org/ - dealii.git/commitdiff
SolverGMRES: Skip work if x is all zero
authorMartin Kronbichler <martin.kronbichler@rub.de>
Tue, 19 Mar 2024 20:51:11 +0000 (21:51 +0100)
committerMartin Kronbichler <martin.kronbichler@rub.de>
Tue, 19 Mar 2024 20:51:11 +0000 (21:51 +0100)
include/deal.II/lac/solver_gmres.h

index 7229f3ce9cc12dcf0e3480e9fadec720f448b87e..0b7abbf4a9559d7c20aa5a1ede774496b24d901a 100644 (file)
@@ -1840,14 +1840,25 @@ SolverGMRES<VectorType>::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<VectorType>::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);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.