<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p></p>
<div>Hi, I doubled the system size and changed the tolerances just to show a better example of the problem. This is the output of the callbacks in the first iteration:<br>
    CG Iter 0/1 | res = 2.25e+00/1.00e-09 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 0/15 | res = 2.25e+00/1.00e-01 | 0.3 s<br>
        MG lvl 0 (s=884): CG Iter 1/15 | res = 1.43e+00/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 2/15 | res = 1.17e+00/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 3/15 | res = 1.32e+00/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 4/15 | res = 5.01e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 5/15 | res = 3.57e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 6/15 | res = 2.49e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 7/15 | res = 3.04e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 8/15 | res = 2.78e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 9/15 | res = 1.68e-01/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 10/15 | res = 1.21e-01/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 11/15 | res = 9.45e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 12/15 | res = 8.31e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 13/15 | res = 5.47e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 14/15 | res = 4.36e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 15/15 | res = 5.08e-02/1.00e-01 | 0.1 s<br>
        ConvergedReason MG lvl 0: 4<br>
        MG lvl -1 (s=524): CG Iter 0/15 | res = 8.15e-02/1.00e-01 | 3.0 s<br>
        ConvergedReason MG lvl -1: 3<br>
        MG lvl 0 (s=884): CG Iter 0/15 | res = 5.08e-02/1.00e-01 | 0.3 s<br>
        MG lvl 0 (s=884): CG Iter 1/15 | res = 2.93e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 2/15 | res = 3.26e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 3/15 | res = 4.14e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 4/15 | res = 4.82e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 5/15 | res = 3.20e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 6/15 | res = 3.46e-02/1.00e-01 | 0.3 s<br>
        MG lvl 0 (s=884): CG Iter 7/15 | res = 3.41e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 8/15 | res = 4.69e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 9/15 | res = 3.37e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 10/15 | res = 4.07e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 11/15 | res = 2.66e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 12/15 | res = 2.83e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 13/15 | res = 2.98e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 14/15 | res = 3.53e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 15/15 | res = 2.33e-02/1.00e-01 | 0.2 s<br>
        ConvergedReason MG lvl 0: 4<br>
    CG Iter 1/1 | res = 2.42e-02/1.00e-09 | 5.6 s<br>
        MG lvl 0 (s=884): CG Iter 0/15 | res = 2.42e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 1/15 | res = 1.76e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 2/15 | res = 1.40e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 3/15 | res = 1.42e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 4/15 | res = 1.62e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 5/15 | res = 1.35e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 6/15 | res = 1.39e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 7/15 | res = 1.51e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 8/15 | res = 1.28e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 9/15 | res = 1.24e-02/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 10/15 | res = 9.59e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 11/15 | res = 9.02e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 12/15 | res = 1.19e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 13/15 | res = 1.08e-02/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 14/15 | res = 8.19e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 15/15 | res = 7.61e-03/1.00e-01 | 0.1 s<br>
        ConvergedReason MG lvl 0: 4<br>
        MG lvl -1 (s=524): CG Iter 0/15 | res = 1.38e-02/1.00e-01 | 5.2 s<br>
        ConvergedReason MG lvl -1: 3<br>
        MG lvl 0 (s=884): CG Iter 0/15 | res = 7.61e-03/1.00e-01 | 0.2 s<br>
        MG lvl 0 (s=884): CG Iter 1/15 | res = 5.62e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 2/15 | res = 6.64e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 3/15 | res = 8.71e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 4/15 | res = 6.40e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 5/15 | res = 7.23e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 6/15 | res = 6.20e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 7/15 | res = 7.04e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 8/15 | res = 7.19e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 9/15 | res = 6.35e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 10/15 | res = 7.31e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 11/15 | res = 6.64e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 12/15 | res = 7.24e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 13/15 | res = 4.97e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 14/15 | res = 5.36e-03/1.00e-01 | 0.1 s<br>
        MG lvl 0 (s=884): CG Iter 15/15 | res = 5.84e-03/1.00e-01 | 0.1 s<br>
        ConvergedReason MG lvl 0: 4    <br>
    CG ConvergedReason: -3 <br>
