<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">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><span><br></span></div><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;">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><!--😀--></body>
</html>