<div dir="ltr">Thanks for the help!<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 17, 2021 at 11:37 AM Barry Smith <<a href="mailto:bsmith@petsc.dev">bsmith@petsc.dev</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br>
<br>
> On Sep 17, 2021, at 12:21 PM, Samuel Estes <<a href="mailto:samuelestes91@gmail.com" target="_blank">samuelestes91@gmail.com</a>> wrote:<br>
> <br>
> Hi,<br>
> <br>
> I have two related questions about the best way to use the KSP solver:<br>
> <br>
> 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:<br>
> KSPSetOperators(ksp,A,A);<br>
> KSPSetFromOptions();<br>
> KSPSolve(ksp,b,x);<br>
> In a separate part of the code, I re-create the matrix and vectors and call KSPReset(ksp); whenever the grid is refined. <br>
> 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?<br>
<br>
   Yes, it is best to call the KSPSetFromOptions after each reset. You do not need to call it for each solve.<br>
<br>
> 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. <br>
> <br>
> 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.<br>
<br>
   It is best to use two KSP. There is no advantage in reusing one.<br>
> <br>
> Thanks in advance for the help. I hope my questions are clear. If not, I'm happy to clarify.<br>
> <br>
> Sam<br>
> <br>
> <br>
<br>
</blockquote></div>