From fa51efbe3c4c17ebf5e831ceee35c729ec520d47 Mon Sep 17 00:00:00 2001 From: Bruno Date: Tue, 9 Feb 2021 22:20:08 -0500 Subject: [PATCH] Add recv and send data to particle cache This adds teh recv and send data to the particle cache in order to prevent dynamic reallocation of this vector, whose size is not changing anyway. This can significantly (10%) increase performance in some of our applications --- include/deal.II/particles/partitioner.h | 12 ++++++++++++ source/particles/particle_handler.cc | 12 +++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/deal.II/particles/partitioner.h b/include/deal.II/particles/partitioner.h index 46ee1def56..f4361a3ae1 100644 --- a/include/deal.II/particles/partitioner.h +++ b/include/deal.II/particles/partitioner.h @@ -97,6 +97,18 @@ namespace Particles std::vector>::iterator> ghost_particles_iterators; + + /** + * Vector of char that is used to organize the particle information to be + * sent to other processors + */ + std::vector send_data; + + /** + * Vector of char that is used to organize the particle information to + * received from other processors + */ + std::vector recv_data; }; } // namespace internal diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index b135d69a4a..4926f52ce3 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -1521,6 +1521,11 @@ namespace Particles n_recv_data[i] * individual_particle_data_size; ghost_particles_cache.neighbors = neighbors; + + ghost_particles_cache.send_data.resize( + ghost_particles_cache.send_pointers.back()); + ghost_particles_cache.recv_data.resize( + ghost_particles_cache.recv_pointers.back()); } while (reinterpret_cast(recv_data_it) - @@ -1580,13 +1585,11 @@ namespace Particles ExcMessage( "This function is only implemented for parallel::TriangulationBase objects.")); - std::vector send_data; + std::vector &send_data = ghost_particles_cache.send_data; // Fill data to send if (send_pointers.back() > 0) { - // Allocate space for sending particle data - send_data.resize(send_pointers.back()); void *data = static_cast(&send_data.front()); // Serialize the data sorted by receiving process @@ -1599,8 +1602,7 @@ namespace Particles } } - // Set up the space for the received particle data - std::vector recv_data(recv_pointers.back()); + std::vector &recv_data = ghost_particles_cache.recv_data; // Exchange the particle data between domains { -- 2.39.5