[petsc-users] printing snes prefix with monitor

Barry Smith bsmith at mcs.anl.gov
Thu Oct 6 13:05:04 CDT 2016


   Ah, this support was added to KSP but not SNES. We will accept a pull request that adds the support for SNES (in your case you should also most definitely do the indenting Matt suggests).

PetscErrorCode  SNESMonitorDefault(SNES snes,PetscInt its,PetscReal fgnorm,PetscViewerAndFormat *vf)
{
  PetscErrorCode ierr;
  PetscViewer    viewer = vf->viewer;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
  ierr = PetscViewerPushFormat(viewer,vf->format);CHKERRQ(ierr);
  ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
  ierr = PetscViewerASCIIPrintf(viewer,"%3D SNES Function norm %14.12e \n",its,(double)fgnorm);CHKERRQ(ierr);
  ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)snes)->tablevel);CHKERRQ(ierr);
  ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr) ;
  PetscFunctionReturn(0);
}

PetscErrorCode  KSPMonitorDefault(KSP ksp,PetscInt n,PetscReal rnorm,PetscViewerAndFormat *dummy)
{
  PetscErrorCode ierr;
  PetscViewer    viewer =  dummy->viewer;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,4);
  ierr = PetscViewerPushFormat(viewer,dummy->format);CHKERRQ(ierr);
  ierr = PetscViewerASCIIAddTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
  if (n == 0 && ((PetscObject)ksp)->prefix) {
    ierr = PetscViewerASCIIPrintf(viewer,"  Residual norms for %s solve.\n",((PetscObject)ksp)->prefix);CHKERRQ(ierr);
  }
  ierr = PetscViewerASCIIPrintf(viewer,"%3D KSP Residual norm %14.12e \n",n,(double)rnorm);CHKERRQ(ierr);
  ierr = PetscViewerASCIISubtractTab(viewer,((PetscObject)ksp)->tablevel);CHKERRQ(ierr);
  ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}

> On Oct 6, 2016, at 9:55 AM, Matthew Knepley <knepley at gmail.com> wrote:
> 
> On Thu, Oct 6, 2016 at 9:51 AM, Blaise A Bourdin <bourdin at lsu.edu> wrote:
> Hi,
> 
> I have a problem with 2 nested snes (i.e. SNESComputeFunction for snes1 involves a SNESSolve for snes2).
> Each snes has a different prefix. The problem is that the SESMonitor won’t print the SNES prefix, so that making sense of output can be a bit tricky…
> Is there a simple way to have each snes monitor display the prefix of the snes it refers to? Alternatively, where in the source code is the residual printed during snessolve?
> 
> It would be nice to have a mode that put the prefix on the monitor line.
> 
> What we currently do is indent the subsolve. I normally make the tab level 1 greater than the enclosing solve
> 
>   http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectGetTabLevel.html#PetscObjectGetTabLevel
>   http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscObjectSetTabLevel.html
> 
>   Thanks,
> 
>      Matt
> 
> 
> Blaise
> --
> Department of Mathematics and Center for Computation & Technology
> Louisiana State University, Baton Rouge, LA 70803, USA
> Tel. +1 (225) 578 1612, Fax  +1 (225) 578 4276 http://www.math.lsu.edu/~bourdin
> -- 
> What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.
> -- Norbert Wiener



More information about the petsc-users mailing list