# extracting work vectors

jarunan at ascomp.ch jarunan at ascomp.ch
Fri Dec 4 05:51:27 CST 2009

```Hi Jed,

Thanks for the advice. I took a look in PCShellSetApplyRicharson() and
its apply function.

PetscErrorCode apply (PC pc,Vec b,Vec x,Vec r,PetscReal rtol,PetscReal
abstol,PetscReal dtol,PetscInt maxits)

b - right-hand-side
x - current iterate
r - work space

1. Can I use PCShellSetApplyRicharson() with KSPGMRES? or it is
restrict only for Richardson solver.

2. Is x equivalent to xin in PCShellSetApply(pc,apply(PC pc,Vec
xin,Vec xout))?

3. Are b vector is the right hand side specified by user and r the
work vector in the iterations?

Jarunan

Quoting Jed Brown <jed at 59A2.org>:

> On Fri, 04 Dec 2009 11:25:11 +0100, jarunan at ascomp.ch wrote:
>> I would like to use user-defined preconditioner PCSHELL for GMRES,
>> from which I need the work vector(Right hand side during solving which
>> is residual) and approx solution.
>
> A preconditioner for a Krylov iteration cannot use this information,
> maybe you're thinking of preconditioned Richardson iteration in which
> case, see PCShellSetApplyRicharson.
>
>>  From PCShellSetApply(pc,apply)
>>
>> where 'apply' define as PetscErrorCode apply (void *ptr,Vec xin,Vec xout)
>
> should be
>
>   PetscErrorCode apply(PC pc,Vec xin,Vec xout);
>
> use PCShellGetContext() to retrieve your pointer from the PC.
>
>> Is xin automatically the approx solution?
>
> No, it's the vector that the KSP needs you to apply your preconditioner
> to.  The relationship between this vector and the "approximate solution"
> is different at every iteration of every Krylov method, and different
> with right versus left preconditioning.  GMRES does not even build the
> "approximate solution" during the iteration, it is only built once you
> have converged.  Application of your preconditioner *only* uses xin.
>
> Jed
>

--
Jarunan Panyasantisuk
Development Engineer
ASCOMP GmbH, Technoparkstr. 1
CH-8005 Zurich, Switzerland
Phone : +41 44 445 4072
Fax   : +41 44 445 4075
E-mail: jarunan at ascomp.ch
www.ascomp.ch
```