]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Validate correctness of input arguments.
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 13 Jan 2022 04:50:54 +0000 (21:50 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 16 Jan 2022 20:19:44 +0000 (13:19 -0700)
include/deal.II/base/mpi_consensus_algorithms.templates.h

index 1e216c979a233e2646e9b7d9564bbeb9e4d1994c..e7982b81d4a39898ff4bda1a7e26fffa058fba70 100644 (file)
@@ -150,7 +150,21 @@ namespace Utilities
       {
 #ifdef DEAL_II_WITH_MPI
         // 1)
-        targets              = this->process.compute_targets();
+        targets = this->process.compute_targets();
+        Assert(
+          [this]() {
+            std::vector<unsigned int> my_destinations = this->targets;
+            const unsigned int        n_destinations  = my_destinations.size();
+            std::sort(my_destinations.begin(), my_destinations.end());
+            my_destinations.erase(std::unique(my_destinations.begin(),
+                                              my_destinations.end()),
+                                  my_destinations.end());
+            return (my_destinations.size() == n_destinations);
+          }(),
+          ExcMessage("The consensus algorithms expect that each process "
+                     "only sends a single message to another process, "
+                     "but the targets provided include duplicates."));
+
         const auto n_targets = targets.size();
 
         const int tag_request = Utilities::MPI::internal::Tags::
@@ -428,14 +442,29 @@ namespace Utilities
       PEX<T1, T2>::start_communication()
       {
 #ifdef DEAL_II_WITH_MPI
-        // 1) determine with which processes this process wants to communicate
-        targets = this->process.compute_targets();
-
         const int tag_request = Utilities::MPI::internal::Tags::
           consensus_algorithm_pex_answer_request;
         const int tag_deliver = Utilities::MPI::internal::Tags::
           consensus_algorithm_pex_process_deliver;
 
+
+        // 1) determine with which processes this process wants to communicate
+        // with
+        targets = this->process.compute_targets();
+        Assert(
+          [this]() {
+            std::vector<unsigned int> my_destinations = this->targets;
+            const unsigned int        n_destinations  = my_destinations.size();
+            std::sort(my_destinations.begin(), my_destinations.end());
+            my_destinations.erase(std::unique(my_destinations.begin(),
+                                              my_destinations.end()),
+                                  my_destinations.end());
+            return (my_destinations.size() == n_destinations);
+          }(),
+          ExcMessage("The consensus algorithms expect that each process "
+                     "only sends a single message to another process, "
+                     "but the targets provided include duplicates."));
+
         // 2) determine who wants to communicate with this process
         sources =
           compute_point_to_point_communication_pattern(this->comm, targets);

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.