]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Let CA return the requesting processes 12193/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 12 May 2021 16:54:06 +0000 (18:54 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 12 May 2021 18:39:53 +0000 (20:39 +0200)
include/deal.II/base/mpi_consensus_algorithms.h
include/deal.II/base/mpi_consensus_algorithms.templates.h
tests/base/consensus_algorithm_01.cc
tests/base/consensus_algorithm_01.mpirun=4.output

index 05ad9c32ba276126c7a6596eb4a5897e816653df..45fb9388a2c74e51eae8ddd55f2bd70036e669bc 100644 (file)
@@ -174,9 +174,9 @@ namespace Utilities
         virtual ~Interface() = default;
 
         /**
-         * Run consensus algorithm.
+         * Run consensus algorithm and return the requesting processes.
          */
-        virtual void
+        virtual std::vector<unsigned int>
         run() = 0;
 
       protected:
@@ -241,7 +241,7 @@ namespace Utilities
         /**
          * @copydoc Interface::run()
          */
-        virtual void
+        virtual std::vector<unsigned int>
         run() override;
 
       private:
@@ -286,12 +286,10 @@ namespace Utilities
         MPI_Request barrier_request;
 #endif
 
-#ifdef DEBUG
         /**
          * List of processes who have made a request to this process.
          */
         std::set<unsigned int> requesting_processes;
-#endif
 
         /**
          * Check if all request answers have been received by this rank.
@@ -377,7 +375,7 @@ namespace Utilities
         /**
          * @copydoc Interface::run()
          */
-        virtual void
+        virtual std::vector<unsigned int>
         run() override;
 
       private:
@@ -419,6 +417,10 @@ namespace Utilities
          */
         std::vector<MPI_Request> requests_answers;
 #endif
+        /**
+         * List of processes who have made a request to this process.
+         */
+        std::set<unsigned int> requesting_processes;
 
         /**
          * The ith request message from another rank has been received: process
@@ -461,7 +463,7 @@ namespace Utilities
         /**
          * @copydoc Interface::run()
          */
-        virtual void
+        virtual std::vector<unsigned int>
         run() override;
       };
 
@@ -497,7 +499,7 @@ namespace Utilities
          *
          * @note The function call is delegated to another ConsensusAlgorithms::Interface implementation.
          */
-        virtual void
+        virtual std::vector<unsigned int>
         run() override;
 
       private:
index 3037ef78fc1220b3251caa969c3ab3c486aa1c3f..eb6945da09331dcb00e2c7749f7feeb3c18e6a49 100644 (file)
@@ -98,7 +98,7 @@ namespace Utilities
 
 
       template <typename T1, typename T2>
-      void
+      std::vector<unsigned int>
       NBX<T1, T2>::run()
       {
         static CollectiveMutex      mutex;
@@ -124,6 +124,10 @@ namespace Utilities
 
         // 5) process the answer to all requests
         clean_up_and_end_communication();
+
+        return std::vector<unsigned int>(requesting_processes.begin(),
+                                         requesting_processes.end());
+        ;
       }
 
 
@@ -211,12 +215,10 @@ namespace Utilities
             // get rank of requesting process
             const auto other_rank = status.MPI_SOURCE;
 
-#  ifdef DEBUG
             Assert(requesting_processes.find(other_rank) ==
                      requesting_processes.end(),
                    ExcMessage("Process is requesting a second time!"));
             requesting_processes.insert(other_rank);
-#  endif
 
             std::vector<T1> buffer_recv;
             // get size of incoming message
@@ -378,7 +380,7 @@ namespace Utilities
 
 
       template <typename T1, typename T2>
-      void
+      std::vector<unsigned int>
       PEX<T1, T2>::run()
       {
         static CollectiveMutex      mutex;
@@ -394,6 +396,9 @@ namespace Utilities
 
         // 3) process answers
         clean_up_and_end_communication();
+
+        return std::vector<unsigned int>(requesting_processes.begin(),
+                                         requesting_processes.end());
       }
 
 
