[petsc-users] KSP solver iteration stop criteria

Barry Smith bsmith at mcs.anl.gov
Fri Feb 14 13:12:43 CST 2014


On Feb 14, 2014, at 1:07 PM, Danyang Su <danyang.su at gmail.com> wrote:

> Hi All,
> 
> Can I control KSP solver iteration by user defined criteria? I would like to check both preconditioned residual norm and true residual norm in every iteration, and force the solver to stop iteration if either criteria matches.
> 
> If using KSPSetConvergenceTest, can I get the true residual norm directly from a function

   Since it is not always available you need to compute it yourself.

> or shall I compute it in the user-defined convergence function:
> 
>      call KSPBuildSolution(ksp,PETSC_NULL_OBJECT,x,ierr)
>      call KSPGetRhs(ksp, b, ierr)
>      call KSPGetOperators(ksp,a,PETSC_NULL_OBJECT ,PETSC_NULL_OBJECT, ierr)
>      call MatMult(a, x, u, ierr)
>      call VecAXPY(u, -1.0d0, b, ierr)
>      call VecNormBegin(u, Norm_2, rnorm_true, ierr)
>      call VecNormEnd(u, Norm_2, rnorm_true, ierr)
> 
   But note that this process is rather expensive (this is why we don’t do it in our convergence tests). 

   Better to just use right preconditioning and then the compute norm is the true residual norm and you just test on that.

-ksp_norm_type unpreconditioned  -ksp_set_pc_side right 

Don’t include the -ksp_set_pc_side right if you are using CG.

   Barry


> Thanks and regards,
> 
> Danyang



More information about the petsc-users mailing list