From: Martin Kronbichler Date: Mon, 23 May 2022 10:07:59 +0000 (+0200) Subject: Reduce cost to set up dictionary for compute_index_owner X-Git-Tag: v9.4.0-rc1~160^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13791%2Fhead;p=dealii.git Reduce cost to set up dictionary for compute_index_owner --- diff --git a/include/deal.II/base/mpi_compute_index_owner_internal.h b/include/deal.II/base/mpi_compute_index_owner_internal.h index 20efb739f4..88ea9c88bd 100644 --- a/include/deal.II/base/mpi_compute_index_owner_internal.h +++ b/include/deal.II/base/mpi_compute_index_owner_internal.h @@ -427,13 +427,13 @@ namespace Utilities * out the owner of the index that was requested (using the guess in * `owner_index`, as we typically might look up on the same rank * several times in a row, which avoids the binary search in - * Dictionary::get_owning_rank_index(). Once we know the rank of the - * owner, we the vector entry with the rank of the request. Here, we - * utilize the fact that requests are processed rank-by-rank, so we - * can simply look at the end of the vector if there is already some - * data stored or not. Finally, we build ranges, again using that - * the index list is sorted and we therefore only need to append at - * the end. + * Dictionary::get_owning_rank_index()). Once we know the rank of + * the owner, we fill the vector entry with the rank of the + * request. Here, we utilize the fact that requests are processed + * rank-by-rank, so we can simply look at the end of the vector + * whether there is already some data stored or not. Finally, we + * build ranges, again using that the index list is sorted and we + * therefore only need to append at the end. */ void append_index_origin(const types::global_dof_index index, diff --git a/source/base/mpi_compute_index_owner_internal.cc b/source/base/mpi_compute_index_owner_internal.cc index 92b82a3dd8..f115482350 100644 --- a/source/base/mpi_compute_index_owner_internal.cc +++ b/source/base/mpi_compute_index_owner_internal.cc @@ -47,14 +47,11 @@ namespace Utilities this->use_vector = use_vector; this->size = size; - data.clear(); + data = {}; data_map.clear(); - if (use_vector) - { - data = {}; - data.resize(size, invalid_index_value); - } + // do not initialize the vector but only upon first request in + // `fill` } @@ -70,8 +67,27 @@ namespace Utilities if (use_vector) { - AssertDimension(data.size(), size); - std::fill(data.begin() + start, data.begin() + end, value); + if (data.empty() && end > start) + { + // in debug mode, we want to track whether we set all + // indices, so we first fill an invalid index and only later + // the actual ones, whereas we simply assign the given rank + // to the complete vector the first time we pass around in + // this function in release mode to avoid touching data + // unnecessarily (and overwrite the smaller pieces), as the + // locally owned part comes first +#ifdef DEBUG + data.resize(size, invalid_index_value); + std::fill(data.begin() + start, data.begin() + end, value); +#else + data.resize(size, value); +#endif + } + else + { + AssertDimension(data.size(), size); + std::fill(data.begin() + start, data.begin() + end, value); + } } else { @@ -131,6 +147,9 @@ namespace Utilities if (use_vector) { + if (data.empty()) + return false; + AssertDimension(data.size(), size); return data[index] != invalid_index_value; }