Conjugate Gradient technique
Barai, Pallab
baraip at ornl.gov
Thu May 14 16:36:43 CDT 2009
Thank you very much Barry for the solution. I will give it a try.
Pallab
-----Original Message-----
From: petsc-users-bounces at mcs.anl.gov on behalf of Barry Smith
Sent: Thu 5/14/2009 5:29 PM
To: PETSc users list
Subject: Re: Conjugate Gradient technique
You just pass the shell matrix into KSPSetOperators() and
KSPSolve() will do the rest.
Note: you will need to use -pc_type none as the preconditioner
since you are not providing a matrix from which to build the
preconditioner.
Barry
On May 14, 2009, at 4:26 PM, Barai, Pallab wrote:
> Hello Matt,
>
> Thank you very much for your reply.
>
> Here "S" is a symmetric matrix, so I have to use the CG.
>
> But I can not figure out how to use the Conjugate Gradient technique
> to find the solution. In the "MatShell" I can wrap my "MatVec"
> routine which calculates the "S*x" vector.
>
> But how will I be able to do the comparison between the known "b"
> vector and the calculated "S*x" using a CG (and come up with a new
> trial solution "x" for the next iteration). What is the function
> that I should call for this purpose?
>
> Thanking you.
>
> Pallab
>
>
> -----Original Message-----
> From: petsc-users-bounces at mcs.anl.gov on behalf of Matthew Knepley
> Sent: Thu 5/14/2009 5:03 PM
> To: PETSc users list
> Subject: Re: Conjugate Gradient technique
>
> On Thu, May 14, 2009 at 3:58 PM, Barai, Pallab <baraip at ornl.gov>
> 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:
>
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Mat/MatCreateShell.html
>
> Matt
>
>
>>
>> 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
> lead.
> -- Norbert Wiener
>
More information about the petsc-users
mailing list