[petsc-dev] Matrix Free Conjugate Gradient

Jed Brown jedbrown at mcs.anl.gov
Sat Dec 1 00:53:20 CST 2012


On Sat, Dec 1, 2012 at 12:48 AM, Hesameddin Ilatikhameneh <
hilatikh at purdue.edu> wrote:

> Sorry but I didn't get/understand the answer to my questions:
>
> 1- I don't want to store Jacobian matrix so how is that Mat A is input of
> the function PetscErrorCode YourMatMult(Mat A,Vec X,Vec Y)?
>

That Mat has type MATSHELL. It contains no data (or only the data you put
there). You are implementing the Mat interface as you like.


>
> 2- I need to find each row of Jacobian and multiply it with a vector which
> is needed in Petsc CG and store that to a vector. So there should be very
> specific function associated with specific method (like CG in this case).
>
>
You just need to apply your operator to the Vec. Most matrix-free operators
never explicitly construct entries of the matrix. (Other matrix-free
operators include matrix-free finite difference, FFT, FMM, tensor product
operations, unassembled Galerkin products, and approximate Schur
complements.)


> 3- What is vector X in YourMatMult(Mat A,Vec X,Vec Y)?


It's the Vec that's passed in. You use the Vec interface (VecGetArray, etc)
to interact with it.


> Where this matrix-multipication will be used?
>

When CG (or any other method) needs to apply the matrix.


>
> Thanks
> Hesam
> ----- Original Message -----
> From: "Jed Brown" <jedbrown at mcs.anl.gov>
> To: "For users of the development version of PETSc" <petsc-dev at mcs.anl.gov
> >
> Sent: Saturday, December 1, 2012 1:08:59 AM
> Subject: Re: [petsc-dev] Matrix Free Conjugate Gradient
>
> On Fri, Nov 30, 2012 at 11:53 PM, Hesameddin Ilatikhameneh <
> hilatikh at purdue.edu > wrote:
>
>
>
>
> Could you provide more information/example.
> I don't know that for example for matrix-free conjugate gradient in Petsc
> which matrix operation I should do.
> I guess that I need to write the function that gives Jacobian times a
> vector which is vector (Since I don't want to store Jacobian).
> If it is so, which vector is that vector? Petsc will do which parts of the
> algorithm?
>
>
>
> You implement
>
>
> PetscErrorCode YourMatMult(Mat A,Vec X,Vec Y);
>
>
> which computes Y <-- A*X. There is a section of the user's manual, as well
> as a couple examples linked from the page I sent.
>
>
> You only need to implement that one function, then pass -pc_type none so
> that no preconditioning is done. PETSc will do everything else in the solve.
>
>
>
>
> Thanks for your help.
>
> Hesam
>
>
>
> ----- Original Message -----
> From: "Jed Brown" < jedbrown at mcs.anl.gov >
> To: "For users of the development version of PETSc" <
> petsc-dev at mcs.anl.gov >
> Sent: Saturday, December 1, 2012 12:37:22 AM
> Subject: Re: [petsc-dev] Matrix Free Conjugate Gradient
>
>
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatShellSetOperation.html
>
>
>
> Note that without an assembled matrix, you'll generally need to write your
> own preconditioner, which you can do using PCShell.
>
>
>
> On Fri, Nov 30, 2012 at 11:24 PM, Hesameddin Ilatikhameneh <
> hilatikh at purdue.edu > wrote:
>
>
> Hello,
>
> We have a very large system (100M variables) which we want to minimize its
> energy. We are using Petsc extensively for matrix operations.
> I know that it is theoretically possible to use conjugate gradient method
> without storing Jacobian matrix (which is very huge in this case) since the
> conjugate gradient needs Jacobian times a vector not Jacobian itself.
>
> I read your manual about matrix free methods but I couldn't find where I
> can determine that function to Jacobian times a vector.
>
> I appreciate your help.
>
> Thanks
> Hesam
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20121201/605eca30/attachment.html>


More information about the petsc-dev mailing list