<div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 8:45 AM 王赫萌 <<a href="mailto:wanghemeng@163.com">wanghemeng@163.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

    

<div><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6">
            <div><div>
        <font face="微软雅黑"><span style="line-height:1.6">Thank so much for your patience! I'm really </span>grateful<span style="line-height:1.6"> for that!</span></font></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><span><br></span></div><div><font face="微软雅黑"><span style="line-height:1.6">Could you </span>explain<span style="line-height:1.6"> the calculation of "<span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">1.31278e+06"</span></span></font></div><div><font face="微软雅黑"><span style="line-height:1.6"><span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">It appears that my calculation of this value is "<span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">18.0468"</span></span></span></font></div></div></div></div></blockquote><div><br></div><div><div>100 KSP unpreconditioned resid norm 1.312782529439e+06 true resid norm 1.312782529439e+06 ||r(i)||/||b|| 1.804684612214e+01</div><div>norm_delta 1312782.529439, norm_b 72743.044439<br>Norm of error 18.0468 iterations 100<br>Residue of error 1.31278e+06 iterations 100<br></div><div><br style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px"></div></div><div>Here norm_delta matches true resid norm, because they are both A x - b. What you are calling</div><div>"Norm of error" is actually the "Relative Residual" ||r_100|| / ||b|| = 18.0468, which is correct since</div><div>that is 1312782.529439 / 72743.044439. What you call "Residue of error" is the "Residual" just</div><div>as reported in the KSP monitor output.</div><div><br></div><div>  Thanks,</div><div><br></div><div>      Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6"><div><div><font face="微软雅黑"><span style="line-height:1.6"><span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline"><span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">Please forgive my ignorance. I just begin my learning on iterative method.</span></span></span></font></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><br></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6">Thank you so much for the reply!</div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><br></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6">Welcome to China if you have time! ^_^</div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6">
        <span>
            <br>
        </span>
    </div><div id="m_-6675005952295145098ntes-pcmac-signature" style="font-family:"";font-size:14px;line-height:1.6">
         
        <div style="font-size:14px;padding:0px;margin:0px">
            <div style="padding-bottom:6px;margin-bottom:10px;display:inline-block">
                        <a href="https://maas.mail.163.com/dashi-web-extend/html/proSignature.html?ftlId=1&name=%E7%8E%8B%E8%B5%AB%E8%90%8C&uid=wanghemeng%40163.com&iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fqiyelogo%2FdefaultAvatar.png&items=%5B%22wanghemeng%40163.com%22%5D" style="display:block;background:rgb(255,255,255);max-width:400px;padding:15px 0px 10px;text-decoration:none;outline:none" target="_blank"></a>
            </div>
        </div>
     </div></div>
        <div style="padding-top:1px;padding-bottom:1px">
  <div style="margin-top:2em;margin-bottom:1em;font-size:14px;line-height:1.25;color:rgb(120,120,122)">
    ---- Replied Message ----
  </div>
  <div style="margin-bottom:1em;font-size:12px;line-height:1.25;color:rgb(35,35,36);padding:0.5em 0.25em;border-radius:0.67em;background-color:rgb(240,240,240)">
    <table width="100%" cellpadding="0" cellspacing="9" border="0">
      <tbody><tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         From 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
            <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:knepley@gmail.com" target="_blank">Matthew Knepley<knepley@gmail.com>
            </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Date 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
        7/2/2023 20:32
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         To 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
         
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:wanghemeng@163.com" target="_blank">
            王赫萌<wanghemeng@163.com>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Cc 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:petsc-users@mcs.anl.gov" target="_blank">
            PETSc<petsc-users@mcs.anl.gov>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Subject 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
              Re: [petsc-users] Question about residue norm in PETSc
        </td>
      </tr>
    </tbody></table>
  </div>
<div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 8:19 AM 王赫萌 <<a href="mailto:wanghemeng@163.com" target="_blank">wanghemeng@163.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

    

<div>
            <div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6">
            <div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div>Here is the mat and rhs used in code! (May need to change the data path)</div><div><br></div><div>mat:</div><div></div><a href="https://studentcupeducn-my.sharepoint.com/:u:/g/personal/wanghemeng_student_cup_edu_cn/Ed76oGtC1ttDriZsObbPR74BCnDPUP8aicVXQEL4sO1AyQ?e=zeszik" target="_blank">https://studentcupeducn-my.sharepoint.com/:u:/g/personal/wanghemeng_student_cup_edu_cn/Ed76oGtC1ttDriZsObbPR74BCnDPUP8aicVXQEL4sO1AyQ?e=zeszik</a></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6">rhs:</div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><a href="https://studentcupeducn-my.sharepoint.com/:u:/g/personal/wanghemeng_student_cup_edu_cn/EdHRqWbzVmtIkAppOLL1UMIBM7tK7ws0gEASESGHuGC3yw?e=SMQSmY" target="_blank">https://studentcupeducn-my.sharepoint.com/:u:/g/personal/wanghemeng_student_cup_edu_cn/EdHRqWbzVmtIkAppOLL1UMIBM7tK7ws0gEASESGHuGC3yw?e=SMQSmY</a></div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div><br></div><div>I tried <span style="font-family:微软雅黑,宋体,"Sans Serif";line-height:22.4px">using<br></span><span style="color:rgb(0,0,0);font-family:微软雅黑,宋体,"Sans Serif";font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">PetscCall(VecAXPY(u, -1.0, b));</span></div><div>but is just as same as</div><div><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">PetscCall(VecAXPY(b, -1.0, u));</span></div><div><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline"><br></span></div><div><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">Thank you so much for that!!!</span></div></div></div></div></div></blockquote><div><br></div><div> 90 KSP unpreconditioned resid norm 9.749157899195e+05 true resid norm 9.749157899195e+05 ||r(i)||/||b|| 1.340218569960e+01<br> 91 KSP unpreconditioned resid norm 1.073123446417e+06 true resid norm 1.073123446417e+06 ||r(i)||/||b|| 1.475224820050e+01<br> 92 KSP unpreconditioned resid norm 1.170251286554e+06 true resid norm 1.170251286554e+06 ||r(i)||/||b|| 1.608746644557e+01<br> 93 KSP unpreconditioned resid norm 1.264719067990e+06 true resid norm 1.264719067990e+06 ||r(i)||/||b|| 1.738611681365e+01<br> 94 KSP unpreconditioned resid norm 1.329446257320e+06 true resid norm 1.329446257320e+06 ||r(i)||/||b|| 1.827592270272e+01<br> 95 KSP unpreconditioned resid norm 1.365944956372e+06 true resid norm 1.365944956372e+06 ||r(i)||/||b|| 1.877767100504e+01<br> 96 KSP unpreconditioned resid norm 1.369513563400e+06 true resid norm 1.369513563400e+06 ||r(i)||/||b|| 1.882672871297e+01<br> 97 KSP unpreconditioned resid norm 1.364905651654e+06 true resid norm 1.364905651654e+06 ||r(i)||/||b|| 1.876338366353e+01<br> 98 KSP unpreconditioned resid norm 1.352584030803e+06 true resid norm 1.352584030803e+06 ||r(i)||/||b|| 1.859399810996e+01<br> 99 KSP unpreconditioned resid norm 1.330589478009e+06 true resid norm 1.330589478009e+06 ||r(i)||/||b|| 1.829163857903e+01<br>100 KSP unpreconditioned resid norm 1.312782529439e+06 true resid norm 1.312782529439e+06 ||r(i)||/||b|| 1.804684612214e+01<br>Linear solve did not converge due to DIVERGED_ITS iterations 100<br>KSPSolve Time: 7579.364000 ms<br>norm_delta 1312782.529439, norm_b 72743.044439 <br>Norm of error 18.0468 iterations 100<br>Residue of error 1.31278e+06 iterations 100<br></div><div><br></div><div>I ran with</div><div><br></div><div>  -pc_type jacobi -ksp_max_it 100</div><div><br></div><div>because GAMG takes a long time to setup on my laptop. Those numbers match exactly.</div><div><br></div><div>   THanks,</div><div><br></div><div>     Matt</div><div><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><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6"><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">I'm such a beginner T_T</span></div><div id="m_-6675005952295145098m_-8410163716324109912ntes-pcmac-signature" style="font-family:""">
     </div></div>
        <div style="padding-top:1px;padding-bottom:1px">
  <div style="margin-top:2em;margin-bottom:1em;font-size:14px;line-height:1.25;color:rgb(120,120,122)">
    ---- Replied Message ----
  </div>
  <div style="margin-bottom:1em;font-size:12px;line-height:1.25;color:rgb(35,35,36);padding:0.5em 0.25em;border-radius:0.67em;background-color:rgb(240,240,240)">
    <table width="100%" cellpadding="0" cellspacing="9" border="0">
      <tbody><tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         From 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
            <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:knepley@gmail.com" target="_blank">Matthew Knepley<knepley@gmail.com>
            </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Date 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
        7/2/2023 20:10
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         To 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
         
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:wanghemeng@163.com" target="_blank">
            王赫萌<wanghemeng@163.com>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Cc 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:petsc-users@mcs.anl.gov" target="_blank">
            PETSc<petsc-users@mcs.anl.gov>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Subject 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
              Re: [petsc-users] Question about residue norm in PETSc
        </td>
      </tr>
    </tbody></table>
  </div>
<div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 8:05 AM Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 7:53 AM 王赫萌 <<a href="mailto:wanghemeng@163.com" target="_blank">wanghemeng@163.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

    

<div><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6">
            <div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div>Thanks for your reply!
</div><div>
</div><div>So sorry that I made a mistake in the description.
</div><div>
</div><div>I set the tolerances by:
</div><div>
</div><div><span style="background-color:rgb(233,233,233)">PetscCall(KSPSetTolerances(ksp, 1e-12, DBL_MIN, PETSC_DEFAULT, PETSC_DEFAULT));
</span></div><div>
</div><div>and got (by passing `-ksp_norm_type unpreconditioned -ksp_monitor_true_residual`)
</div><div>
</div><div><span style="background-color:rgb(233,233,233)">74 KSP unpreconditioned resid norm 7.256655641876e-08 true resid norm 7.256655641876e-08 ||r(i)||/||b|| 9.975738158726e-13
</span></div><div>
</div><div>I'm wondering why the ` ||r(i)||/||b||` is different with mine which calculated by:
</div><div>
</div><div>```
</div><div>  PetscCall(VecNorm(b, NORM_2, &norm_b)); // (main.c, line 74) (which is 72743.044439)
</div><div>
</div><div>  PetscCall(VecDuplicate(b, &u)); // (main.c, line 105)
</div><div>  PetscCall(MatMult(A, x, u));
</div><div>  PetscCall(VecAXPY(b, -1.0, u));
</div><div>  PetscCall(VecNorm(b, NORM_2, &norm_delta)); // (which is 0.039608)
</div><div>```
</div><div>
</div><div>and (norm_delta) / (norm_b) = <span style="background-color:rgb(233,233,233)">5.44496e-07</span> which is higher and different with the rtol I set (<span style="background-color:rgb(233,233,233)">1e-12</span>).
</div><div>
</div><div>Sorry again for the waste of your time. I would really appreciated if you could help me again!</div></div></div></div></blockquote><div><br></div><div>1) 7.256655641876e-08 / 72743.044439 = 9.975738158726e-13 so ||r_i||/||b|| is correct in the output</div><div><br></div><div>2) You are asking why you calculate a different residual? I will have to run your code.</div></div></div></blockquote><div><br></div><div>I built your code, but you did not send the matrix and rhs.</div><div><br></div><div>I suggest using</div><div><br></div>PetscCall(VecAXPY(u, -1.0, b));<br><div><br></div><div>instead so that you do not change b, and keep the residual in u.</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt  </div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:微软雅黑,Verdana,"Microsoft Yahei",SimSun,sans-serif;font-size:14px;line-height:1.6"><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div>
</div><div>
</div><div>Best regards!
</div><div>
</div><div>Hemeng Wang</div><div id="m_-6675005952295145098m_-8410163716324109912m_3582424377874080934m_-8237380491218595464ntes-pcmac-signature" style="font-family:"""><div style="font-size:14px;padding:0px;margin:0px"><div style="padding-bottom:6px;margin-bottom:10px;display:inline-block"><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline"><br></span></div></div><div style="font-size:14px;padding:0px;margin:0px"><div style="padding-bottom:6px;margin-bottom:10px;display:inline-block"><span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline"><br></span></div></div>
     </div></div>
        <div style="padding-top:1px;padding-bottom:1px">
  <div style="margin-top:2em;margin-bottom:1em;font-size:14px;line-height:1.25;color:rgb(120,120,122)">
    ---- Replied Message ----
  </div>
  <div style="margin-bottom:1em;font-size:12px;line-height:1.25;color:rgb(35,35,36);padding:0.5em 0.25em;border-radius:0.67em;background-color:rgb(240,240,240)">
    <table width="100%" cellpadding="0" cellspacing="9" border="0">
      <tbody><tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         From 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
            <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:knepley@gmail.com" target="_blank">Matthew Knepley<knepley@gmail.com>
            </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Date 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
        7/2/2023 18:51
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         To 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
         
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:wanghemeng@163.com" target="_blank">
            王赫萌<wanghemeng@163.com>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Cc 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
          <a style="color:rgb(48,97,242);text-decoration:none" href="mailto:petsc-users@mcs.anl.gov" target="_blank">
            petsc-users@mcs.anl.gov<petsc-users@mcs.anl.gov>
            
          </a>
        </td>
      </tr>
      <tr>
        <td valign="top" style="width:4.25em;font-size:12px;line-height:1.25;color:rgb(120,120,122)">
         Subject 
        </td>
        <td valign="top" style="font-size:12px;line-height:1.25;color:rgb(35,35,36);word-break:break-all">
              Re: [petsc-users] Question about residue norm in PETSc
        </td>
      </tr>
    </tbody></table>
  </div>
