[petsc-users] On MatDestroy() in Fortran

Edoardo alinovi edoardo.alinovi at gmail.com
Sun Jul 31 04:22:32 CDT 2022


Hello Barry,

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.

I attach here the memory traces of my code:
- baseline (each equation keep the matrix and does not destroy KSP)
- With KSPSetOperators(ksp, PETSC_NULL_MAT,PETSC_NULL_MAT)
- With KSPDestroy() before MatDestroy()

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 :)

Is there any way to get the reference count of an object just to double
check it is not referenced anymore?

Thank you

Il Sab 30 Lug 2022, 21:59 Barry Smith <bsmith at petsc.dev> ha scritto:

>
>   Yes, as you describe below.
>
> On Jul 30, 2022, at 4:31 PM, Edoardo alinovi <edoardo.alinovi at gmail.com>
> wrote:
>
> Hello Barry,
>
> * I assume you are calling KSPSetOperators() before each new KSPSolve() so
> that it knows to solve a new system?*
>
> Yes, I do.
>
> This looks like a good trick:
> KSPSetOperators(ksp,PETSC_NULL_MAT,PETSC_NULL_MAT)
>
> So you would do:
>
> 1) KSPSetOperators(ksp,A,A)
>
> 2) KSPSolve(myksp, myrhs, mysol)
>
> 3) KSPSetOperators(ksp,PETSC_NULL_MAT,PETSC_NULL_MAT)
>
> 4) MatDestroy(A)
>
> Am I right?
>
> 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.
>
> Thanks a lot!
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220731/dc8503ab/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: baseline.PNG
Type: image/png
Size: 304879 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220731/dc8503ab/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KSPDestroy.PNG
Type: image/png
Size: 349978 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220731/dc8503ab/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: setOperatorsNULL.PNG
Type: image/png
Size: 304854 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220731/dc8503ab/attachment-0005.png>


More information about the petsc-users mailing list