From 1ad2447267852b58c74e54a62f67fb0bce93b187 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 5 Jul 2001 16:33:11 +0000 Subject: [PATCH] Save one vmult in the common case that the input vector to the CG method is zero. git-svn-id: https://svn.dealii.org/trunk@4823 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/solver_cg.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/solver_cg.h b/deal.II/lac/include/lac/solver_cg.h index d0e5f76002..efacba01da 100644 --- a/deal.II/lac/include/lac/solver_cg.h +++ b/deal.II/lac/include/lac/solver_cg.h @@ -220,8 +220,16 @@ SolverCG::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); -- 2.39.5