dolfinx icon indicating copy to clipboard operation
dolfinx copied to clipboard

Reduce dynamic memory allocation inside tight loops in PlazaRefinementND

Open garth-wells opened this issue 6 years ago • 4 comments

The PlazaRefinementND has considerable dynamic memory allocation inside loops over all cells. This should be eliminated for performance.

A data structure that may help is an Eigen::Matrix with an upper limit on the size (https://eigen.tuxfamily.org/dox/group__TutorialMatrixClass.html), e.g.

Eigen::Matrix<int, 1, Dynamic, 0, 1, 16> a;

for a row vector whose size will not exceed 16.

garth-wells avatar Apr 24 '18 15:04 garth-wells

The problem with the Eigen:: structure is that it is not that easy to dynamically add data. cf:

Eigen::Matrix<int, Dynamic, 4, RowMajor, 8, 4> a;

...
a.conservativeResize(a.rows() + 1, NoChange);
a.bottomRows<1>() << i, j, k, l;

versus a.insert(a.end(), {i, j, k, l});

chrisrichardson avatar Apr 30 '18 09:04 chrisrichardson

Can always index into it. I don't much like the Eigen << syntax.

garth-wells avatar Apr 30 '18 09:04 garth-wells

Hi, I wanted to ask if the issue is still current and open?

nils-imhoff avatar Jan 22 '23 11:01 nils-imhoff

It's not high priority. Obviously, we are not using Eigen any more. I've made a branch which reduces the dynamic allocation, but I couldn't see any difference in the run time when refining a large mesh. https://github.com/FEniCS/dolfinx/tree/chris/refinement-alloc

chrisrichardson avatar Jan 22 '23 22:01 chrisrichardson