]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only resort if necessary
authorRene Gassmoeller <rene.gassmoeller@mailbox.org>
Wed, 9 Jun 2021 16:01:27 +0000 (12:01 -0400)
committerRene Gassmoeller <rene.gassmoeller@mailbox.org>
Sat, 12 Jun 2021 03:28:17 +0000 (23:28 -0400)
source/particles/particle_handler.cc
source/particles/property_pool.cc

index 52d47fc513d2a782fa143275092352273c2fd6a7..f41ada5324cfe078f368c193a027e5fcd3b4bfb7 100644 (file)
@@ -1291,7 +1291,35 @@ namespace Particles
 
     // remove_particles also calls update_cached_numbers()
     remove_particles(particles_out_of_cell);
-    property_pool->sort_memory_slots(particles);
+
+    // Sort the particle memory if we noticed during sorting
+    // the particles above that more than 10% of particle
+    // handles are non-consecutive. We do not want to do this
+    // if it is not necessary, because it involves a copy of
+    // all particle memory.
+    types::particle_index                        n_fragmented_handles = 0;
+    typename PropertyPool<dim, spacedim>::Handle last_handle =
+      PropertyPool<dim, spacedim>::invalid_handle;
+    for (const auto &particles_in_cell : particles)
+      for (const auto &particle : particles_in_cell)
+        {
+          if (last_handle == PropertyPool<dim, spacedim>::invalid_handle)
+            {
+              last_handle = particle;
+              continue;
+            }
+
+          if (particle != last_handle + 1)
+            ++n_fragmented_handles;
+
+          last_handle = particle;
+        }
+
+    if (n_fragmented_handles > n_locally_owned_particles() / 3)
+      {
+        property_pool->sort_memory_slots(particles);
+      }
+
   } // namespace Particles
 
 
index 94a1906964452aa08c5f30c44c6db34c0a43e96f..950a70b8a5272d62552412e4e33a2f6600e40db3 100644 (file)
@@ -178,7 +178,7 @@ namespace Particles
     std::vector<types::particle_index> sorted_ids(ids.size());
     std::vector<double>                sorted_properties(properties.size());
 
-    unsigned int i = 0;
+    Handle i = 0;
     for (auto &handles_in_cell : sorted_handles)
       for (auto &handle : handles_in_cell)
         {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.