]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Don't overallocate memory. 15041/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 6 Apr 2023 21:19:21 +0000 (15:19 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 6 Apr 2023 23:13:19 +0000 (17:13 -0600)
source/grid/grid_tools_cache.cc

index 4caa9a671a308efd33aa47277f7a78cf3cf39d30..d6e873cad3d3e29d608e261eebef0b4746fc152a 100644 (file)
@@ -155,7 +155,12 @@ namespace GridTools
           BoundingBox<spacedim>,
           typename Triangulation<dim, spacedim>::active_cell_iterator>>
           boxes;
-        boxes.reserve(tria->n_active_cells());
+        if (const parallel::TriangulationBase<dim, spacedim> *parallel_tria =
+              dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
+                &*tria))
+          boxes.reserve(parallel_tria->n_locally_owned_active_cells());
+        else
+          boxes.reserve(tria->n_active_cells());
         for (const auto &cell : tria->active_cell_iterators() |
                                   IteratorFilters::LocallyOwnedCell())
           boxes.emplace_back(mapping->get_bounding_box(cell), cell);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.