Memory - sparse matrix

Hi,

Im using Python37 through Jupyter Notebook with the netgen/ngsolve packages to do finite elements, this part is working but I want to be able to approximate the memory usage of my code. If you are aware of a way to have python profile it please let me know but I couldn’t find a way that would work with my set up. If not I would like to know how ngsolve stores its sparse matrices, and how to calculate that?

Many thanks

Hi,
some classes have implemented a memory profiling interface (BilinearForm, LinearForm, GridFunction,…)
You can get it by calling the memory property of them for example:

a = BilinearForm(fes)
...
a.Assemble()
print(a.__memory__)

gives something like

[('SparseMatrix bf biform_from_py low-order', 1352, 1), ('SparseMatrix bf biform_from_py', 24200, 1)]

meaning that the sparse matrix uses 24200 bytes in 1 block and the low order matrix (used in some preconditioners,…) needs 1352 bytes in 1 block.

Best
Christopher

Hi, thanks for replying so quick. When I tried your suggestion I got the following error:

AttributeError: ‘ngsolve.comp.BilinearForm’ object has no attribute ‘memory

my ‘a’ is defined as:

a=BilinearForm(fes,symmetric=False)
a+=SymbolicBFI(grad(u)*grad(v))
a.Assemble()

on a unit square. Did this memory tool get added recently?

Yes, git says 2018-09-18. So it should be in the latest version v6.2.1809

Best
Christopher

Thanks!