<div dir="ltr"><div>Hello Barry,</div><div><br></div><div>I tested what we discussed yesterday and I would say the KSPDestroy works good, while the trick of setting the matrix to NULL in KSPSetOperators does not.</div><div dir="auto"><br></div><div>I attach here the memory traces of my code:</div><div>- baseline (each equation keep the matrix and does not destroy KSP)</div><div>- With KSPSetOperators(ksp, PETSC_NULL_MAT,PETSC_NULL_MAT)</div><div>- With KSPDestroy() before MatDestroy()</div><div><br></div><div>Clearly, the last one is a winner, while the first two look pretty similar! Any possible explanation? I can happily destroy KSP, but the other one is cleaner to implement :)</div><div><br></div><div dir="auto">Is there any way to get the reference count of an object just to double check it is not referenced anymore?</div><div dir="auto"><br></div><div>Thank you</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il Sab 30 Lug 2022, 21:59 Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;"><div><br></div> Yes, as you describe below. <br><div><br><blockquote type="cite"><div>On Jul 30, 2022, at 4:31 PM, Edoardo alinovi <<a href="mailto:edoardo.alinovi@gmail.com" rel="noreferrer" target="_blank">edoardo.alinovi@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Hello Barry,<div><br></div><div><i><b> I assume you are calling KSPSetOperators() before each new KSPSolve() so that it knows to solve a new system?</b></i><br></div><div><i><b><br></b></i></div><div>Yes, I do.</div><div><br></div><div>This looks like a good trick: KSPSetOperators(ksp,PETSC_NULL_MAT,PETSC_NULL_MAT)</div><div><br></div><div>So you would do: </div><div><br></div><div>1) KSPSetOperators(ksp,A,A)<br></div><div><br></div><div>2) KSPSolve(myksp, myrhs, mysol)<br></div><div><br></div><div>3) KSPSetOperators(ksp,PETSC_NULL_MAT,PETSC_NULL_MAT)<br></div><div><br></div><div>4) MatDestroy(A)</div><div><br></div><div>Am I right?</div><div><br></div><div>I'll have a try and I'll try to destroy the ksp of each equation as well. The second is more tedious because I'll have to reconstruct it every time. I'll do some tests to see if that helps. </div><div><br></div><div>Thanks a lot! </div><div><br></div><div><br></div><div><br></div></div>
</div></blockquote></div><br></div></blockquote></div>