7.3.2. Convergence Monitoring

Up: Contents Next: Checking Accuracy of Derivatives Previous: Convergence Tests

By default the SNES solvers run silently without displaying information about the iterations. The user can initiate monitoring with the command

   ierr = SNESSetMonitor(SNES snes,int (*mon)(SNES,int its,double norm,void* mctx), 
                         void *mctx); 
The routine, mon, indicates a user-defined monitoring routine, where its and mctx respectively denote the iteration number and an optional user-defined context for private data for the monitor routine. The argument norm is the function norm (or gradient norm for unconstrained minimization problems).

The routine set by SNESSetMonitor() is called once after every successful step computation within the nonlinear solver. Hence, the user can employ this routine for any application-specific computations that should be done after the solution update. The option -snes_monitor activates the default SNES monitor routine, SNESDefaultMonitor(), while -snes_xmonitor draws a simple line graph of the residual norm's convergence.

Once can cancel all hardwired monitoring routines for SNES at runtime with -snes_cancelmonitors.

As the Newton method converges so that the residual norm is small, say 10-10, many of the final digits printed with the -snes_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 -snes_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.

The routines

   ierr = SNESGetSolution(SNES snes,Vec *x); 
   ierr = SNESGetFunction(SNES snes,Vec *r); 
return the solution vector and function vector from a SNES context. These routines are useful, for instance, if the convergence test requires some property of the solution or function other than those passed with routine arguments.


Up: Contents Next: Checking Accuracy of Derivatives Previous: Convergence Tests