[petsc-users] Memory leak after reset ksp operators

Karl Yang y.juntao at hotmail.com
Thu Nov 5 00:50:39 CST 2020


Sorry, I've found my problem.
I've been repeatedly doing KSPCreate()...

All is good now.
Regards
Juntao

On Nov 5 2020, at 2:32 pm, Karl Yang <y.juntao at hotmail.com> wrote:
> Hi, I have a solver for time dependent problem and in each forward time step, I do
>
> // after update values in Amat and Pmat / /
> KSPSetOperators(ksp, Amat, Pmat)
> KSPSolve(ksp, rhs, solution)
>
> The program runs and gives correct solution. But I got following memory leak errors from valgrind.
> Do I need to create a new ksp in order to avoid the memory leak? Or is it due to the fieldsplit preconditioner I used?
>
> ==1340== 675,330 (1,232 direct, 674,098 indirect) bytes in 7 blocks are definitely lost in loss record 3,123 of 3,155
> ==1340== at 0x4C320A6: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1340== by 0x4FDDA26: PetscMallocAlign (mal.c:49)
> ==1340== by 0x4FDF3AD: PetscMallocA (mal.c:422)
> ==1340== by 0x6564982: PCCreate_LU (lu.c:241)
> ==1340== by 0x66BD26A: PCSetType (pcset.c:84)
> ==1340== by 0x66BDDF8: PCSetFromOptions (pcset.c:154)
> ==1340== by 0x680DAD0: KSPSetFromOptions (itcl.c:335)
> ==1340== by 0x6606EA7: PCSetUp_FieldSplit (fieldsplit.c:944)
> ==1340== by 0x66B29C4: PCSetUp (precon.c:894)
> ==1340== by 0x68174DF: KSPSetUp (itfunc.c:376)
> ==1340== by 0x681B07D: KSPSolve (itfunc.c:703)
> ==1340== by 0x118F87: stokesSolver::forwardStep() (transient.cpp:1256)
> ==1340==
> ==1340== 851,586 (6,840 direct, 844,746 indirect) bytes in 9 blocks are definitely lost in loss record 3,126 of 3,155
> ==1340== at 0x4C320A6: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1340== by 0x4FDDA26: PetscMallocAlign (mal.c:49)
> ==1340== by 0x4FDF3AD: PetscMallocA (mal.c:422)
> ==1340== by 0x55C6C46: ISCreate (isreg.c:37)
> ==1340== by 0x55B5983: ISCreateGeneral (general.c:627)
> ==1340== by 0x55B1C01: ISInvertPermutation_General (general.c:174)
> ==1340== by 0x55BD8D5: ISInvertPermutation (index.c:481)
> ==1340== by 0x5C275DC: MatLUFactorSymbolic_SeqAIJ (aijfact.c:296)
> ==1340== by 0x57824CF: MatLUFactorSymbolic (matrix.c:3005)
> ==1340== by 0x656311C: PCSetUp_LU (lu.c:109)
> ==1340== by 0x66B29C4: PCSetUp (precon.c:894)
> ==1340== by 0x68174DF: KSPSetUp (itfunc.c:376)
> ==1340==
> ==1340== 979,830 (25,488 direct, 954,342 indirect) bytes in 9 blocks are definitely lost in loss record 3,129 of 3,155
> ==1340== at 0x4C320A6: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1340== by 0x4FDDA26: PetscMallocAlign (mal.c:49)
> ==1340== by 0x4FDF3AD: PetscMallocA (mal.c:422)
> ==1340== by 0x5DC7F7D: MatCreate (gcreate.c:83)
> ==1340== by 0x5C24F29: MatGetFactor_seqaij_petsc (aijfact.c:101)
> ==1340== by 0x5797454: MatGetFactor (matrix.c:4426)
> ==1340== by 0x656308C: PCSetUp_LU (lu.c:108)
> ==1340== by 0x66B29C4: PCSetUp (precon.c:894)
> ==1340== by 0x68174DF: KSPSetUp (itfunc.c:376)
> ==1340== by 0x681B07D: KSPSolve (itfunc.c:703)
> ==1340== by 0x660BDA1: PCApply_FieldSplit_Schur (fieldsplit.c:1180)
> ==1340== by 0x66AC096: PCApply (precon.c:444)
> ==1340==
> ==1340== 1,070,621 (5,320 direct, 1,065,301 indirect) bytes in 7 blocks are definitely lost in loss record 3,134 of 3,155
> ==1340== at 0x4C320A6: memalign (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==1340== by 0x4FDDA26: PetscMallocAlign (mal.c:49)
> ==1340== by 0x4FDF3AD: PetscMallocA (mal.c:422)
> ==1340== by 0x55C6C46: ISCreate (isreg.c:37)
> ==1340== by 0x55B5983: ISCreateGeneral (general.c:627)
> ==1340== by 0x5DA3869: MatGetOrdering_ND (spnd.c:27)
> ==1340== by 0x5DA7712: MatGetOrdering (sorder.c:247)
> ==1340== by 0x6562E19: PCSetUp_LU (lu.c:98)
> ==1340== by 0x66B29C4: PCSetUp (precon.c:894)
> ==1340== by 0x68174DF: KSPSetUp (itfunc.c:376)
> ==1340== by 0x681B07D: KSPSolve (itfunc.c:703)
> ==1340== by 0x660BDA1: PCApply_FieldSplit_Schur (fieldsplit.c:1180)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201105/e10e9b22/attachment.html>


More information about the petsc-users mailing list