<div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 2:24 AM 王赫萌 <<a href="mailto:wanghemeng@163.com" target="_blank">wanghemeng@163.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

    

<div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div><span>Dear PETSc Team,
</span></div><div><span><br></span></div><div><span>
</span></div><div><span>Sorry to bother! My name is Hemeng Wang, and I am currently learning the use of PETSc software package. I am confused while calculating the norm of residue.
</span></div><div><span><br></span></div><div><span>
</span></div><div><span>I calculated residue norm by myself with:
</span></div><div><span>```
</span></div><div><span>  PetscCall(VecNorm(b, NORM_2, &norm_b)); // (<span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">main.c, </span>line 74)</span></div><div><span><br></span></div><div><span>  PetscCall(VecDuplicate(b, &u)); // (<span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">main.c, </span>line 105)
</span></div><div><span>  PetscCall(MatMult(A, x, u));
</span></div><div><span>  PetscCall(VecAXPY(b, -1.0, u));
</span></div><div><span>  PetscCall(VecNorm(b, NORM_2, &norm_delta));
</span></div><div><span>```
</span></div><div><span>and check the (norm_delta) / (norm_b). It seems not the `atol` which set by `KSPSetTolerances()`.
</span></div><div>(I set atol as 1e-12, but got 5e-7 finally)</div><div>(options:  -ksp_type cg -pc_type gamg -ksp_converged_reason -ksp_norm_type unpreconditioned -ksp_monitor_true_residual)</div></div></div></blockquote><div><br></div><div>If you are using the default convergence test, there is an absolute tolerance (atol) _and_ a relative tolerance (rtol). It seems likely you hit the relative tolerance. You can check this using</div><div><br></div><div>  -ksp_converged_reason</div><div><br></div><div>You could make rtol really small if you want to just see the atol</div><div><br></div><div>  -ksp_rtol 1e-20</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:微软雅黑;font-size:14px;line-height:1.6"><div><span>
</span></div><div><span>I also check the soure code of `KSPSolve_CG` in `petsc/src/ksp/ksp/impls/cg/cg.c`. And could not figure out where is the difference.
</span></div><div><span><br></span></div><div><span>
</span></div><div><span>I will really really appreciated if someone can explain the calculation of `resid norm` in petsc. And where is my mistake.</span></div><div><span><br></span></div><div><span>
</span></div><div><span>To provide you with more context, here are the source code about my implementation. And the output of my test.</span></div><div><span>
</span></div><div><span><br></span></div><div><span>main.c</span></div><div>Main code of my program</div><div><br></div><div>mmio.h  mmloader.h</div><div>Headers for matrix read</div><div><br></div><div>Makefile</div><div>For compiling, same as sample provided</div><div><br></div><div>task.sh</div><div>A script for running program in `slurm`</div><div><br></div><div>slurm-4803840.out</div><div>Output of my <span style="color:rgb(0,0,0);font-family:微软雅黑;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:22.4px;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline">test</span></div><div><br></div><div>Thank you very much for your time and attention. I greatly appreciate your support and look forward to hearing from you soon.
</div><div>
</div><div>Best regards,</div><div>Hemeng Wang</div><div><br></div></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div></div></div></div>
        </div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>