<div dir="ltr">I am on windows. I am detecting the memory leak through the windows resource monitor, I can see the memory utilization going up during the iteration. Memory utilization goes down after the destruction of SNES, the solution vector and residual, but ends higher than at the beginning. <div><br></div><div>Within FormJacobian I call a function that creates the Jacobian in c++ objects which I use to popular the PETSc Jacobian matrix as indicated above. I don't create the Jacobian beforehand.</div><div><br></div><div>I am not using PETSc for the time-stepping part of the problem so I am not sure if I can use TSSetPostStep and TSSetPreStep.</div><div><br></div><div>Hopefully, this clarifies my question a little bit.</div><div><br></div><div>Adolfo</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 7:45 AM Mark Adams <<a href="mailto:mfadams@lbl.gov">mfadams@lbl.gov</a>> wrote:<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 dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 22, 2020 at 8:05 AM Adolfo Rodriguez <<a href="mailto:adantra@gmail.com" target="_blank">adantra@gmail.com</a>> wrote:<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 dir="ltr">I am trying to replace the non-linear solver in a flow simulation problem where the matrix sparsity can change during the iterations. I tried successfully to create the matrix within the FormJacobian function but I have a memory leak which I don't know how to fix.<div><br></div><div>My FormJacobian function is something like this:</div><div><br></div><div>.. FormJacobian( ..){</div><div>     matrixconstruction(); // returns csr matrix in c++ regular vectors</div><div>     MatSeqAIJSetPreallocationCSR ...;</div><div>     //loop over the entries and </div><div>     MatSetValues;</div><div>     MatAssemblyBegin();</div><div>     MatAssemblyEnd();</div><div>     return 0;</div><div>}</div><div><br></div><div>This approach works for small problems but, when dealing with large ones I observe a memory leak. </div></div></blockquote><div><br></div><div>How are you detecting a memory leak? It's odd that you would not see it on a small problem. You can run with -malloc_debug to get a listing of PETSc memory that was not freed.</div><div> <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 dir="ltr"><div>I am pretty sure that It is related to the fact that I am creating new matrices every time FormJacobian is called but I don't know how to destroy it between iterations.</div></div></blockquote><div><br></div><div>You don't create the matrix in FormJacobian, do you? </div><div>Do your changes (eg, AMR) before or after the time step (you can do this with a TSSetPostStep and TSSetPreStep), then destroy the old matrix and vectors.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><br></div><div>Any suggestions?</div><div><br></div><div>Regards,</div><div><br></div><div>Adolfo</div></div>
</blockquote></div></div>
</blockquote></div>