adding support for custom call to inner linear solve in SNES

Lisandro Dalcin dalcinl at
Tue Aug 7 18:12:58 CDT 2007

I would like to add some support in SNES to enable users to customize
the inner call to KSPSolve(). The approach amount to implement
something like this:

#undef __FUNCT__
#define __FUNCT__ "SNES_KSPSolve"
PetscErrorCode SNES_KSPSolve(SNES snes, KSP ksp, Vec b, Vec x)
  PetscErrorCode ierr;

  if (snes->ksp_ewconv) { ierr =
SNESKSPEW_PreSolve(snes,ksp,b,x);CHKERRQ(ierr);  }
  if (snes->ops->linsolve) {
    ierr = (*snes->ops->linsolve)(snes, ksp, b, x);CHKERRQ(ierr);
  } else {
    ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
  if (snes->ksp_ewconv) { ierr =
SNESKSPEW_PostSolve(snes,ksp,b,x);CHKERRQ(ierr); }

and, of course, add a routine to let users set their custom linear
solve routine.

Is this fine? Is it open-door for too-much user hackery? There could
be a better way to enable something like this?

I am also thinking (if there is no objection) in adding support for
setting a PreSolve and a PostSolve routine, but not sure what the
interface of the callback functions should be, and if the presolve
routine should be called after of before SNESSetUp().

Lisandro Dalcín
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594

More information about the petsc-dev mailing list