Skip to content

Commit

Permalink
Do not a priori allocate memory for objects that will later be re-sized.
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
bangerth committed Oct 21, 2021
1 parent c0262b0 commit fb3bb0e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/numerics/data_out.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ DataOut<dim, spacedim>::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<Point<spacedim>> &q_points =
fe_patch_values.get_quadrature_points();
Expand Down
10 changes: 3 additions & 7 deletions source/numerics/data_out_faces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ DataOutFaces<dim, spacedim>::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<dim - 1>::vertices_per_cell;
for (unsigned int vertex = 0; vertex < cell->face(face_number)->n_vertices();
++vertex)
patch.vertices[vertex] =
data.mapping_collection[0].transform_unit_to_real_cell(
Expand All @@ -132,9 +131,9 @@ DataOutFaces<dim, spacedim>::build_one_patch(
Assert(patch.space_dim == dim, ExcInternalError());
const std::vector<Point<dim>> &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;
Expand Down Expand Up @@ -395,9 +394,6 @@ DataOutFaces<dim, spacedim>::build_patches(
update_flags);
DataOutBase::Patch<patch_dim, patch_spacedim> sample_patch;
sample_patch.n_subdivisions = n_subdivisions;
sample_patch.data.reinit(n_datasets,
Utilities::fixed_power<patch_dim>(n_subdivisions +
1));

// now build the patches in parallel
WorkStream::run(
Expand Down

0 comments on commit fb3bb0e

Please sign in to comment.