]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid a quadratic bottleneck in AffineConstraints::distribute(). 15366/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 15 Jun 2023 23:02:51 +0000 (17:02 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 16 Jun 2023 16:07:02 +0000 (10:07 -0600)
include/deal.II/lac/affine_constraints.templates.h

index d0d0adf99837c56dae05b38e375dfececf53741d..0893dcfdedcb9ad61487b63e77561ca01c69d61b 100644 (file)
@@ -2610,11 +2610,19 @@ AffineConstraints<number>::distribute(VectorType &vec) const
       // following.
       IndexSet needed_elements = vec_owned_elements;
 
+      std::vector<types::global_dof_index> additional_elements;
       for (const ConstraintLine &line : lines)
         if (vec_owned_elements.is_element(line.index))
           for (const std::pair<size_type, number> &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(

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.