]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Save one vmult in the common case that the input vector to the CG method is zero.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Jul 2001 16:33:11 +0000 (16:33 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Jul 2001 16:33:11 +0000 (16:33 +0000)
git-svn-id: https://svn.dealii.org/trunk@4823 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/solver_cg.h

index d0e5f76002ae6e89a7fdc750c46f5d6210fa2893..efacba01da1c9699ab363c36b318d97cb5d64f6f 100644 (file)
@@ -220,8 +220,16 @@ SolverCG<VECTOR>::solve (const MATRIX &A,
   int  it=0;
   double res,gh,alpha,beta;
 
-  A.vmult(g,x);
-  g.sadd(-1.,1.,b);
+                                  // compute residual. if vector is
+                                  // zero, then short-circuit the
+                                  // full computation
+  if (!x.all_zero())
+    {
+      A.vmult(g,x);
+      g.sadd(-1.,1.,b);
+    }
+  else
+    g = b;
   res = g.l2_norm();
   
   conv = control().check(0,res);

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.