FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
776 stars 181 forks source link

Reduce dynamic memory allocation inside tight loops in PlazaRefinementND #43

Closed garth-wells closed 6 months ago

garth-wells commented 6 years ago

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.

chrisrichardson commented 6 years ago

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});

garth-wells commented 6 years ago

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

nils-imhoff commented 1 year ago

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

chrisrichardson commented 1 year ago

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