[petsc-users] Question about residue norm in PETSc

王赫萌 wanghemeng at 163.com
Sun Jul 2 00:47:14 CDT 2023


Dear PETSc Team,


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.


I calculated residue norm by myself with:
```
  PetscCall(VecNorm(b, NORM_2, &norm_b)); // (main.c, line 74)


  PetscCall(VecDuplicate(b, &u)); // (main.c, line 105)
  PetscCall(MatMult(A, x, u));
  PetscCall(VecAXPY(b, -1.0, u));
  PetscCall(VecNorm(b, NORM_2, &norm_delta));
```
and check the (norm_delta) / (norm_b). It seems not the `atol` which set by `KSPSetTolerances()`.
(I set atol as 1e-12, but got 5e-7 finally)
(options:  -ksp_type cg -pc_type gamg -ksp_converged_reason -ksp_norm_type unpreconditioned -ksp_monitor_true_residual)


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.


I will really really appreciated if someone can explain the calculation of `resid norm` in petsc. And where is my mistake.


To provide you with more context, here are the source code about my implementation. And the output of my test.


main.c
Main code of my program


mmio.h  mmloader.h
Headers for matrix read


Makefile
For compiling, same as sample provided


task.sh
A script for running program in `slurm`


slurm-4803840.out
Output of my test


Thank you very much for your time and attention. I greatly appreciate your support and look forward to hearing from you soon.
Best regards,
Hemeng Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.c
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0001.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Makefile
Type: application/octet-stream
Size: 818 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0002.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mmio.h
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0002.h>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mmloader.h
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0003.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: slurm-4803840.out
Type: application/octet-stream
Size: 13311 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: task.sh
Type: application/x-sh
Size: 585 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230702/71e517bb/attachment-0001.sh>


More information about the petsc-users mailing list