[petsc-users] Matrix assembly in SNES problem
Adolfo Rodriguez
adantra at gmail.com
Wed Jul 22 08:08:57 CDT 2020
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.
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.
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.
Hopefully, this clarifies my question a little bit.
Adolfo
On Wed, Jul 22, 2020 at 7:45 AM Mark Adams <mfadams at lbl.gov> wrote:
>
>
> On Wed, Jul 22, 2020 at 8:05 AM Adolfo Rodriguez <adantra at gmail.com>
> wrote:
>
>> 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.
>>
>> My FormJacobian function is something like this:
>>
>> .. FormJacobian( ..){
>> matrixconstruction(); // returns csr matrix in c++ regular vectors
>> MatSeqAIJSetPreallocationCSR ...;
>> //loop over the entries and
>> MatSetValues;
>> MatAssemblyBegin();
>> MatAssemblyEnd();
>> return 0;
>> }
>>
>> This approach works for small problems but, when dealing with large ones
>> I observe a memory leak.
>>
>
> 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.
>
>
>> 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.
>>
>
> You don't create the matrix in FormJacobian, do you?
> 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.
>
>
>>
>> Any suggestions?
>>
>> Regards,
>>
>> Adolfo
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20200722/eec70e8c/attachment.html>
More information about the petsc-users
mailing list