Hi Everyone<div><br></div><div>I have a small suggestion for the KSPRichardson implementation. I often use a KSPRichardson object to perform a small number (2-4) applications of a preconditioner (Additive Schwartz for example). Since I'm using a fixed number of iterations, the object uses KSP_NORM_NONE to save the vecNorm. </div>
<div><br></div><div>Near the end of the function KSPSolve_Richardson, (line 138 according to the current docs, link below), the new residual is evaluated. However, for the last iteration, when using KSP_NORM_NONE, the last matMult and VecAYPX is not necessary. This results in additional unnecessary matMults(). In one system I'm solving, this adds approximately 20% to the computation cost. (30 secs -> 36 secs)</div>
<div><br></div><div>I think the following code should work:</div><div><div> if (ksp->its < maxit || ksp->normtype != KSP_NORM_NONE){</div><div> ierr = KSP_MatMult(ksp,Amat,x,r);CHKERRQ(ierr); /* r <- b - Ax */</div>
<div> ierr = VecAYPX(r,-1.0,b);CHKERRQ(ierr);</div><div> }</div></div><div><br></div><div>Also, it makes the degenerate case of 1 iteration have same cost as if the KSPRichardson wasn't there. </div><div><br>
</div><div>Hopefully this is useful.</div><div><br></div><div>Gaetan Kenway</div><div><br></div><div>Link to source code:</div><div><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/impls/rich/rich.c.html#KSPRICHARDSON">http://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/impls/rich/rich.c.html#KSPRICHARDSON</a></div>
<div><br></div>