[petsc-users] preconditioning matrix-free newton-krylov

Mark Lohry mlohry at gmail.com
Sun Oct 29 11:50:47 CDT 2017


Thanks again Barry, I've got the preconditioners hooked up with
-snes_mf_operator and at least AMG looks to be working great on a high
order unstructured DG problem.

Couple questions on the SNESSetLagJacobian + SNESSetLagPreconditioner code
flow:

1) With -snes_mf_operator, and given SNESSetLagJacobian(snes, 1) (default)
 and SNESSetLagPreconditioner(snes, 2), after the first KSP solve in a
newton iteration, will it do the finite different jacobian calculation? Or
will the Jacobian only be computed when the preconditioner lag setting
demands it on the 3rd newton step? I suspect it's the latter based on where
I see the code pause.

2) How do implicit TS and SNESSetLagPreconditioner/Persists interact? Does
the counter since-last-preconditioner-compute reset with time steps, or
does that lag counter just increment with every SNES solve regardless of
how many nonlinear solves might have happened in a given timestep? Say lag
preconditioner is 2, and a time stepper uses 3, 2, and 3 nonlinear solves
on 3 steps, is the flow

(time step 1)->(update preconditioner)->(snes solve)->(snes solve)->(update
preconditioner)->(snes solve)
(time step 2)->(snes solve)->(update preconditioner)->(snes solve)
(time step 3)->(snes solve)->(update preconditioner)->(snes solve)->(snes
solve)

or

(time step 1)->(update preconditioner)->(snes solve)->(snes solve)->(update
preconditioner)->(snes solve)
(time step 2)->(update preconditioner)->(snes solve)->(snes solve)
(time step 3)->(update preconditioner)->(snes solve)->(snes solve)->(update
preconditioner)->(snes solve)

?

I think for implicit time stepping I'd probably want the preconditioner to
be recomputed just once at the beginning of each time step, or some
multiple of that. Does that sound reasonable?

3) Are there any hooks analogous to KSPSetPreSolve/PostSolve for the FD
computation of the jacobians, or for the computation of the preconditioner?
I'd like to get a handle on the relative costs of these.


Best,
Mark

On Sat, Sep 23, 2017 at 3:28 PM, Mark Lohry <mlohry at gmail.com> wrote:

> Great, thanks Barry.
>
> On Sat, Sep 23, 2017 at 3:12 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>>
>> > On Sep 23, 2017, at 12:48 PM, Mark W. Lohry <mlohry at princeton.edu>
>> wrote:
>> >
>> > I'm currently using JFNK in an application where I don't have a
>> hand-coded jacobian, and it's working well enough but as expected the
>> scaling isn't great.
>> >
>> > What is the general process for using PC with MatMFFDComputeJacobian?
>> Does it make sense to occasionally have petsc re-compute the jacobian via
>> finite differences, and then recompute the preconditioner? Any that just
>> need the sparsity structure?
>>
>>  Mark
>>
>>    Yes, this is a common approach. SNESSetLagJacobian -snes_lag_jacobian
>>
>>     The normal approach in SNES to use matrix-free for the operator and
>> use finite differences to compute an approximate Jacobian used to construct
>> preconditioners is to to create a sparse matrix with the sparsity of the
>> approximate Jacobian (yes you need a way to figure out the sparsity, if you
>> use DMDA it will figure out the sparsity for you). Then you use
>>
>>    SNESSetJacobian(snes,J,J, SNESComputeJacobianDefaultColor, NULL);
>>
>> and use the options database option -snes_mf_operator
>>
>>
>> > Are there any PCs that don't work in the matrix-free context?
>>
>>   If you do the above you can use almost all the PC since you are
>> providing an explicit matrix from which to build the preconditioner
>>
>> > Are there any example codes I overlooked?
>> >
>> > Last but not least... can the Boomer-AMG preconditioner work with JFNK?
>> To really show my ignorance of AMG, can it actually be written as a matrix
>> P^-1(Ax-b)=0, , or is it just a linear operator?
>>
>>   Again, if you provide an approximate Jacobian like above you can use it
>> with BoomerAMG, if you provide NO explicit matrix you cannot use BoomerAMG
>> or almost any other preconditioner.
>>
>>    Barry
>>
>> >
>> > Thanks,
>> > Mark
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20171029/c6db095f/attachment.html>


More information about the petsc-users mailing list