From: wolf Date: Thu, 5 Jul 2001 16:33:11 +0000 (+0000) Subject: Save one vmult in the common case that the input vector to the CG method is zero. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ad2447267852b58c74e54a62f67fb0bce93b187;p=dealii-svn.git 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 --- 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);