# [petsc-users] On re usability of A matrix and b vector

baikadi pranay pranayreddy865 at gmail.com
Thu Aug 20 19:45:48 CDT 2020

```Thank you for the clarification.

I also want to get two more things clarified. After i^th call to
KSPSolve(), I get x^i as the solution vector. I do a bunch of updates to A
matrix and b vector using this x^i and copy x^i into a vector called x_old.

1) When I call KSPSolve for the (i+1)th time using KSPSolve(ksp,b,x,ierr),
the variable x already has the solution of the previous iteration in it.
Does that mean I need to create a new x vector each time I call KSPSolve?
2) On the similar lines, do I need to create new x_old after each
iteration?

Please let me know if the questions are unclear, so that I can elaborate.
ᐧ

On Wed, Aug 19, 2020 at 9:06 PM Barry Smith <bsmith at petsc.dev> wrote:

>
>   KSP knows if the matrix has changed and rebuilds the parts of the
> preconditioner it needs if the matrix has changed. When the matrix has not
> changed it uses the exact same preconditioner as before.
>
>
>    Barry
>
>  This "trick" is done by having an integer state variable inside the
> matrix object. Each time the matrix is changed by MatSetValues() etc. the
> state variable is incremented. KSPSolve() keeps a record of the state
> variable of the matrix for each call to SNESSolve(), if the state variable
> has increased it knows the matrix has changed so updates the
> preconditioner.
>
> On Aug 19, 2020, at 9:05 PM, baikadi pranay <pranayreddy865 at gmail.com>
> wrote:
>
> Hello,
>
> I am trying to solve the poisson equation iteratively using BiCGStab in
> FORTRAN 90. After every call to KSPSolve, I update the central coefficients
> of A matrix and the b vector (and then solve the new linear equation
> system, repeating the process until convergence is achieved). I want to
> know whether the A matrix and b vector that are created initially can be
> used in the iteration process or do I need to create a new A matrix and b
> vector in each iteration.
>
> Please let me know if you need any further information.
>
> Thank you.
>
> Sincerely,
> Pranay.
> ᐧ
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200820/8b743a6d/attachment.html>
```