From: Wolfgang Bangerth Date: Tue, 24 Oct 2023 18:47:11 +0000 (-0600) Subject: Minor clean-up in dof_info.cc. X-Git-Tag: relicensing~363^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16183%2Fhead;p=dealii.git Minor clean-up in dof_info.cc. --- 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)