# [petsc-users] KSP for successive linear systems

K. Wu wuktsinghua at gmail.com
Tue Mar 14 09:06:50 CDT 2023

```Thank you for the clarification.

Barry Smith <bsmith at petsc.dev> 于2023年3月14日周二 13:27写道：

>
>   To gain an advantage in reusing the KSP the Mat must be the same size
> and the Mat must have the same nonzero structure (different numerical
> values are fine). Otherwise there is no measurable improvement in reusing
> the same KSP.
>
>   Barry
>
>
> > On Mar 14, 2023, at 7:25 AM, K. Wu <wuktsinghua at gmail.com> wrote:
> >
> > Hi all,
> >
> > Good day!
> >
> > I am trying to solve an optimization problem where I need to solve
> multiple successive linear systems inside each optimization loop. The
> matrices are based on the same grid, but their data structure will change
> for each linear system.
> >
> > Currently I am doing it by setting up just one single KSP object. Then
> call KSPSetOperators() and KSPSolve() for each solve. This means the KSP
> object is solving the successive linear systems one by one, and in the next
> optimization iteration, it starts all over again.
> >
> > I am wondering that should I use separate KSP objects for each linear
> system so that during optimization the same KSP will be specialized in
> solving its corresponding system all the time?
> >
> > I use non-zero initial guess, so I pay attention to use different x
> vectors for different linear systems, so that the x vectors from the
> previous iteration can be used as initial guesses for linear systems in the
> next iteration. Not sure whether some similar thing should also be done for
> KSP?
> >
> > Thanks for your kind help!
> >
> > Best regards,
> > Kai
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230314/f84524ac/attachment.html>
```