* 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,
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`
}
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
{
if (use_vector)
{
+ if (data.empty())
+ return false;
+
AssertDimension(data.size(), size);
return data[index] != invalid_index_value;
}