Actual source code: lsqr_monitor.c
1: #include "petscksp.h"
2: #include ../src/ksp/ksp/impls/lsqr/lsqr.h
5: PetscErrorCode KSPMonitorLSQR(KSP solksp, PetscInt iter, PetscReal rnorm, void *ctx)
6: {
7: PetscInt mxiter; /* Maximum number of iterations */
8: PetscReal arnorm; /* The norm of the vector A.r */
9: PetscReal atol; /* Absolute convergence tolerance */
10: PetscReal dtol; /* Divergence tolerance */
11: PetscReal rtol; /* Relative convergence tolerance */
12: Vec x_sol;
13: PetscReal rdum;
14: PetscReal xnorm;
15: PetscErrorCode ierr;
16: MPI_Comm comm;
17:
19: PetscObjectGetComm((PetscObject)solksp,&comm);
20: KSPGetTolerances( solksp, &rtol, &atol, &dtol, &mxiter );
21: KSPLSQRGetArnorm( solksp, &arnorm, &rdum, &rdum);
22: KSPGetSolution( solksp, &x_sol );
23: VecNorm( x_sol, NORM_2, &xnorm );
25: if (iter % 100 == 0){
26: PetscPrintf(comm, "Iteration Res norm Grad norm Upd norm\n");
27: }
28: if (iter <= 10 || iter >= mxiter - 10 || iter % 10 == 0){
29: PetscPrintf(comm, "%10d %10.7e %10.7e %10.7e\n", iter, rnorm , arnorm, xnorm );
30: }
31: return(0);
32: }