From: Wolfgang Bangerth Date: Thu, 15 Jun 2023 23:02:51 +0000 (-0600) Subject: Avoid a quadratic bottleneck in AffineConstraints::distribute(). X-Git-Tag: v9.5.0-rc1~102^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec384923ab543be35b1899a26e2e3ded926aa924;p=dealii.git Avoid a quadratic bottleneck in AffineConstraints::distribute(). --- diff --git a/include/deal.II/lac/affine_constraints.templates.h b/include/deal.II/lac/affine_constraints.templates.h index d0d0adf998..0893dcfded 100644 --- a/include/deal.II/lac/affine_constraints.templates.h +++ b/include/deal.II/lac/affine_constraints.templates.h @@ -2610,11 +2610,19 @@ AffineConstraints::distribute(VectorType &vec) const // following. IndexSet needed_elements = vec_owned_elements; + std::vector additional_elements; for (const ConstraintLine &line : lines) if (vec_owned_elements.is_element(line.index)) for (const std::pair &entry : line.entries) if (!vec_owned_elements.is_element(entry.first)) - needed_elements.add_index(entry.first); + additional_elements.emplace_back(entry.first); + std::sort(additional_elements.begin(), additional_elements.end()); + additional_elements.erase(std::unique(additional_elements.begin(), + additional_elements.end()), + additional_elements.end()); + + needed_elements.add_indices(additional_elements.begin(), + additional_elements.end()); VectorType ghosted_vector; internal::import_vector_with_ghost_elements(