Actual source code: lsqr_monitor.c
petsc-3.9.2 2018-05-20
1: #include <petsc/private/kspimpl.h>
3: PetscErrorCode KSPMonitorLSQR(KSP solksp, PetscInt iter, PetscReal rnorm, void *ctx)
4: {
5: PetscInt mxiter; /* Maximum number of iterations */
6: PetscReal arnorm; /* The norm of the vector A.r */
7: PetscReal atol; /* Absolute convergence tolerance */
8: PetscReal dtol; /* Divergence tolerance */
9: PetscReal rtol; /* Relative convergence tolerance */
10: Vec x_sol;
11: PetscReal xnorm;
13: MPI_Comm comm;
16: PetscObjectGetComm((PetscObject)solksp,&comm);
17: KSPGetTolerances(solksp, &rtol, &atol, &dtol, &mxiter);
18: KSPLSQRGetArnorm(solksp, &arnorm,NULL,NULL);
19: KSPGetSolution(solksp, &x_sol);
20: VecNorm(x_sol, NORM_2, &xnorm);
22: if (iter % 100 == 0) {
23: PetscPrintf(comm, "Iteration Res norm Grad norm Upd norm\n");
24: }
25: if (iter <= 10 || iter >= mxiter - 10 || iter % 10 == 0) {
26: PetscPrintf(comm, "%10d %10.7e %10.7e %10.7e\n", iter, rnorm, arnorm, xnorm);
27: }
28: return(0);
29: }