<div dir="ltr"><div>Dear PETSc users, <br></div><div><br><br></div><div>I am using PETSc  Fortran API. <br></div><div>I try to solve a linear system, and would like to define my own convergence test. <br></div><div>More precisely, my convergence test calls the default convergence test </div><div>and then checks the true residual norm : <br>     subroutine MyKSPConverged(ksp,n,rnorm,flag,dummy,ierr)<br><br>      implicit none<br><br>#include <petsc/finclude/petscsys.h><br>#include <petsc/finclude/petscvec.h><br>#include <petsc/finclude/petscksp.h><br><br>      KSP              ksp<br>      PetscErrorCode ierr<br>      PetscInt n,dummy<br>      KSPConvergedReason flag<br>      PetscReal rnorm, true_rnorm<br>      Vec true_res<br>      !<br>      call KSPConvergedDefault(ksp,n,rnorm,flag,PETSC_NULL_OBJECT,ierr)<br>      !<br>      ! If convergence test succeeds <br>       if ( (flag == KSP_CONVERGED_ATOL) .or.                           &<br>     &  (flag == KSP_CONVERGED_RTOL)) then <br>        ! Compute true residual<br>        call KSPBuildResidual( ksp , PETSC_NULL_OBJECT,                 &<br>     & PETSC_NULL_OBJECT, true_res, ierr )<br>        ! Compute true residual norm <br>        call VecNorm(true_res,NORM_2,true_rnorm,ierr)<br>        ! And check again convergence with respect to the true residual norm<br>        call KSPConvergedDefault(ksp,n,true_rnorm,flag,                 &<br>     & PETSC_NULL_OBJECT, ierr)<br>        ! Free memory<br>        call VecDestroy(true_res, ierr) <br>      endif <br>      !       <br>      ierr = 0<br><br>      end<br><br></div><div>I get the following error message<br><br>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: Null argument, when expecting valid pointer<br>[0]PETSC ERROR: Convergence context must have been created with KSPConvergedDefaultCreate()<br>[0]PETSC ERROR: See <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html">http://www.mcs.anl.gov/petsc/documentation/faq.html</a> for trouble shooting.<br>[0]PETSC ERROR: Petsc Release Version 3.6.2, Oct, 02, 2015 <br><br></div><div>I understand that I should have  call KSPConvergedDefaultCreate() before calling KSConvergedDefault( ....) <br></div><div><br></div><div>Am I right ? <br></div><div><br>If so what is the Fortran calling sequence for  KSPConvergedDefaultCreate ? It is supposed to return a valid pointer and I don't succeed in doing so from Fortran. <br></div><div><br>If you have any idea, I'd greatly appreciate it<br>Thank you!<br></div><div>Natacha <br></div><div><br></div><div><br></div><div>PS I have attached my code (it's a slightly modified version of ex2f.F showing  the convergence test code )<br></div></div>