6.3.3. Convergence Monitoring

Up: Contents Next: Understanding the Operator's Spectrum Previous: Convergence Tests

By default, the Krylov solvers run silently without displaying information about the iterations. The user can indicate that the norms of the residuals should be displayed by using -ksp_monitor within the options database. To display the residual norms in a graphical window (running under X Windows), one should use -ksp_xmonitor [x,y,w,h], where either all or none of the options must be specified. Application programmers can also provide their own routines to perform the monitoring by using the command

   ierr = KSPSetMonitor(KSP ksp,int (*mon)(KSP ksp,int it,double rnorm,void *ctx), 
                        void *ctx); 
The final routine argument, ctx, is an optional context for private data for the user-defined monitoring routine, mon. Other mon routine arguments are the iteration number ( it) and the residual's l2 norm ( rnorm). A helpful routine within user-defined monitors is PetscObjectGetComm((PetscObject)ksp,MPI_Comm *comm), which returns in comm the MPI communicator for the KSP context. See section Writing PETSc Programs for more discussion of the use of MPI communicators within PETSc.

Several monitoring routines are supplied with PETSc, including

   ierr = KSPDefaultMonitor(KSP,int,double, void *); 
   ierr = KSPSingularValueMonitor(KSP,int,double, void *); 
   ierr = KSPTrueMonitor(KSP,int,double, void *); 
The default monitor simply prints an estimate of the l2-norm of the residual at each iteration. The routine KSPSingularValueMonitor() is appropriate only for use with the conjugate gradient method or GMRES, since it prints estimates of the extreme singular values of the preconditioned operator at each iteration. Since KSPTrueMonitor() prints the true residual at each iteration by actually computing the residual using the formula r = b - Ax, the routine is slow and should be used only for testing or convergence studies, not for timing. These monitors may be accessed with the command line options -ksp_monitor, -ksp_singmonitor, and -ksp_truemonitor. .

To employ the default graphical monitor, one should use the commands

   DrawLG lg; 
   ierr = KSPLGMonitorCreate(char *display,char *title,int x,int y,int w,int h,DrawLG *lg); 
   ierr = KSPSetMonitor(KSP ksp,KSPLGMonitor,(void *)lg); 
When no longer needed, the line graph should be destroyed with the command
   ierr = KSPLGMonitorDestroy(DrawLG lg); 
The user can change aspects of the graphs with the DrawLG*() and DrawAxis*() routines. One can also access this functionality from the options database with the command -ksp_xmonitor [x,y,w,h]. Where x, y, w, h are the optional location and size of the window.

Once can cancel all hardwired monitoring routines for KSP at runtime with -ksp_cancelmonitors.

As the Krylov method converges so that the residual norm is small, say 10-10 many of the final digits printed with the -ksp_monitor option are meaningless. Worse, they are different on different machines; due to different round-off rules used by, say, the IBM RS6000 and the Sun Sparc. This makes testing between different machines difficult. The option -ksp_smonitor causes PETSc to print fewer of the digits of the residual norm as it gets smaller; thus on most of the machines it will always print the same numbers making cross processor testing easier.


Up: Contents Next: Understanding the Operator's Spectrum Previous: Convergence Tests