From: Martin Kronbichler Date: Mon, 20 Jun 2022 15:06:10 +0000 (+0200) Subject: Query ghost index set only once in Partitioner::global_to_local X-Git-Tag: v9.5.0-rc1~1179^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F14025%2Fhead;p=dealii.git Query ghost index set only once in Partitioner::global_to_local --- 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); + } }