[petsc-users] Solving two successive linear systems

Samuel Estes samuelestes91 at gmail.com
Fri Sep 17 11:21:35 CDT 2021


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? 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.

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/4094396c/attachment.html>


More information about the petsc-users mailing list