[petsc-users] Solving two successive linear systems

Samuel Estes samuelestes91 at gmail.com
Fri Sep 17 11:46:24 CDT 2021


Thanks for the help!

On Fri, Sep 17, 2021 at 11:37 AM Barry Smith <bsmith at petsc.dev> wrote:

>
>
> > On Sep 17, 2021, at 12:21 PM, Samuel Estes <samuelestes91 at gmail.com>
> wrote:
> >
> > Hi,
> >
> > I have two related questions about the best way to use the KSP solver:
> >
> > First, I have an adaptive FEM code which solves the same linear system
> at each iteration until the grid is refined at which point, obviously, the
> size of the linear system changes. Currently, I just call:
> > KSPSetOperators(ksp,A,A);
> > KSPSetFromOptions();
> > KSPSolve(ksp,b,x);
> > In a separate part of the code, I re-create the matrix and vectors and
> call KSPReset(ksp); whenever the grid is refined.
> > Is this an optimal way to do things? In particular, does
> KSPSetFromOptions need to be called before each solve or can I just call it
> once somewhere else and then be done with it. Does it need to be called
> after each call to KSPReset?
>
>    Yes, it is best to call the KSPSetFromOptions after each reset. You do
> not need to call it for each solve.
>
> > There is a section in the PETSc Manual about solving successive linear
> systems but it is rather terse so I'm just trying to get a sense of how to
> optimally code this.
> >
> > Second, one model in this code actually successively solves two linear
> systems of different sizes (one system is n x n and the other is 3*n x
> 3*n). I solve this by creating two matrices, two right hand sides, and two
> solution vectors for each system. I currently just use one KSP object which
> I reset after each use since the linear system changes size each time.
> Would it be more efficient to simply allocate a second ksp solver object so
> that I don't have to call KSPReset every time? I'm not sure how much memory
> a ksp object requires or how much computation I would save by using a
> second solver. Any ideas here? This part of the code is also adaptive.
>
>    It is best to use two KSP. There is no advantage in reusing one.
> >
> > Thanks in advance for the help. I hope my questions are clear. If not,
> I'm happy to clarify.
> >
> > Sam
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210917/fa069ab2/attachment.html>


More information about the petsc-users mailing list