memory issues (python bindings or internal?)
There is either an issue with the python bindings for alu (not there for Yasp) or some cache that is not cleanedup after usage in Alugrid. Consider the test script
from memory_profiler import profile
import gc, sys
from dune.grid import cartesianDomain
N = 150
domain = cartesianDomain([-1]*2, [1]*2, [N]*2)
@profile(precision=8)
def op(domain, hierarchicGrid):
if not domain:
domain = cartesianDomain([-1]*2, [1]*2, [N]*2)
view = hierarchicGrid(domain)
gc.collect()
print("======================================== profile Yasp")
from dune.grid import yaspGrid as hierarchicGrid
for i in range(15):
op(domain,hierarchicGrid)
gc.collect()
print("======================================== profile ALU - cartesianDomain")
from dune.alugrid import aluSimplexGrid as hierarchicGrid
"""
for i in range(15):
op(domain,hierarchicGrid)
gc.collect()
"""
print("======================================== profile ALU - GridFactory")
vertices = []
for i in range(N+1):
for j in range(N+1):
vertices += [[float(i),float(j)]]
simplices = []
for i in range(N):
for j in range(N):
simplices += [[i*N+j,i*N+j+1,(i+1)*N+j]]
simplices += [[(i+1)*N+j,(i+1)*N+j+1,i*N+j+1]]
domain = {"vertices":vertices, "simplices":simplices}
for i in range(15):
op(domain,hierarchicGrid)
gc.collect()
print("======================================== profile ALU - cartesianDomain II")
for i in range(15):
op(None,hierarchicGrid)
gc.collect()
running python memALUGrid.py |& grep profil
:
======================================== profile Yasp
9 73.48437500 MiB 73.48437500 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.55859375 MiB 81.55859375 MiB 1 @profile(precision=8)
9 81.57812500 MiB 81.57812500 MiB 1 @profile(precision=8)
9 81.57812500 MiB 81.57812500 MiB 1 @profile(precision=8)
9 81.57812500 MiB 81.57812500 MiB 1 @profile(precision=8)
9 81.57812500 MiB 81.57812500 MiB 1 @profile(precision=8)
9 81.57812500 MiB 81.57812500 MiB 1 @profile(precision=8)
======================================== profile ALU - cartesianDomain
======================================== profile ALU - GridFactory
9 92.82812500 MiB 92.82812500 MiB 1 @profile(precision=8)
9 162.32421875 MiB 162.32421875 MiB 1 @profile(precision=8)
9 165.71484375 MiB 165.71484375 MiB 1 @profile(precision=8)
9 167.42968750 MiB 167.42968750 MiB 1 @profile(precision=8)
9 169.15625000 MiB 169.15625000 MiB 1 @profile(precision=8)
9 170.87500000 MiB 170.87500000 MiB 1 @profile(precision=8)
9 172.60156250 MiB 172.60156250 MiB 1 @profile(precision=8)
9 172.60546875 MiB 172.60546875 MiB 1 @profile(precision=8)
9 172.60937500 MiB 172.60937500 MiB 1 @profile(precision=8)
9 172.61328125 MiB 172.61328125 MiB 1 @profile(precision=8)
9 172.61328125 MiB 172.61328125 MiB 1 @profile(precision=8)
9 171.00781250 MiB 171.00781250 MiB 1 @profile(precision=8)
9 172.59765625 MiB 172.59765625 MiB 1 @profile(precision=8)
9 172.60156250 MiB 172.60156250 MiB 1 @profile(precision=8)
9 172.60156250 MiB 172.60156250 MiB 1 @profile(precision=8)
======================================== profile ALU - cartesianDomain II
9 172.60156250 MiB 172.60156250 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.94140625 MiB 172.94140625 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8)
9 172.95312500 MiB 172.95312500 MiB 1 @profile(precision=8
The amount of memory used depends on N. With N=250
the YaspGrid is still constant 9 81.66796875 MiB 81.66796875 MiB
while Alu grows:
9 115.03906250 MiB 115.03906250 MiB 1 @profile(precision=8)
9 284.74218750 MiB 284.74218750 MiB 1 @profile(precision=8)
9 295.89453125 MiB 295.89453125 MiB 1 @profile(precision=8)
9 300.75390625 MiB 300.75390625 MiB 1 @profile(precision=8)
9 305.39453125 MiB 305.39453125 MiB 1 @profile(precision=8)
9 310.31250000 MiB 310.31250000 MiB 1 @profile(precision=8)
9 315.09375000 MiB 315.09375000 MiB 1 @profile(precision=8)
9 319.68359375 MiB 319.68359375 MiB 1 @profile(precision=8)
9 322.26562500 MiB 322.26562500 MiB 1 @profile(precision=8)
9 326.54687500 MiB 326.54687500 MiB 1 @profile(precision=8)
9 328.76953125 MiB 328.76953125 MiB 1 @profile(precision=8)
9 333.73437500 MiB 333.73437500 MiB 1 @profile(precision=8)
9 338.31640625 MiB 338.31640625 MiB 1 @profile(precision=8)
9 340.71093750 MiB 340.71093750 MiB 1 @profile(precision=8)
9 343.27734375 MiB 343.27734375 MiB 1 @profile(precision=8)
======================================== profile ALU - cartesianDomain II
9 345.49218750 MiB 345.49218750 MiB 1 @profile(precision=8)
9 348.36718750 MiB 348.36718750 MiB 1 @profile(precision=8)
9 350.57421875 MiB 350.57421875 MiB 1 @profile(precision=8)
9 352.94921875 MiB 352.94921875 MiB 1 @profile(precision=8)
9 355.55468750 MiB 355.55468750 MiB 1 @profile(precision=8)
9 357.76171875 MiB 357.76171875 MiB 1 @profile(precision=8)
9 360.15625000 MiB 360.15625000 MiB 1 @profile(precision=8)
9 362.68750000 MiB 362.68750000 MiB 1 @profile(precision=8)
9 365.10937500 MiB 365.10937500 MiB 1 @profile(precision=8)
9 367.16796875 MiB 367.16796875 MiB 1 @profile(precision=8)
9 369.87890625 MiB 369.87890625 MiB 1 @profile(precision=8)
9 372.25781250 MiB 372.25781250 MiB 1 @profile(precision=8)
9 374.69531250 MiB 374.69531250 MiB 1 @profile(precision=8)
9 376.87890625 MiB 376.87890625 MiB 1 @profile(precision=8)
9 377.41015625 MiB 377.41015625 MiB 1 @profile(precision=8)
So generating a yaspgrid takes up 8M which is not freed (pybind11 and the typeregistry possibly). While Alugrid adds +300M