From f07228e9f1ca4bb654c4d0fa6d9066b7b9ccb1d9 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Mon, 20 Jun 2022 17:06:10 +0200 Subject: [PATCH] Query ghost index set only once in Partitioner::global_to_local --- include/deal.II/base/partitioner.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/include/deal.II/base/partitioner.h b/include/deal.II/base/partitioner.h index 5596a99153..8664d39236 100644 --- a/include/deal.II/base/partitioner.h +++ b/include/deal.II/base/partitioner.h @@ -873,15 +873,19 @@ namespace Utilities ExcIndexNotPresent(global_index, my_pid)); if (in_local_range(global_index)) return static_cast(global_index - local_range_data.first); - else if (is_ghost_entry(global_index)) - return (locally_owned_size() + - static_cast( - 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(index_within_ghosts); + } } -- 2.39.5