LCOV - code coverage report
Current view: top level - lme/interface - lmemon.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 36 66 54.5 %
Date: 2019-09-16 06:01:52 Functions: 4 7 57.1 %

          Line data    Source code
       1             : /*
       2             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       3             :    SLEPc - Scalable Library for Eigenvalue Problem Computations
       4             :    Copyright (c) 2002-2019, Universitat Politecnica de Valencia, Spain
       5             : 
       6             :    This file is part of SLEPc.
       7             :    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
       8             :    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       9             : */
      10             : /*
      11             :    LME routines related to monitors
      12             : */
      13             : 
      14             : #include <slepc/private/lmeimpl.h>   /*I "slepclme.h" I*/
      15             : #include <petscdraw.h>
      16             : 
      17             : /*
      18             :    Runs the user provided monitor routines, if any.
      19             : */
      20          16 : PetscErrorCode LMEMonitor(LME lme,PetscInt it,PetscReal errest)
      21             : {
      22             :   PetscErrorCode ierr;
      23          16 :   PetscInt       i,n = lme->numbermonitors;
      24             : 
      25          16 :   PetscFunctionBegin;
      26           8 :   for (i=0;i<n;i++) {
      27           8 :     ierr = (*lme->monitor[i])(lme,it,errest,lme->monitorcontext[i]);CHKERRQ(ierr);
      28             :   }
      29          16 :   PetscFunctionReturn(0);
      30             : }
      31             : 
      32             : /*@C
      33             :    LMEMonitorSet - Sets an ADDITIONAL function to be called at every
      34             :    iteration to monitor convergence.
      35             : 
      36             :    Logically Collective on lme
      37             : 
      38             :    Input Parameters:
      39             : +  lme     - linear matrix equation solver context obtained from LMECreate()
      40             : .  monitor - pointer to function (if this is NULL, it turns off monitoring)
      41             : .  mctx    - [optional] context for private data for the
      42             :              monitor routine (use NULL if no context is desired)
      43             : -  monitordestroy - [optional] routine that frees monitor context (may be NULL)
      44             : 
      45             :    Calling Sequence of monitor:
      46             : $   monitor(LME lme,int its,PetscReal errest,void *mctx)
      47             : 
      48             : +  lme    - linear matrix equation solver context obtained from LMECreate()
      49             : .  its    - iteration number
      50             : .  errest - error estimate
      51             : -  mctx   - optional monitoring context, as set by LMEMonitorSet()
      52             : 
      53             :    Options Database Keys:
      54             : +    -lme_monitor        - print the error estimate
      55             : .    -lme_monitor_lg     - sets line graph monitor for the error estimate
      56             : -    -lme_monitor_cancel - cancels all monitors that have been hardwired into
      57             :       a code by calls to LMEMonitorSet(), but does not cancel those set via
      58             :       the options database.
      59             : 
      60             :    Notes:
      61             :    Several different monitoring routines may be set by calling
      62             :    LMEMonitorSet() multiple times; all will be called in the
      63             :    order in which they were set.
      64             : 
      65             :    Level: intermediate
      66             : 
      67             : .seealso: LMEMonitorCancel()
      68             : @*/
      69           4 : PetscErrorCode LMEMonitorSet(LME lme,PetscErrorCode (*monitor)(LME,PetscInt,PetscReal,void*),void *mctx,PetscErrorCode (*monitordestroy)(void**))
      70             : {
      71           4 :   PetscFunctionBegin;
      72           4 :   PetscValidHeaderSpecific(lme,LME_CLASSID,1);
      73           4 :   if (lme->numbermonitors >= MAXLMEMONITORS) SETERRQ(PetscObjectComm((PetscObject)lme),PETSC_ERR_ARG_OUTOFRANGE,"Too many LME monitors set");
      74           4 :   lme->monitor[lme->numbermonitors]           = monitor;
      75           4 :   lme->monitorcontext[lme->numbermonitors]    = (void*)mctx;
      76           4 :   lme->monitordestroy[lme->numbermonitors++]  = monitordestroy;
      77           4 :   PetscFunctionReturn(0);
      78             : }
      79             : 
      80             : /*@
      81             :    LMEMonitorCancel - Clears all monitors for an LME object.
      82             : 
      83             :    Logically Collective on lme
      84             : 
      85             :    Input Parameters:
      86             : .  lme - linear matrix equation solver context obtained from LMECreate()
      87             : 
      88             :    Options Database Key:
      89             : .    -lme_monitor_cancel - Cancels all monitors that have been hardwired
      90             :       into a code by calls to LMEMonitorSet(),
      91             :       but does not cancel those set via the options database.
      92             : 
      93             :    Level: intermediate
      94             : 
      95             : .seealso: LMEMonitorSet()
      96             : @*/
      97           7 : PetscErrorCode LMEMonitorCancel(LME lme)
      98             : {
      99             :   PetscErrorCode ierr;
     100             :   PetscInt       i;
     101             : 
     102           7 :   PetscFunctionBegin;
     103           7 :   PetscValidHeaderSpecific(lme,LME_CLASSID,1);
     104           4 :   for (i=0; i<lme->numbermonitors; i++) {
     105           4 :     if (lme->monitordestroy[i]) {
     106           4 :       ierr = (*lme->monitordestroy[i])(&lme->monitorcontext[i]);CHKERRQ(ierr);
     107             :     }
     108             :   }
     109           7 :   lme->numbermonitors = 0;
     110           7 :   PetscFunctionReturn(0);
     111             : }
     112             : 
     113             : /*@C
     114             :    LMEGetMonitorContext - Gets the monitor context, as set by
     115             :    LMEMonitorSet() for the FIRST monitor only.
     116             : 
     117             :    Not Collective
     118             : 
     119             :    Input Parameter:
     120             : .  lme - linear matrix equation solver context obtained from LMECreate()
     121             : 
     122             :    Output Parameter:
     123             : .  ctx - monitor context
     124             : 
     125             :    Level: intermediate
     126             : 
     127             : .seealso: LMEMonitorSet()
     128             : @*/
     129           0 : PetscErrorCode LMEGetMonitorContext(LME lme,void **ctx)
     130             : {
     131           0 :   PetscFunctionBegin;
     132           0 :   PetscValidHeaderSpecific(lme,LME_CLASSID,1);
     133           0 :   *ctx = lme->monitorcontext[0];
     134           0 :   PetscFunctionReturn(0);
     135             : }
     136             : 
     137             : /*@C
     138             :    LMEMonitorDefault - Print the error estimate of the current approximation at each
     139             :    iteration of the linear matrix equation solver.
     140             : 
     141             :    Collective on lme
     142             : 
     143             :    Input Parameters:
     144             : +  lme    - linear matrix equation solver context
     145             : .  its    - iteration number
     146             : .  errest - error estimate
     147             : -  vf     - viewer and format for monitoring
     148             : 
     149             :    Level: intermediate
     150             : 
     151             : .seealso: LMEMonitorSet()
     152             : @*/
     153           8 : PetscErrorCode LMEMonitorDefault(LME lme,PetscInt its,PetscReal errest,PetscViewerAndFormat *vf)
     154             : {
     155             :   PetscErrorCode ierr;
     156             :   PetscViewer    viewer;
     157             : 
     158           8 :   PetscFunctionBegin;
     159           8 :   PetscValidHeaderSpecific(lme,LME_CLASSID,1);
     160           8 :   PetscValidPointer(vf,4);
     161           8 :   viewer = vf->viewer;
     162           8 :   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
     163           8 :   ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
     164           8 :   ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)lme)->tablevel);CHKERRQ(ierr);
     165           8 :   if (its == 1 && ((PetscObject)lme)->prefix) {
     166           2 :     ierr = PetscViewerASCIIPrintf(viewer,"  Error estimates for %s solve.\n",((PetscObject)lme)->prefix);CHKERRQ(ierr);
     167             :   }
     168           8 :   ierr = PetscViewerASCIIPrintf(viewer,"%3D LME Error estimate %14.12e\n",its,(double)errest);CHKERRQ(ierr);
     169           8 :   ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)lme)->tablevel);CHKERRQ(ierr);
     170           8 :   ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     171           8 :   PetscFunctionReturn(0);
     172             : }
     173             : 
     174             : /*@C
     175             :    LMEMonitorLGCreate - Creates a line graph context for use with
     176             :    LME to monitor convergence.
     177             : 
     178             :    Collective
     179             : 
     180             :    Input Parameters:
     181             : +  comm - communicator context
     182             : .  host - the X display to open, or null for the local machine
     183             : .  label - the title to put in the title bar
     184             : .  x, y - the screen coordinates of the upper left coordinate of
     185             :           the window
     186             : -  m, n - the screen width and height in pixels
     187             : 
     188             :    Output Parameter:
     189             : .  lgctx - the drawing context
     190             : 
     191             :    Options Database Keys:
     192             : .  -lme_monitor_lg - Sets line graph monitor
     193             : 
     194             :    Notes:
     195             :    Use PetscDrawLGDestroy() to destroy this line graph.
     196             : 
     197             :    Level: intermediate
     198             : 
     199             : .seealso: LMEMonitorSet()
     200             : @*/
     201           0 : PetscErrorCode LMEMonitorLGCreate(MPI_Comm comm,const char host[],const char label[],int x,int y,int m,int n,PetscDrawLG *lgctx)
     202             : {
     203             :   PetscDraw      draw;
     204             :   PetscDrawLG    lg;
     205             :   PetscErrorCode ierr;
     206             : 
     207           0 :   PetscFunctionBegin;
     208           0 :   ierr = PetscDrawCreate(comm,host,label,x,y,m,n,&draw);CHKERRQ(ierr);
     209           0 :   ierr = PetscDrawSetFromOptions(draw);CHKERRQ(ierr);
     210           0 :   ierr = PetscDrawLGCreate(draw,1,&lg);CHKERRQ(ierr);
     211           0 :   ierr = PetscDrawLGSetFromOptions(lg);CHKERRQ(ierr);
     212           0 :   ierr = PetscDrawDestroy(&draw);CHKERRQ(ierr);
     213           0 :   *lgctx = lg;
     214           0 :   PetscFunctionReturn(0);
     215             : }
     216             : 
     217           0 : PetscErrorCode LMEMonitorLG(LME lme,PetscInt its,PetscReal errest,void *ctx)
     218             : {
     219           0 :   PetscDrawLG    lg = (PetscDrawLG)ctx;
     220             :   PetscReal      x,y;
     221             :   PetscErrorCode ierr;
     222             : 
     223           0 :   PetscFunctionBegin;
     224           0 :   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,8);
     225           0 :   if (its==1) {
     226           0 :     ierr = PetscDrawLGReset(lg);CHKERRQ(ierr);
     227           0 :     ierr = PetscDrawLGSetDimension(lg,1);CHKERRQ(ierr);
     228           0 :     ierr = PetscDrawLGSetLimits(lg,1,1.0,PetscLog10Real(lme->tol)-2,0.0);CHKERRQ(ierr);
     229             :   }
     230           0 :   x = (PetscReal)its;
     231           0 :   if (errest > 0.0) y = PetscLog10Real(errest);
     232           0 :   else y = 0.0;
     233           0 :   ierr = PetscDrawLGAddPoint(lg,&x,&y);CHKERRQ(ierr);
     234           0 :   if (its <= 20 || !(its % 5) || lme->reason) {
     235           0 :     ierr = PetscDrawLGDraw(lg);CHKERRQ(ierr);
     236           0 :     ierr = PetscDrawLGSave(lg);CHKERRQ(ierr);
     237             :   }
     238           0 :   PetscFunctionReturn(0);
     239             : }
     240             : 

Generated by: LCOV version 1.13