New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poor garbage collection with petsc4py 3.18.3 (was "Memory leak in term.justErrorVector()
", but this isn't strictly a leak)
#896
Comments
Interestingly, this does not appear to happen on my other machine, which has the same version of |
Given that, the leak is likely to be in that build of petsc and not something fipy has control over. What os are you running? Some variant of linux, I assume? What version of Python? FWIW, this does not leak on my MacBook with Python 3.10. |
If the error is With a Dirichlet condition, I do see a small monotonic increase in RAM usage with Either way, 5 GiB is an insane amount of RAM usage for this tiny problem. Do both |
It does seem likely that the issue is in I've attached two files below with my environments that do and don't work: environment_leak.txt Both are using python 3.10.8, and were generated from the following
The version that works only consumes a couple of KiB of ram as it runs. The version that does not work rapidly consumes memory at around 1GiB per 30 seconds I am running this on a |
For the scipy solver, the issue was that I was setting If I don't specify the solver explicitly when I import, then switching between solvers on the fly seems to work. |
I think under some circumstances, it could work, but mixing solver packages is not intended usage. |
OK, thanks for this. If I can reproduce, I'll submit a ticket against |
I can, indeed, reproduce, on both debian and macOS. Something is very wrong with that |
Thank you! I also just checked and the error reproduces with the latest build in |
Running with I eventually remembered trilinos/Trilinos#2327 from five years ago. The same "fix" is not effective, however. |
Thanks for filing this ticket, @Maxwellfire! I encountered a memory leak with petsc4py 3.18 as well, but got lost in other things instead of tracking it down. I see the same leak from your MWE with petsc4py 3.18.3 (conda-forge), but no leaks with 3.16 or 3.17. This helps a lot! |
While not a proper fix, this issue can be mitigated by adding a call to import fipy
from petsc4py import PETSc
mesh = fipy.Grid1D(nx=100, dx=1)
var1 = fipy.CellVariable(mesh=mesh, hasOld=True, value = 1.0)
eq1 = fipy.DiffusionTerm(var = var1, coeff=1.) == 0
for n in range(1,50000):
eq1.justErrorVector()
PETSc.garbage_cleanup() I have identified some things that we should be cleaning up, but they don't completely resolve the leak (without manual |
I realized I wasn't cleaning up the PETSc I have filed https://gitlab.com/petsc/petsc/-/issues/1309 against |
term.justErrorVector()
term.justErrorVector()
", but this isn't strictly a leak)
term.justErrorVector()
", but this isn't strictly a leak)term.justErrorVector()
", but this isn't strictly a leak)
Garbage collection works differently (worse) in petsc4py 3.18.3 than in 3.17.4. Fixes usnistgov#896
Garbage collection works differently (worse) in petsc4py 3.18.3 than in 3.17.4. Fixes usnistgov#896
Garbage collection works differently (worse) in petsc4py 3.18.3 than in 3.17.4. Fixes #896
I'm trying to use a slightly unorthodox solving method that requires me to get the error vector from my set of equations repeatedly. Each time
term.justErrorVector()
is called, it consumes some memory that is never freed.Here is some simple code that reproduces the memory increase for me:
This takes a couple of minutes to run and consumes about 5GiB on my system.
I was going to try the other solver implementations (
pysparse
andscipy
), butpysparse
won't run on python3 andscipy
throws an error (which I can submit a bug report for separately.)The text was updated successfully, but these errors were encountered: