From: Rene Gassmoeller Date: Wed, 2 Aug 2023 20:43:36 +0000 (-0400) Subject: Avoid memory allocations in step 68 X-Git-Tag: relicensing~623^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b56fb09f9014e9eb55c0dceca524240104fc6ce7;p=dealii.git Avoid memory allocations in step 68 --- diff --git a/examples/step-68/step-68.cc b/examples/step-68/step-68.cc index 38bd36561b..58d49c5bd7 100644 --- a/examples/step-68/step-68.cc +++ b/examples/step-68/step-68.cc @@ -541,6 +541,7 @@ namespace Step68 Vector local_dof_values(fluid_fe.dofs_per_cell); FEPointEvaluation evaluator(mapping, fluid_fe, update_values); + std::vector> particle_positions; // We loop over all the local particles. Although this could be achieved // directly by looping over all the cells, this would force us @@ -564,7 +565,7 @@ namespace Step68 // This is achieved using FEPointEvaluation object. const auto pic = particle_handler.particles_in_cell(cell); Assert(pic.begin() == particle, ExcInternalError()); - std::vector> particle_positions; + particle_positions.clear(); for (auto &p : pic) particle_positions.push_back(p.get_reference_location()); diff --git a/tests/performance/timing_step_68.cc b/tests/performance/timing_step_68.cc index 632fbf9711..3527985f4f 100644 --- a/tests/performance/timing_step_68.cc +++ b/tests/performance/timing_step_68.cc @@ -324,6 +324,7 @@ namespace Step68 Vector local_dof_values(fluid_fe.dofs_per_cell); FEPointEvaluation evaluator(mapping, fluid_fe, update_values); + std::vector> particle_positions; const double this_mpi_process = static_cast(Utilities::MPI::this_mpi_process(mpi_communicator)); @@ -339,7 +340,7 @@ namespace Step68 const auto pic = particle_handler.particles_in_cell(cell); Assert(pic.begin() == particle, ExcInternalError()); - std::vector> particle_positions; + particle_positions.clear(); for (auto &p : pic) particle_positions.push_back(p.get_reference_location());