[petsc-users] setting correct tolerances for MG smoother CG at the finest level

Mark Adams mfadams at lbl.gov
Sun Sep 28 13:13:54 CDT 2025


Not sure why your "whole"solver does not have a coarse grid but this is
wrong:

KSP Object: (mg_coarse_) 1 MPI process
  type: cg
    variant HERMITIAN
  maximum iterations=100, initial guess is zero
  tolerances: relative=0.1, absolute=0.1, divergence=1e+30

The coarse grid has to be accurate. The defaults are a good place to start:
max_it=10.000, rtol=1e-5, atol=1e-30 (ish)


On Fri, Sep 26, 2025 at 3:21 PM Barry Smith <bsmith at petsc.dev> wrote:

>   Looks reasonable. Send the output running with
>
>    -ksp_monitor -mg_levels_ksp_monitor -ksp_converged_reason
> -mg_levels_ksp_converged_reason
>
> On Sep 26, 2025, at 1:19 PM, Moral Sanchez, Elena <
> Elena.Moral.Sanchez at ipp.mpg.de> wrote:
>
> Dear Barry,
>
> This is -ksp_view for the smoother at the finest level:
>
> KSP Object: (mg_levels_1_) 1 MPI process
>   type: cg
>     variant HERMITIAN
>   maximum iterations=10, nonzero initial guess
>   tolerances: relative=0.1, absolute=0.1, divergence=1e+30
>   left preconditioning
>   using UNPRECONDITIONED norm type for convergence test
> PC Object: (mg_levels_1_) 1 MPI process
>   type: none
>   linear system matrix = precond matrix:
>   Mat Object: 1 MPI process
>     type: python
>     rows=524, cols=524
>         Python: Solver_petsc.LeastSquaresOperator
>
> And at the coarsest level:
>
> KSP Object: (mg_coarse_) 1 MPI process
>   type: cg
>     variant HERMITIAN
>   maximum iterations=100, initial guess is zero
>   tolerances: relative=0.1, absolute=0.1, divergence=1e+30
>   left preconditioning
>   using UNPRECONDITIONED norm type for convergence test
> PC Object: (mg_coarse_) 1 MPI process
>   type: none
>   linear system matrix = precond matrix:
>   Mat Object: 1 MPI process
>     type: python
>     rows=344, cols=344
>         Python: Solver_petsc.LeastSquaresOperator
>
> And for the whole solver:
>
> KSP Object: 1 MPI process
>   type: cg
>     variant HERMITIAN
>   maximum iterations=100, nonzero initial guess
>   tolerances: relative=1e-08, absolute=1e-09, divergence=10000.
>   left preconditioning
>   using UNPRECONDITIONED norm type for convergence test
> PC Object: 1 MPI process
>   type: mg
>     type is MULTIPLICATIVE, levels=2 cycles=v
>       Cycles per PCApply=1
>       Not using Galerkin computed coarse grid matrices
>   Coarse grid solver -- level 0 -------------------------------
>     KSP Object: (mg_coarse_) 1 MPI process
>       type: cg
>         variant HERMITIAN
>       maximum iterations=100, initial guess is zero
>       tolerances: relative=0.1, absolute=0.1, divergence=1e+30
>       left preconditioning
>       using UNPRECONDITIONED norm type for convergence test
>     PC Object: (mg_coarse_) 1 MPI process
>       type: none
>       linear system matrix = precond matrix:
>       Mat Object: 1 MPI process
>         type: python
>         rows=344, cols=344
>             Python: Solver_petsc.LeastSquaresOperator
>   Down solver (pre-smoother) on level 1 -------------------------------
>     KSP Object: (mg_levels_1_) 1 MPI process
>       type: cg
>         variant HERMITIAN
>       maximum iterations=10, nonzero initial guess
>       tolerances: relative=0.1, absolute=0.1, divergence=1e+30
>       left preconditioning
>       using UNPRECONDITIONED norm type for convergence test
>     PC Object: (mg_levels_1_) 1 MPI process
>       type: none
>       linear system matrix = precond matrix:
>       Mat Object: 1 MPI process
>         type: python
>         rows=524, cols=524
>             Python: Solver_petsc.LeastSquaresOperator
>   Up solver (post-smoother) same as down solver (pre-smoother)
>   linear system matrix = precond matrix:
>   Mat Object: 1 MPI process
>     type: python
>     rows=524, cols=524
>         Python: Solver_petsc.LeastSquaresOperator
>
> Best,
> Elena
>
> ------------------------------
> *From:* Barry Smith <bsmith at petsc.dev>
> *Sent:* 26 September 2025 19:05:02
> *To:* Moral Sanchez, Elena
> *Cc:* petsc-users at mcs.anl.gov
> *Subject:* Re: [petsc-users] setting correct tolerances for MG smoother
> CG at the finest level
>
>
> Send the output using -ksp_view
>
> Normally one uses a fixed number of iterations of smoothing  on level with
> multigrid rather than a tolerance, but yes PETSc should respect such a
> tolerance.
>
> Barry
>
>
> On Sep 26, 2025, at 12:49 PM, Moral Sanchez, Elena <
> Elena.Moral.Sanchez at ipp.mpg.de> wrote:
>
> Hi,
> I am using multigrid (multiplicative) as a preconditioner with a V-cycle
> of two levels. At each level, I am setting CG as the smoother with certain
> tolerance.
>
> What I observe is that in the finest level the CG continues iterating
> after the residual norm reaches the tolerance (atol) and it only stops when
> reaching the maximum number of iterations at that level. At the coarsest
> level this does not occur and the CG stops when the tolerance is reached.
>
> I double-checked that the smoother at the finest level has the right
> tolerance. And I am using a Monitor function to track the residual.
>
> Do you know how to make the smoother at the finest level stop when
> reaching the tolerance?
>
> Cheers,
> Elena.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250928/16c178b4/attachment.html>


More information about the petsc-users mailing list