<br>
For completeness, I add here the -ksp_view of the whole solver:<br>
    KSP Object: 1 MPI process<br>
      type: cg<br>
        variant HERMITIAN<br>
      maximum iterations=1, nonzero initial guess<br>
      tolerances: relative=1e-08, absolute=1e-09, divergence=10000.<br>
      left preconditioning<br>
      using UNPRECONDITIONED norm type for convergence test<br>
    PC Object: 1 MPI process<br>
      type: mg<br>
        type is MULTIPLICATIVE, levels=2 cycles=v<br>
          Cycles per PCApply=1<br>
          Not using Galerkin computed coarse grid matrices<br>
      Coarse grid solver -- level 0 -------------------------------<br>
        KSP Object: (mg_coarse_) 1 MPI process<br>
          type: cg<br>
        variant HERMITIAN<br>
          maximum iterations=15, nonzero initial guess<br>
          tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
          left preconditioning<br>
          using UNPRECONDITIONED norm type for convergence test<br>
        PC Object: (mg_coarse_) 1 MPI process<br>
          type: none<br>
          linear system matrix = precond matrix:<br>
          Mat Object: 1 MPI process<br>
        type: python<br>
        rows=524, cols=524<br>
            Python: Solver_petsc.LeastSquaresOperator<br>
      Down solver (pre-smoother) on level 1 -------------------------------<br>
        KSP Object: (mg_levels_1_) 1 MPI process<br>
          type: cg<br>
        variant HERMITIAN<br>
          maximum iterations=15, nonzero initial guess<br>
          tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
          left preconditioning<br>
          using UNPRECONDITIONED norm type for convergence test<br>
        PC Object: (mg_levels_1_) 1 MPI process<br>
          type: none<br>
          linear system matrix = precond matrix:<br>
          Mat Object: 1 MPI process<br>
        type: python<br>
        rows=884, cols=884<br>
            Python: Solver_petsc.LeastSquaresOperator<br>
      Up solver (post-smoother) same as down solver (pre-smoother)<br>
      linear system matrix = precond matrix:<br>
      Mat Object: 1 MPI process<br>
        type: python<br>
        rows=884, cols=884<br>
        Python: Solver_petsc.LeastSquaresOperator<br>
        <br>
Regarding Mark's Email: What do you mean with "the whole solver doesn't have a coarse grid"? I am using my own Restriction and Interpolation operators.
<br>
Thanks for the help,<br>
Elena</div>
<br>
<p></p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Mark Adams <mfadams@lbl.gov><br>
<b>Sent:</b> 28 September 2025 20:13:54<br>
<b>To:</b> Barry Smith<br>
<b>Cc:</b> Moral Sanchez, Elena; petsc-users<br>
<b>Subject:</b> Re: [petsc-users] setting correct tolerances for MG smoother CG at the finest level</font>
<div> </div>
</div>
<div>
<div dir="ltr">Not sure why your "whole"solver does not have a coarse grid but this is wrong:
<div><br>
</div>
<div>
<blockquote type="cite">
<div>
<div id="m_5159186700595764030divtagdefaultwrapper" dir="ltr" style="font-size:12pt;font-family:Calibri,Helvetica,sans-serif">
<div>
<blockquote>
<div>KSP Object: (mg_coarse_) 1 MPI process<br>
  type: cg<br>
    variant HERMITIAN<br>
  maximum iterations=100, initial guess is zero<br>
  tolerances: relative=0.1, absolute=0.1, divergence=1e+30</div>
<div><br>
</div>
<div>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)</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
<br>
<div class="gmail_quote gmail_quote_container">
<div dir="ltr" class="gmail_attr">On Fri, Sep 26, 2025 at 3:21 PM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>  Looks reasonable. Send the output running with 
<div><br>
</div>
<div>   -ksp_monitor -mg_levels_ksp_monitor -ksp_converged_reason -mg_levels_ksp_converged_reason<br id="m_5159186700595764030lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Sep 26, 2025, at 1:19 PM, Moral Sanchez, Elena <<a href="mailto:Elena.Moral.Sanchez@ipp.mpg.de" target="_blank">Elena.Moral.Sanchez@ipp.mpg.de</a>> wrote:</div>
<br>
<div>
<div id="m_5159186700595764030divtagdefaultwrapper" dir="ltr" style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-size:12pt;font-family:Calibri,Helvetica,sans-serif">
<div style="margin-top:0px;margin-bottom:0px">Dear Barry,</div>
<div style="margin-top:0px;margin-bottom:0px"><br>
</div>
<div style="margin-top:0px;margin-bottom:0px">This is -ksp_view for the smoother at the finest level:</div>
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>
<blockquote>KSP Object: (mg_levels_1_) 1 MPI process<br>
  type: cg<br>
    variant HERMITIAN<br>
  maximum iterations=10, nonzero initial guess<br>
  tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
  left preconditioning<br>
  using UNPRECONDITIONED norm type for convergence test<br>
PC Object: (mg_levels_1_) 1 MPI process<br>
  type: none<br>
  linear system matrix = precond matrix:<br>
  Mat Object: 1 MPI process<br>
    type: python<br>
    rows=524, cols=524<br>
        Python: Solver_petsc.LeastSquaresOperator<br>
