From: Rene Gassmoeller Date: Fri, 11 Jun 2021 13:58:12 +0000 (-0400) Subject: Address comments X-Git-Tag: v9.4.0-rc1~1222^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2aa547e0bcde826a7a64fb778ce0582a75dbbdab;p=dealii.git Address comments --- diff --git a/include/deal.II/particles/property_pool.h b/include/deal.II/particles/property_pool.h index 26da5e373e..8d26b445e5 100644 --- a/include/deal.II/particles/property_pool.h +++ b/include/deal.II/particles/property_pool.h @@ -211,8 +211,17 @@ namespace Particles unsigned int n_properties_per_slot() const; + /** + * This function makes sure that all internally stored memory blocks + * are sorted in the same order as one would loop over the @p handles_to_sort + * container. This makes sure memory access is contiguous with actual + * memory location. Because the ordering is given in the input argumet + * the complexity of this function is $O(N)$ where N is the number of + * elements in the input argument. This function creates a temporary copy of + * all currently registered memory blocks. + */ void - sort_memory_slots(std::vector> &sorted_handles); + sort_memory_slots(std::vector> &handles_to_sort); private: /** diff --git a/source/particles/property_pool.cc b/source/particles/property_pool.cc index 94a1906964..20e48d1f96 100644 --- a/source/particles/property_pool.cc +++ b/source/particles/property_pool.cc @@ -59,7 +59,7 @@ namespace Particles " open handles to memory that was allocated " "via allocate_properties_array() but that has " "not been returned via " - "deallocate_properties_array().")); + "deregister_particle().")); } // Clear vectors and ensure deallocation of memory @@ -170,35 +170,39 @@ namespace Particles template void PropertyPool::sort_memory_slots( - std::vector> &sorted_handles) + std::vector> &handles_to_sort) { - std::vector> sorted_locations(locations.size()); - std::vector> sorted_reference_locations( - reference_locations.size()); - std::vector sorted_ids(ids.size()); - std::vector sorted_properties(properties.size()); - - unsigned int i = 0; - for (auto &handles_in_cell : sorted_handles) + std::vector> sorted_locations; + std::vector> sorted_reference_locations; + std::vector sorted_ids; + std::vector sorted_properties; + + sorted_locations.reserve(locations.size()); + sorted_reference_locations.reserve(reference_locations.size()); + sorted_ids.reserve(ids.size()); + sorted_properties.reserve(properties.size()); + + Handle i = 0; + for (auto &handles_in_cell : handles_to_sort) for (auto &handle : handles_in_cell) { Assert(handle != invalid_handle, ExcMessage( "Invalid handle detected during sorting particle memory.")); - sorted_locations[i] = locations[handle]; - sorted_reference_locations[i] = reference_locations[handle]; - sorted_ids[i] = ids[handle]; + sorted_locations.push_back(locations[handle]); + sorted_reference_locations.push_back(reference_locations[handle]); + sorted_ids.push_back(ids[handle]); for (unsigned int j = 0; j < n_properties; ++j) - sorted_properties[i * n_properties + j] = - properties[handle * n_properties + j]; + sorted_properties.push_back(properties[handle * n_properties + j]); handle = i; ++i; } - Assert(i == locations.size() - currently_available_handles.size(), + Assert(sorted_locations.size() == + locations.size() - currently_available_handles.size(), ExcMessage( "Number of sorted property handles is not equal to number " "of currently registered handles.")); @@ -208,17 +212,7 @@ namespace Particles ids.swap(sorted_ids); properties.swap(sorted_properties); - // Now update the available handles - for (auto &available_handle : currently_available_handles) - { - available_handle = i; - ++i; - } - - Assert(i == locations.size(), - ExcMessage("Number of allocated handles does not match number " - "of registered handles plus number of unregistered " - "but available handles.")); + currently_available_handles.clear(); }