[petsc-users] Matrix-free method in PETSc

Yuyun Yang yyang85 at stanford.edu
Sun Feb 16 05:12:13 CST 2020


Thank you, that is very helpful information indeed! I will try it and send you my code when it works.

Best regards,
Yuyun
________________________________
From: Smith, Barry F. <bsmith at mcs.anl.gov>
Sent: Saturday, February 15, 2020 10:02 PM
To: Yuyun Yang <yyang85 at stanford.edu>
Cc: petsc-users at mcs.anl.gov <petsc-users at mcs.anl.gov>
Subject: Re: [petsc-users] Matrix-free method in PETSc

  Yuyun,

    If you are speaking about using a finite difference stencil on a structured grid where you provide the Jacobian vector products yourself by looping over the grid doing the stencil operation we unfortunately do not have exactly that kind of example.

    But it is actually not difficult. I suggest starting with src/ts/examples/tests/ex22.c It computes the sparse matrix explicitly with FormIJacobian()

    What you need to do is instead in main() use MatCreateShell() and MatShellSetOperation(,MATOP_MULT,(void (*)(void))MyMatMult) then provide the routine MyMatMult() to do your stencil based matrix free product; note that you can create this new routine by taking the structure of IFunction() and reorganizing it to do the Jacobian product instead. You will need to get the information about the shell matrix size on each process by calling DMDAGetCorners().

    You will then remove the explicit computation of the Jacobian, and also remove the Event stuff since you don't need it.

     Extending to 2 and 3d is straight forward.

     Any questions let us know.

   Barry

   If you like this would make a great merge request with your code to improve our examples.


> On Feb 15, 2020, at 9:42 PM, Yuyun Yang <yyang85 at stanford.edu> wrote:
>
> Hello team,
>
> I wanted to apply the Krylov subspace method to a matrix-free implementation of a stencil, such that the iterative method acts on the operation without ever constructing the matrix explicitly (for example, when doing backward Euler).
>
> I'm not sure whether there is already an example for that somewhere. If so, could you point me to a relevant example?
>
> Thank you!
>
> Best regards,
> Yuyun

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200216/271544e7/attachment.html>


More information about the petsc-users mailing list