</blockquote>
And at the coarsest level:<br>
<blockquote>
<div>KSP Object: (mg_coarse_) 1 MPI process<br>
  type: cg<br>
    variant HERMITIAN<br>
  maximum iterations=100, initial guess is zero<br>
  tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
  left preconditioning<br>
  using UNPRECONDITIONED norm type for convergence test<br>
PC Object: (mg_coarse_) 1 MPI process<br>
  type: none<br>
  linear system matrix = precond matrix:<br>
  Mat Object: 1 MPI process<br>
    type: python<br>
    rows=344, cols=344<br>
        Python: Solver_petsc.LeastSquaresOperator</div>
</blockquote>
And for the whole solver:</div>
<div>
<blockquote>
<div>KSP Object: 1 MPI process<br>
  type: cg<br>
    variant HERMITIAN<br>
  maximum iterations=100, nonzero initial guess<br>
  tolerances: relative=1e-08, absolute=1e-09, divergence=10000.<br>
  left preconditioning<br>
  using UNPRECONDITIONED norm type for convergence test<br>
PC Object: 1 MPI process<br>
  type: mg<br>
    type is MULTIPLICATIVE, levels=2 cycles=v<br>
      Cycles per PCApply=1<br>
      Not using Galerkin computed coarse grid matrices<br>
  Coarse grid solver -- level 0 -------------------------------<br>
    KSP Object: (mg_coarse_) 1 MPI process<br>
      type: cg<br>
        variant HERMITIAN<br>
      maximum iterations=100, initial guess is zero<br>
      tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
      left preconditioning<br>
      using UNPRECONDITIONED norm type for convergence test<br>
    PC Object: (mg_coarse_) 1 MPI process<br>
      type: none<br>
      linear system matrix = precond matrix:<br>
      Mat Object: 1 MPI process<br>
        type: python<br>
        rows=344, cols=344<br>
            Python: Solver_petsc.LeastSquaresOperator<br>
  Down solver (pre-smoother) on level 1 -------------------------------<br>
    KSP Object: (mg_levels_1_) 1 MPI process<br>
      type: cg<br>
        variant HERMITIAN<br>
      maximum iterations=10, nonzero initial guess<br>
      tolerances: relative=0.1, absolute=0.1, divergence=1e+30<br>
      left preconditioning<br>
      using UNPRECONDITIONED norm type for convergence test<br>
    PC Object: (mg_levels_1_) 1 MPI process<br>
      type: none<br>
      linear system matrix = precond matrix:<br>
      Mat Object: 1 MPI process<br>
        type: python<br>
        rows=524, cols=524<br>
            Python: Solver_petsc.LeastSquaresOperator<br>
  Up solver (post-smoother) same as down solver (pre-smoother)<br>
  linear system matrix = precond matrix:<br>
  Mat Object: 1 MPI process<br>
    type: python<br>
    rows=524, cols=524<br>
        Python: Solver_petsc.LeastSquaresOperator</div>
</blockquote>
Best,</div>
<div>Elena</div>
<br>
<p style="margin-top:0px;margin-bottom:0px"></p>
</div>
<hr style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;display:inline-block;width:1043.69px">
<span style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline"></span>
<div id="m_5159186700595764030divRplyFwdMsg" dir="ltr" style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<font face="Calibri, sans-serif" style="font-size:11pt"><b>From:</b><span> </span>Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>><br>
<b>Sent:</b><span> </span>26 September 2025 19:05:02<br>
<b>To:</b><span> </span>Moral Sanchez, Elena<br>
<b>Cc:</b><span> </span><a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
<b>Subject:</b><span> </span>Re: [petsc-users] setting correct tolerances for MG smoother CG at the finest level</font>
<div> </div>
</div>
<div style="font-family:Helvetica;font-size:18px;font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
  
<div>Send the output using -ksp_view </div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Barry</div>
<div><br id="m_5159186700595764030lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On Sep 26, 2025, at 12:49 PM, Moral Sanchez, Elena <<a href="mailto:Elena.Moral.Sanchez@ipp.mpg.de" target="_blank">Elena.Moral.Sanchez@ipp.mpg.de</a>> wrote:</div>
<br>
<div>
<div id="m_5159186700595764030divtagdefaultwrapper" dir="ltr" style="font-style:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;font-size:12pt;font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0px;margin-bottom:0px"></p>
<div>Hi, <br>
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.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Do you know how to make the smoother at the finest level stop when reaching the tolerance?<br>
<br>
Cheers,<br>
Elena.</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>