@@ -415,6 +420,11 @@ namespace Utilities
         // get rank of incoming message
         const auto other_rank = status.MPI_SOURCE;
 
+        Assert(requesting_processes.find(other_rank) ==
+                 requesting_processes.end(),
+               ExcMessage("Process is requesting a second time!"));
+        requesting_processes.insert(other_rank);
+
         std::vector<T1> buffer_recv;
 
         // get size of incoming message
@@ -560,25 +570,27 @@ namespace Utilities
 
 
       template <typename T1, typename T2>
-      void
+      std::vector<unsigned int>
       Serial<T1, T2>::run()
       {
         const auto targets = this->process.compute_targets();
 
-        if (targets.size() == 0)
-          return; // nothing to do
+        if (targets.size() != 0)
+          {
+            AssertDimension(targets[0], 0);
 
-        AssertDimension(targets[0], 0);
+            std::vector<T1> send_buffer;
+            std::vector<T2> recv_buffer;
+            std::vector<T2> request_buffer;
 
-        std::vector<T1> send_buffer;
-        std::vector<T2> recv_buffer;
-        std::vector<T2> request_buffer;
+            this->process.create_request(0, send_buffer);
+            this->process.prepare_buffer_for_answer(0, recv_buffer);
+            this->process.answer_request(0, send_buffer, request_buffer);
+            recv_buffer = request_buffer;
+            this->process.read_answer(0, recv_buffer);
+          }
 
-        this->process.create_request(0, send_buffer);
-        this->process.prepare_buffer_for_answer(0, recv_buffer);
-        this->process.answer_request(0, send_buffer, request_buffer);
-        recv_buffer = request_buffer;
-        this->process.read_answer(0, recv_buffer);
+        return targets; // nothing to do
       }
 
 
@@ -612,10 +624,10 @@ namespace Utilities
 
 
       template <typename T1, typename T2>
-      void
+      std::vector<unsigned int>
       Selector<T1, T2>::run()
       {
-        consensus_algo->run();
+        return consensus_algo->run();
       }
 
 
index 0d2204825b0d66ee86e159d8bc10fca6932218ce..bdbe93f6164d7178cdddfaee0f2aaeda3876f8c5 100644 (file)
@@ -54,8 +54,14 @@ test(const MPI_Comm &comm)
       deallog << "ConsensusAlgorithmProcess::function_read_answer() passed!"
               << std::endl;
     });
-  dealii::Utilities::MPI::ConsensusAlgorithms::Selector<T1, T2>(process, comm)
-    .run();
+
+  const auto sources =
+    dealii::Utilities::MPI::ConsensusAlgorithms::Selector<T1, T2>(process, comm)
+      .run();
+
+  for (const auto &i : sources)
+    deallog << i << " ";
+  deallog << std::endl;
 }
 
 int
index 8faf9d944b159e12360dda9b9099dadda1fbd9c5..f2df94cb28ad0e3de22e22905492edd721f335ef 100644 (file)
@@ -1,15 +1,19 @@
 
 DEAL:0::ConsensusAlgorithmProcess::answer_request() passed!
 DEAL:0::ConsensusAlgorithmProcess::function_read_answer() passed!
+DEAL:0::3 
 
 DEAL:1::ConsensusAlgorithmProcess::answer_request() passed!
 DEAL:1::ConsensusAlgorithmProcess::function_read_answer() passed!
+DEAL:1::0 
 
 
 DEAL:2::ConsensusAlgorithmProcess::answer_request() passed!
 DEAL:2::ConsensusAlgorithmProcess::function_read_answer() passed!
+DEAL:2::1 
 
 
 DEAL:3::ConsensusAlgorithmProcess::answer_request() passed!
 DEAL:3::ConsensusAlgorithmProcess::function_read_answer() passed!
+DEAL:3::2 
 

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.