[petsc-users] Preconditioning Matrix-free SNES, preconditioner update, PCView

Barry Smith bsmith at mcs.anl.gov
Wed Apr 1 17:37:10 CDT 2015


> On Apr 1, 2015, at 5:09 PM, Juris Vencels <juris.vencels at gmail.com> wrote:
> 
> On 03/31/2015 08:26 PM, Barry Smith wrote:
>>   No, the model is that each time the matrix changes the PCSetUp is called automatically and so is a shell set up if you have provided it, so you need to change your PCShellSetUp() function so that it can be called repeatedly for each new matrix and call 
>> 
>> 
>>> > 
>>> call PCShellSetApply(pc,PCShellSetUp,ierr)
>>> 
>> when you create the Shell PC.
>> 
>>   Then make a test run in the debugger to make sure that your setup is being called each time the matrix changes.
>> 
>> 
> 
> It works, thank you! 
> 
>>   Note: also if you are using ILU preconditioning, you do not need to use PCSHELL, you can just use PCSetType(pc,PCILU) or -pc_type ilu.
> 
> I am confused about this, I am using matrix-free SNES and Manual Section 5.5. says:
> 
>> The matrix-free variant is allowed only when the linear systems are solved by an it-
>> erative method in combination with no preconditioning (PCNONE or -pc_type none), a user-provided
>> preconditioner matrix, or a user-provided preconditioner shell (PCSHELL, discussed in Section 4.4); ...
> 
> PETSc has function "PCShellSetApply " which sets routine to use as preconditioner.
> How can I set a routine if I do not use PCSHELL? There is no such function as " PCSetApply" anymore.

   One can use -snes_mf_operator this causes the operator that DEFINES the linear system to be matrix free. Meanwhile one still builds an explicit approximation to the Jacobian as the SECOND matrix argument to SNESSetJacobian(). The preconditioner is then buildt from this second matrix. So if one does -pc_type ilu the preconditioner is built by doing ILU on that second matrix. 

    If you use -snes_mf you need to use a PCSHELL but if you have an explicit matrix from which you are going to build the preconditioner then there is no reason to use PCSHELL (which is more complicated) because you can use -snes_mf_operator instead and have PETSc manage the preconditioner in the usual manner with, for example, -pc_type ilu etc

  
  Barry






More information about the petsc-users mailing list