trixi-framework / Trixi.jl

Trixi.jl: Adaptive high-order numerical simulations of conservation laws in Julia
https://trixi-framework.github.io/Trixi.jl
MIT License
505 stars 98 forks source link

Reduce memory allocations in AMR #161

Open ranocha opened 3 years ago

ranocha commented 3 years ago

Currently, we create completely new solution arrays when refining and coarsening (the solver).

sloede commented 3 years ago

Here are my initial thoughts on this issue:

ranocha commented 3 years ago

You're definitely right - we should do some careful benchmarks before trying to optimize stuff that isn't worth it.I just thought that allocation 679MiB on average per call looks like it might be worth the effort to reduce the allocations.

sloede commented 3 years ago

allocation 679MiB on average per call looks like it might be worth

No, you're right. This should at least be motivation enough to be investigated once. The downside is that it would require the elements container to be larger than strictly necessary to account for future growth. Thus, e.g., nelements(elements::ElementContainer2D) = length(elements.cell_ids) will not be possible anymore. This might be OK, but we'd have to make sure that anywhere any of the element variables are accessed, no slicing with :, or size(dg.elements.u, <index_for_element_ids>) is used.

ranocha commented 3 years ago

Moreover, we allocate some temporary arrays - we could also move them to some cache.