From 45b62f0cbb2510be8b9fa10043d093eba18f5713 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 24 Oct 2023 12:47:11 -0600 Subject: [PATCH] Minor clean-up in dof_info.cc. --- source/matrix_free/dof_info.cc | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/source/matrix_free/dof_info.cc b/source/matrix_free/dof_info.cc index 83c399bfbf..433e501368 100644 --- a/source/matrix_free/dof_info.cc +++ b/source/matrix_free/dof_info.cc @@ -1285,29 +1285,30 @@ namespace internal const unsigned int n_components = dof_info.start_components.back(); for (unsigned int block = begin; block < end; ++block) { - scratch.clear(); - scratch.insert( - scratch.end(), + scratch.assign( dof_info.dof_indices.data() + dof_info.row_starts[block * n_components].first, dof_info.dof_indices.data() + dof_info.row_starts[(block + 1) * n_components].first); std::sort(scratch.begin(), scratch.end()); - std::vector::const_iterator end_unique = + + const std::vector::const_iterator end_unique = std::unique(scratch.begin(), scratch.end()); - std::vector::const_iterator it = scratch.begin(); - while (it != end_unique) + for (std::vector::const_iterator it = scratch.begin(); + it != end_unique; + /* update in loop body */) { // In this code, the procedure is that we insert all elements // that are within the range of one lock at once const unsigned int next_bucket = (*it / bucket_size_threading + 1) * bucket_size_threading; + std::lock_guard lock( mutexes[*it / bucket_size_threading]); for (; it != end_unique && *it < next_bucket; ++it) { AssertIndexRange(*it, row_lengths.size()); - row_lengths[*it]++; + ++row_lengths[*it]; } } } @@ -1325,21 +1326,22 @@ namespace internal const unsigned int n_components = dof_info.start_components.back(); for (unsigned int block = begin; block < end; ++block) { - scratch.clear(); - scratch.insert( - scratch.end(), + scratch.assign( dof_info.dof_indices.data() + dof_info.row_starts[block * n_components].first, dof_info.dof_indices.data() + dof_info.row_starts[(block + 1) * n_components].first); std::sort(scratch.begin(), scratch.end()); - std::vector::const_iterator end_unique = + + const std::vector::const_iterator end_unique = std::unique(scratch.begin(), scratch.end()); - std::vector::const_iterator it = scratch.begin(); - while (it != end_unique) + for (std::vector::const_iterator it = scratch.begin(); + it != end_unique; + /* update in loop body */) { const unsigned int next_bucket = (*it / bucket_size_threading + 1) * bucket_size_threading; + std::lock_guard lock( mutexes[*it / bucket_size_threading]); for (; it != end_unique && *it < next_bucket; ++it) -- 2.39.5