[petsc-users] Matrix-free preconditioner using shell matrix

Smith, Barry F. bsmith at mcs.anl.gov
Fri May 18 12:05:25 CDT 2018



> On May 18, 2018, at 9:09 AM, Praveen C <cpraveen at gmail.com> wrote:
> 
> Thanks, I will check these out.
> 
> I am solving a non-linear problem using TS. I will use -snes_mf so that jacobian action is computed by petsc using finite differences.
> 
> I am trying to use shell matrix for preconditioner P as follows.
> 
>      call MatCreateShell(PETSC_COMM_WORLD, n, n, &
>                          PETSC_DETERMINE, PETSC_DETERMINE, &
>                          ctx, P, ierr); CHKERRQ(ierr)
>      call MatShellSetOperation(P, MATOP_MULT, ApplyPC, ierr); CHKERRQ(ierr)

   This is wrong. If you have a ApplyPC you need to attach it to the PC not the mat. So you would have 

       SNESGetPC(snes,&pc);
       PCSetType(pc,PCSHELL);
       PCShellSetAppy(pc,ApplyPC)

   Barry


>      call TSSetRHSJacobian(ts, P, P, RHSJacobian, ctx, ierr); CHKERRQ(ierr)
> 
> Is ApplyPC supposed to do the following ?
> 
> subroutine ApplyPC(P, x, y, ierr)
> 
> ! Compute y = P^(-1) * x
> 
> end subroutine ApplyPC
> 
> Thanks
> praveen
> 
>> On 18-May-2018, at 7:23 PM, Jed Brown <jed at jedbrown.org> wrote:
>> 
>> See examples at the bottom of the page.
>> 
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/PC/PCShellSetApply.html
>> 
>> Praveen C <cpraveen at gmail.com> writes:
>> 
>>> Dear all
>>> 
>>> I am looking for any example code that shows how to use my own matrix-free preconditioner using a shell matrix. I am using TS to solve my problem.
>>> 
>>> Thanks
>>> praveen
> 



More information about the petsc-users mailing list