]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Query ghost index set only once in Partitioner::global_to_local 14025/head
authorMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 20 Jun 2022 15:06:10 +0000 (17:06 +0200)
committerMartin Kronbichler <martin.kronbichler@uni-a.de>
Mon, 20 Jun 2022 15:06:10 +0000 (17:06 +0200)
include/deal.II/base/partitioner.h

index 5596a99153d7a0eedbe31b983d858107f37648ad..8664d39236347dca2c84bc116f11c23ec2efc989 100644 (file)
@@ -873,15 +873,19 @@ namespace Utilities
              ExcIndexNotPresent(global_index, my_pid));
       if (in_local_range(global_index))
         return static_cast<unsigned int>(global_index - local_range_data.first);
-      else if (is_ghost_entry(global_index))
-        return (locally_owned_size() +
-                static_cast<unsigned int>(
-                  ghost_indices_data.index_within_set(global_index)));
       else
-        // should only end up here in optimized mode, when we use this large
-        // number to trigger a segfault when using this method for array
-        // access
-        return numbers::invalid_unsigned_int;
+        {
+          // avoid checking the ghost index set via a binary search twice by
+          // querying the index within set, which returns invalid_dof_index
+          // for non-existent entries
+          const types::global_dof_index index_within_ghosts =
+            ghost_indices_data.index_within_set(global_index);
+          if (index_within_ghosts == numbers::invalid_dof_index)
+            return numbers::invalid_unsigned_int;
+          else
+            return locally_owned_size() +
+                   static_cast<unsigned int>(index_within_ghosts);
+        }
     }
 
 

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.