Conjugate Gradient technique

Matthew Knepley knepley at
Thu May 14 16:03:13 CDT 2009

On Thu, May 14, 2009 at 3:58 PM, Barai, Pallab <baraip at> wrote:

> Hello,
> I am using PETSc to solve a set of linear equations "Sx=b".
> Here "b" is known and "x" is the trial solution.
> The complete (assembled) form of S is not known. That is why I am not able
> to use something like "KSPSolve".
> But given a trial solution "x", I can calculate "S*x" using a "MatVec"
> routine.
> Is it possible to use the Conjugate Gradient (CG) technique to find a
> solution in this case? In place of "S", I can give "S*x" as the input.

You can use CG if S is symmetric. If not, try GMRES.

> It will be great if someone can show me some direction. If this thing has
> already been discussed before, the link to that thread will be sufficient.

You can wrap your function in a MatShell:


> Thanking you.
> Pallab Barai
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the petsc-users mailing list