If you use the default KSP convergence tests (which almost everyone does) the initial residual norm is stored in ksp->rnorm0. Thus to access it you need to include the private header file that defines the KSP object kspimpl.h so something like
#include <petsc/private/kspimpl.h> PetscErrorCode KSPGetInitialResidualNorm(KSP ksp,PetscReal *norm0) { *norm0 = ksp->rnorm0; return 0; } should work. Barry > On Feb 3, 2019, at 8:27 AM, Edoardo alinovi via petsc-users > <petsc-users@mcs.anl.gov> wrote: > > Dear all, > > I have a very simple question for you. How can I get the initial residual > from a ksp solver? I can easily extract the final (preconditioned) residual > norm but when I try to use to do the same with the initial residual using: > > kspInitialResidual() > > PETSc tells me that this feature is not supported. I am actually doing it > applying the definition of residual "by hand", but I am wondering if > somenthing already built-in is available or not. > > Thank you very much! > ------ > > Edoardo Alinovi, Ph.D. > > DICCA, Scuola Politecnica, > Universita' degli Studi di Genova, > 1, via Montallegro, > 16145 Genova, Italy > > Email: edoardo.alin...@dicca.unige.it > Tel: +39 010 353 2540 > > >