Date: 2016-07-24T17:06:56+00:00

Actual source code: lsqr_monitor.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      1: #include <petscksp.h>
      2: #include <../src/ksp/ksp/impls/lsqr/lsqr.h>
      3: extern PetscErrorCode  KSPLSQRGetArnorm(KSP,PetscReal*,PetscReal*,PetscReal*);

      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      xnorm;
     15:   MPI_Comm       comm;

     18:   PetscObjectGetComm((PetscObject)solksp,&comm);
     19:   KSPGetTolerances(solksp, &rtol, &atol, &dtol, &mxiter);
     20:   KSPLSQRGetArnorm(solksp, &arnorm,NULL,NULL);
     21:   KSPGetSolution(solksp, &x_sol);
     22:   VecNorm(x_sol, NORM_2, &xnorm);

     24:   if (iter % 100 == 0) {
     25:     PetscPrintf(comm, "Iteration  Res norm      Grad norm     Upd norm\n");
     26:   }
     27:   if (iter <= 10 || iter >= mxiter - 10 || iter % 10 == 0) {
     28:     PetscPrintf(comm, "%10d %10.7e %10.7e %10.7e\n", iter, rnorm, arnorm, xnorm);
     29:   }
     30:   return(0);
     31: }