[petsc-dev] Inquiry about PETSc Memory Accumulation Issue and Undefined Reference to `petscgarbagecleanup_`

Pierre Jolivet pierre at joliv.et
Mon Sep 29 00:25:10 CDT 2025



> On 29 Sep 2025, at 5:20 AM, Wang Lei <workPCn1 at outlook.com> wrote:
> 
> Dear PETSc Development Team,
> 
> I hope this message finds you well.
> 
> I am writing to seek your technical assistance regarding two related issues I have encountered while using PETSc in my application.
> 
> ## 1. Memory Accumulation Issue
> 
> My application experiences gradual memory accumulation when performing multiple successive simulations. I've observed that PETSc objects (vectors, matrices, etc.) are not being completely cleaned up between simulation runs, even though I call the appropriate destroy functions.
> 
> Could you please advise:
> - Are there any known issues with memory accumulation in repeated PETSc usage scenarios?

No, it usually appears in user code when PETSc objects are not being destroyed.
What do you get with -malloc_dump?
Do you get matching creations and destructions of PETSc objects in -log_view?

> - What would be the recommended approach to ensure complete cleanup between multiple simulation cycles?

See above.

> - Are there any internal cleanup routines that should be called periodically?

No, internal objects are cleaned up when not needed anymore.
User objects must be destroyed by the user.

> ## 2. Undefined Reference to `petscgarbagecleanup_`
> 
> While investigating the memory issue, I came across references to the `petscgarbagecleanup_` function in documentation, which appears to be tagged as a "developer" function. However, I'm unable to link against this function in my build.
> 
> Here's what I've tried:
> - Verified PETSc installation and basic functionality
> - Checked for the symbol in libpetsc.so <https://urldefense.us/v3/__http://libpetsc.so/__;!!G_uCfscf7eWS!cnhs8_def98hEXUcu7db_dUl4wDZViRIsC1M4jFgboEXGxP7pO-UUb7GktTm-frn81Z5rs5ZZz1xiq2saC2dbg$ > using `nm -gA` - the function is not present
> - Tried rebuilding PETSc with `--with-debugging=0` configuration option
> - Ensured proper compiler and environment consistency
> 
> My environment:
> - PETSc Version: 3.23
> - Operating System: Ubuntu
> - Compiler: Intel OneAPI with MPI and MKL
> - Installation Method: Source Code from git
> - Configuration options used: ./configure --with-cc=mpicc --with-cxx=mpicxx --with-fc=mpiifort --prefix=/home/icer/petsc-3.23 --with-scalar-type=complex --download-slepc=yes --download-mumps=yes --with-scalapack-dir=$MKLROOT --download-parmetis=yes --download-metis=yes --download-arpack=yes --force --with-debugging=0
> 
> Questions:
> - Is `petscgarbagecleanup_` a function that requires special configuration flags to be available?

It’s only available in Python, so you’ll need --with-petsc4py and anyway, you won’t be able to call this from C/Fortran code (note that --download-arpack is useless, this must be passed to SLEPc configure)

> - Are there alternative functions or approaches to force comprehensive garbage collection in PETSc?

PETSc has not garbage collector.

> - Could this be related to my specific PETSc configuration?

Highly unlikely, check -malloc_dump and -log_view first.

Thanks,
Pierre

> I would greatly appreciate any insights or suggestions you might have on resolving these issues. The memory accumulation is particularly critical for my long-running application workflows.
> 
> Thank you for your time and assistance.
> 
> Best regards,
> 
> Lei Wang

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20250929/b5e45af3/attachment-0001.html>


More information about the petsc-dev mailing list