[petsc-users] Custom KSP monitor changes in PETSc 3.7

Miorelli, Federico Federico.Miorelli at CGG.COM
Mon May 2 07:48:29 CDT 2016


Dear All,

I am having some issues upgrading to PETSc 3.7 due to some changes in the KSPMonitor routines.
I need to configure my KSP solver to output its convergence log to an existing ASCII viewer through a custom monitor, printing only one every 10 iterations.
The calling code is Fortran, we wrote a small C code that just calls the default monitor every 10 iterations, passing the viewer as last argument. If I understood correctly it is now necessary to set up a PetscViewerAndFormat structure and pass that as last argument to the monitor routine.

I tried to create one with PetscViewerAndFormatCreate but I'm getting a runtime error (see below).
Could you please help me understand what I did wrong?

Thanks in advance,

Federico



Error:

[1]PETSC ERROR: #1 PetscViewerPushFormat() line 149 in /PETSc/petsc-3.7.0/src/sys/classes/viewer/interface/viewa.c
Error Message --------------------------------------------------------------
[8]PETSC ERROR: Argument out of range
[8]PETSC ERROR: Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?


Fortran code:

  PetscViewer :: viewer
  PetscViewerAndFormat :: vf
  external ShellKSPMonitor
...
  call PetscViewerAndFormatCreate(viewer, PETSC_VIEWER_DEFAULT, vf,ierr)
  call KSPMonitorSet(ksp, ShellKSPMonitor, vf, PetscViewerAndFormatDestroy, ierr)



C code:
PetscErrorCode  shellkspmonitor_(KSP *ksp, PetscInt *n, PetscReal *rnorm, void *ptr)
{
    PetscErrorCode ierr=0;
    if (*n % 10 == 0) {
       ierr = KSPMonitorTrueResidualNorm(*ksp,*n,*rnorm,(PetscViewerAndFormat*)ptr);CHKERRQ(ierr);
    }
    return ierr;
}




______ ______ ______
Federico Miorelli
Senior R&D Geophysicist
Subsurface Imaging - General Geophysics Italy



This email and any accompanying attachments are confidential. If you received this email by mistake, please delete
it from your system. Any review, disclosure, copying, distribution, or use of the email by others is strictly prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20160502/59e6d60c/attachment-0001.html>


More information about the petsc-users mailing list