[petsc-users] Custom KSP monitor changes in PETSc 3.7
Barry Smith
bsmith at mcs.anl.gov
Tue May 3 15:29:13 CDT 2016
Federico,
Sorry for the delay in responding. I think the problem is due to setting the monitor from Fortran but having the monitor written in C.
To make your life simpler I think you should be able to write the ShellKSPMonitor in Fortran. (no C code at all)
If that fails please send us a complete (trivial) code that we can build that exhibits the problem and we'll see what is going on.
Barry
> On May 2, 2016, at 7:48 AM, Miorelli, Federico <Federico.Miorelli at CGG.COM> wrote:
>
> 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.
More information about the petsc-users
mailing list