<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 30 May 2019, at 2:42 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com" class="">knepley@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div dir="ltr" class="">On Thu, May 30, 2019 at 6:08 AM Pierre Jolivet via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" class="">petsc-dev@mcs.anl.gov</a>> wrote:<br class=""></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello,<br class="">
I’m doing a continuation loop with something like:<br class="">
KSP ksp;<br class="">
KSPSetUp(ksp);<br class="">
while(cond) {<br class="">
        SNES snes;<br class="">
        SNESCreate(&snes);<br class="">
        SNESSetKSP(snes, &ksp);<br class="">
        SNESSolve(snes);<br class="">
        SNESDestroy(&snes);<br class="">
}<br class="">
<br class="">
For the first iteration, everything is OK.<br class="">
After that, it looks like SNESDestroy is messing up with my outer-defined KSP(*), i.e., for the code to work I need to comment out the SNESDestroy.<br class="">
Is this the expected behavior? (if not, I’ll provide a MWE)<br class="">
How to fix this properly, without having leaks by not destroying the inner-defined SNESes?<br class="">
<br class="">
Thanks in advance,<br class="">
Pierre<br class="">
<br class="">
(*) to the outer-defined KSP is attached a PCFIELDSPLIT, first SNESSolve, everything OK:<br class="">
PC Object: 1 MPI processes<br class="">
  type: fieldsplit<br class="">
    FieldSplit with MULTIPLICATIVE composition: total splits = 2<br class="">
<br class="">
Second SNESSolve:<br class="">
[0]PETSC ERROR: PCFieldSplitSetDefaults() Unhandled case, must have at least two fields, not 1</blockquote></div><br clear="all" class=""><div class="">I believe SNESDestroy() calls SNESReset(), which calls KSPReset(), which is wiping out your information.</div></div></div></blockquote><div><br class=""></div><div>OK, I thought there was a reference count in XXXReset, but it looks like it is just in the XXXDestroy. That explains why.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">This pattern is in a lot of places. Destroy calls Reset because it is natural to reuse the code which tears down</div><div class="">the internal structures. Reset calls reset on subobjects because we also want to tear down their internal structures (usually).</div><div class="">Reset wouldn't do what we want on resizing if we left subobjects unreset. However, this chain is causing subobjects to</div><div class="">be wiped clean on Destroy, so that we cannot reuse subobjects.</div><div class=""><br class=""></div><div class="">It would not even work if you change the Destroy to Reset in the continuation loop. However, I think you can hoist all</div><div class="">the SNES setup outside the loop. If you are changing sizes, then the KSP needs to be wiped out anyway.</div></div></div></blockquote><div><br class=""></div><div>Indeed, when I turn on mesh adaptation, I wipe out the KSP myself and set everything again, so no problem.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""> If not, then</div><div class="">you do not need to wipe out the SNES.</div></div></div></blockquote><div><br class=""></div><div>Now, this is more of a limitation of our DSL. I don’t expose PETSc SNES type to users, we just do SNESSolve(my Mat+KSP) in the loop, which Create, Solve, and Destroy.</div><div>But I guess I’ll have to split those steps.</div><div><br class=""></div><div>Thanks,</div><div>Pierre</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">  Thanks,</div><div class=""><br class=""></div><div class="">     Matt</div><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br class="">-- Norbert Wiener</div><div class=""><br class=""></div><div class=""><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank" class="">https://www.cse.buffalo.edu/~knepley/</a><br class=""></div></div></div></div></div></div></div></div>
</div></blockquote></div><br class=""></body></html>