From 2523db8db6981779983c236259498f23c4c9e385 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 21 Oct 2021 17:10:09 -0600 Subject: [PATCH] Do not a priori allocate memory for objects that will later be re-sized. Here, this is the case for a CopyData object to be used in WorkStream: We have to give WorkStrean::run() an exemplar of these CopyData objects from which it will create a concrete object for each task (=cell or face) that will then be worked on. We initialize the exemplar's '.data' object to a concrete size, but this size will later be ignored and instead we resize things to whatever we actually need in one place because we don't really know what the correct size is going to be a priori. As a consequence, just omit the original sizing and leave the 'exemplar.data' object empty until the point where we know the size for a concrete object that we obtain by copying the examplar. As a side note: This is in DataOutFaces. The DataOut class doesn't do the initial sizing -- I suspect that we had that code at some point in the past and got rid of the initial sizing a few years ago but didn't make the same change for DataOutFaces. It is also possible that that change was made as part of the simplex transition in DataOut, but DataOutFaces was never actually transitioned and doesn't work for simplices right now. (That's what I'm working on right now, of course.) --- source/numerics/data_out.cc | 2 +- source/numerics/data_out_faces.cc | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/source/numerics/data_out.cc b/source/numerics/data_out.cc index b874167f07..43f4c3c3cf 100644 --- a/source/numerics/data_out.cc +++ b/source/numerics/data_out.cc @@ -153,7 +153,7 @@ DataOut::build_one_patch( // explicitly given patch.points_are_available = true; - // then resize the patch.data member in order to have enough memory for + // then size the patch.data member in order to have enough memory for // the quadrature points as well, and copy the quadrature points there const std::vector> &q_points = fe_patch_values.get_quadrature_points(); diff --git a/source/numerics/data_out_faces.cc b/source/numerics/data_out_faces.cc index c125a45d6c..aaca186ddc 100644 --- a/source/numerics/data_out_faces.cc +++ b/source/numerics/data_out_faces.cc @@ -112,9 +112,7 @@ DataOutFaces::build_one_patch( // on cells, not faces, so transform the face vertex to a cell vertex, that // to a unit cell vertex and then, finally, that to the mapped vertex. In // most cases this complicated procedure will be the identity. - for (unsigned int vertex = 0; - vertex < GeometryInfo::vertices_per_cell; - ++vertex) + for (const unsigned int vertex : cell->face(face_number)->vertex_indices()) { const Point vertex_reference_coordinates = cell->reference_cell().template vertex( @@ -144,9 +142,9 @@ DataOutFaces::build_one_patch( Assert(patch.space_dim == dim, ExcInternalError()); const std::vector> &q_points = fe_patch_values.get_quadrature_points(); - // resize the patch.data member in order to have enough memory for the + // size the patch.data member in order to have enough memory for the // quadrature points as well - patch.data.reinit(data.n_datasets + dim, patch.data.size(1)); + patch.data.reinit(data.n_datasets + dim, q_points.size()); // set the flag indicating that for this cell the points are explicitly // given patch.points_are_available = true; @@ -406,9 +404,6 @@ DataOutFaces::build_patches( update_flags); DataOutBase::Patch sample_patch; sample_patch.n_subdivisions = n_subdivisions; - sample_patch.data.reinit(n_datasets, - Utilities::fixed_power(n_subdivisions + - 1)); // now build the patches in parallel WorkStream::run( -- 2.39.5