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

Barry Smith bsmith at mcs.anl.gov
Tue Mar 31 21:26:49 CDT 2015


> On Mar 31, 2015, at 9:03 PM, Juris Vencels <juris.vencels at gmail.com> wrote:
> 
> Hello PETSc Users,
> 
> I am using Matrix-Free SNES solver with the following options
>    PETSC_OPTIONS="ksp_type gmres -snes_monitor_short -snes_mf -user_precond"
> 
> and shell-ILU preconditioner that I create as following:
> 
> ! ===============================
> 
>       call PCSetType(pc,PCSHELL,ierr)
>       call PCShellSetUp
>       call PCShellSetApply(pc,PCShellApply,ierr)
>       call PCShellSetName(pc,"ShellPC",ierr)
> 
> ! ===============================
> 
>   subroutine PCShellSetUp() 
>     implicit none
> 
>      call SetInitialMatrix   ! Assambles matrix A
> 
>      call PCCreate(PETSC_COMM_WORLD,mf_prec,ierr)
>      call PCSetType(mf_prec,PCILU,ierr)
>      call PCSetOperators(mf_prec,A,A,ierr)
>      call PCSetUp(mf_prec,ierr)
>      call PCShellSetName(mf_prec,"LinPC",ierr)
> 
>   end subroutine PCShellSetUp
> 
> ! ===============================
> 
>   subroutine PCShellApply(pc_tmp,x_tmp,y_tmp,ierr)
>     implicit none
>     PC  :: pc_tmp
>     Vec :: x_tmp,y_tmp
>     PetscErrorCode :: ierr
> 
>     call PCApply(mf_prec,x_tmp,y_tmp,ierr)
> 
>   end subroutine PCShellApply
> 
> ! ===============================
> 
> * If matrix A changes during a simulation, how can I update preconditioner? Is calling "PCSetUp(mf_prec,ierr)" enough?

  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.



> 
> * Function PCView prints out information about type and size of preconditioner. Can I view/get preconditioner matrix itself? I want to compare it with reference matrix.
> 
> If I try to MatView factored matrix:
>     call PCFactorGetMatrix(mf_prec,pcmat,ierr)
>     call MatView(pcmat, PETSC_VIEWER_STDOUT_SELF,ierr)
> 
> Then I get the following error:
>     [0]PETSC ERROR: No viewers for factored matrix except ASCII info or info_detailed

  The LU factors of sparse matrices are rather complicated beasts, there is no reasonable way to see their numerical values and related them to original matrix.

  A note about terminology:  We refer to the "preconditioner matrix" sometimes, it means "the matrix FROM WHICH a preconditioner is built." With ILU the "preconditioner matrix" is factored into L and U (which is what PCFactorGetMatrix() returns. The L and U are the resulting preconditioner, they are not the "matrix from which the preconditioner is built."

  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.



  Barry

> 
> Thanks!
> 
> 
> 



More information about the petsc-users mailing list