<div dir="ltr"><div dir="ltr">On Sun, Jul 2, 2023 at 2:24 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:微软雅黑;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>