]> https://gitweb.dealii.org/ - dealii.git/commitdiff
AffineConstraints: Improve loop 17699/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 12 Sep 2024 20:16:37 +0000 (22:16 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 12 Sep 2024 20:17:03 +0000 (22:17 +0200)
include/deal.II/lac/affine_constraints.templates.h

index e75850c92dd20862e02f41c826f755ec17d4b450..07c6aacae841bf672eae7d24a913c58b27c956c6 100644 (file)
@@ -482,18 +482,32 @@ namespace internal
 
           std::vector<ConstraintLine> data;
 
-          for (const types::global_dof_index index : indices)
+          auto i = indices.begin();
+
+          auto j = std::lower_bound(locally_relevant_constraints.begin(),
+                                    locally_relevant_constraints.end(),
+                                    *i,
+                                    [&](const auto &a, const auto &b) {
+                                      return a.index < b;
+                                    });
+
+          for (; (i != indices.end()) &&
+                 (j != locally_relevant_constraints.end());)
             {
-              // note: at this stage locally_relevant_constraints still
-              // contains only locally owned constraints
-              const typename std::vector<ConstraintLine>::iterator ptr =
-                std::find_if(locally_relevant_constraints.begin(),
-                             locally_relevant_constraints.end(),
-                             [index](const auto &a) {
-                               return a.index == index;
-                             });
-              if (ptr != locally_relevant_constraints.end())
-                data.push_back(*ptr);
+              if (*i == j->index)
+                {
+                  data.push_back(*j);
+                  ++i;
+                  ++j;
+                }
+              else if (*i < j->index)
+                {
+                  ++i;
+                }
+              else
+                {
+                  ++j;
+                }
             }
 
           send_data[destination] = std::move(data);

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.