[petsc-dev] SNES with linear operator

Barry Smith bsmith at mcs.anl.gov
Sun Sep 1 18:08:18 CDT 2013


  You mean -snes_type ksponly ?

  Anyways the manual page says:

     SNESKSPONLY - Nonlinear solver that only performs one Newton step and does not compute any norms.
      The main purpose of this solver is to solve linear problems using the SNES interface, without
      any additional overhead in the form of vector operations.

   So I interprete it to mean that for each nonlinear solve it will evaluate the Jacobian (otherwise it is not doing one Newton step) and from the code

 ierr = SNESComputeJacobian(snes,X,&snes->jacobian,&snes->jacobian_pre,&flg);CHKERRQ(ierr);
  ierr = KSPSetOperators(snes->ksp,snes->jacobian,snes->jacobian_pre,flg);CHKERRQ(ierr);

   so clearly it wants to reevaluate the Jacobian for each solve.

Perhaps you also want  SNESSetLagPreconditioner

-  lag - -1 indicates NEVER rebuild, 1 means rebuild every time the Jacobian is computed within a single nonlinear solve, 2 means every second time
         the Jacobian is built etc. -2 indicates rebuild preconditioner at next chance but then never rebuild after that


With this option it will (if coded correctly) reuse the same Jacobian and preconditioner for every SNESSolve() you call (it will just get Jacobian once the first time). I think this is what you want.

   Barry



On Sep 1, 2013, at 5:54 PM, "Mark F. Adams" <mfadams at lbl.gov> wrote:

> I have a SNES solver that runs with a linear operator at times.  I use -ksp_ksponly.  The KSPSetOperator seems to get called every solve because the PC setup code gets called every solve.  Should this be happening?  
> 
> Mark




More information about the petsc-dev mailing list