]> https://gitweb.dealii.org/ - dealii.git/commitdiff
move implemetation of MPI::some_to_some 5823/head
authorbenjamin <benjamin.brands@fau.de>
Sun, 28 Jan 2018 10:38:09 +0000 (11:38 +0100)
committerbenjamin <benjamin.brands@fau.de>
Sun, 28 Jan 2018 10:38:09 +0000 (11:38 +0100)
include/deal.II/base/mpi.h
include/deal.II/base/mpi.templates.h
tests/base/mpi_some_to_some_01.cc
tests/base/mpi_some_to_some_02.cc

index 50a5842d2742c88d2632593e02860a95b10f4385..8abb223e19e207b95f822fe127eee00725eed05c 100644 (file)
@@ -551,6 +551,85 @@ namespace Utilities
                            mpi_communicator, ArrayView<T>(minima, N));
     }
 
+    template<typename T>
+    std::map<unsigned int, T>
+    some_to_some(const MPI_Comm &comm,
+                 const std::map<unsigned int, T> &objects_to_send)
+    {
+#ifndef DEAL_II_WITH_MPI
+      (void)comm;
+      Assert(objects_to_send.size() == 0, ExcMessage("Cannot send to more than one processor."));
+      Assert(objects_to_send.find(0) != objects_to_send.end() || objects_to_send.size() == 0,
+             ExcMessage("Can only send to myself or to nobody."));
+      return objects_to_send;
+#else
+
+      std::vector<unsigned int> send_to(objects_to_send.size());
+      {
+        unsigned int i=0;
+        for (const auto &m: objects_to_send)
+          send_to[i++] = m.first;
+      }
+      AssertDimension(send_to.size(), objects_to_send.size());
+
+      const auto receive_from =
+        Utilities::MPI::compute_point_to_point_communication_pattern(comm, send_to);
+
+      // Sending buffers
+      std::vector<std::vector<char> > buffers_to_send(send_to.size());
+      std::vector<MPI_Request> buffer_send_requests(send_to.size());
+      {
+        unsigned int i = 0;
+        for (const auto &rank_obj : objects_to_send)
+          {
+            const auto &rank = rank_obj.first;
+            buffers_to_send[i] = Utilities::pack(rank_obj.second);
+            const int ierr = MPI_Isend(buffers_to_send[i].data(),
+                                       buffers_to_send[i].size(), MPI_CHAR,
+                                       rank, 21, comm, &buffer_send_requests[i]);
+            AssertThrowMPI(ierr);
+            ++i;
+          }
+      }
+
+      // Receiving buffers
+      std::map<unsigned int, T> received_objects;
+      {
+        std::vector<char> buffer;
+        // We do this on a first come/first served basis
+        for (unsigned int i = 0; i<receive_from.size(); ++i)
+          {
+            // Probe what's going on. Take data from the first available sender
+            MPI_Status status;
+            int ierr = MPI_Probe(MPI_ANY_SOURCE, 21, comm, &status);
+            AssertThrowMPI(ierr);
+
+            // Length of the message
+            int len;
+            ierr = MPI_Get_count(&status, MPI_CHAR, &len);
+            AssertThrowMPI(ierr);
+            buffer.resize(len);
+
+            // Source rank
+            const unsigned int rank = status.MPI_SOURCE;
+
+            // Actually receive the message
+            ierr = MPI_Recv(buffer.data(), len, MPI_CHAR,
+                            rank, 21, comm, MPI_STATUS_IGNORE);
+            AssertThrowMPI(ierr);
+            Assert(received_objects.find(rank) == received_objects.end(),
+                   ExcInternalError("I should not receive again from this rank"));
+            received_objects[rank] = Utilities::unpack<T>(buffer);
+          }
+      }
+
+      // Wait to have sent all objects.
+      MPI_Waitall(send_to.size(), buffer_send_requests.data(),MPI_STATUSES_IGNORE);
+
+      return received_objects;
+#endif // deal.II with MPI
+    }
+
     template<typename T>
     std::vector<T> all_gather(const MPI_Comm       &comm,
                               const T &object)
index f0cf9c208a2e9c47e8b0dc15b0b7efb7119df1d8..5c8cc75a96625be1a3c93b447799207b8878daa7 100644 (file)
@@ -190,87 +190,6 @@ namespace Utilities
 
 
 
-    template<typename T>
-    std::map<unsigned int, T>
-    some_to_some(const MPI_Comm &comm,
-                 const std::map<unsigned int, T> &objects_to_send)
-    {
-#ifndef DEAL_II_WITH_MPI
-      (void)comm;
-      Assert(objects_to_send.size() == 0, ExcMessage("Cannot send to more than one processor."));
-      Assert(objects_to_send.find(0) != objects_to_send.end() || objects_to_send.size() == 0,
-             ExcMessage("Can only send to myself or to nobody."));
-      return objects_to_send;
-#else
-
-      std::vector<unsigned int> send_to(objects_to_send.size());
-      {
-        unsigned int i=0;
-        for (const auto &m: objects_to_send)
-          send_to[i++] = m.first;
-      }
-      AssertDimension(send_to.size(), objects_to_send.size());
-
-      const auto receive_from =
-        Utilities::MPI::compute_point_to_point_communication_pattern(comm, send_to);
-
-      // Sending buffers
-      std::vector<std::vector<char> > buffers_to_send(send_to.size());
-      std::vector<MPI_Request> buffer_send_requests(send_to.size());
-      {
-        unsigned int i = 0;
-        for (const auto &rank_obj : objects_to_send)
-          {
-            const auto &rank = rank_obj.first;
-            buffers_to_send[i] = Utilities::pack(rank_obj.second);
-            const int ierr = MPI_Isend(buffers_to_send[i].data(),
-                                       buffers_to_send[i].size(), MPI_CHAR,
-                                       rank, 21, comm, &buffer_send_requests[i]);
-            AssertThrowMPI(ierr);
-            ++i;
-          }
-      }
-
-      // Receiving buffers
-      std::map<unsigned int, T> received_objects;
-      {
-        std::vector<char> buffer;
-        // We do this on a first come/first served basis
-        for (unsigned int i = 0; i<receive_from.size(); ++i)
-          {
-            // Probe what's going on. Take data from the first available sender
-            MPI_Status status;
-            int ierr = MPI_Probe(MPI_ANY_SOURCE, 21, comm, &status);
-            AssertThrowMPI(ierr);
-
-            // Length of the message
-            int len;
-            ierr = MPI_Get_count(&status, MPI_CHAR, &len);
-            AssertThrowMPI(ierr);
-            buffer.resize(len);
-
-            // Source rank
-            const unsigned int rank = status.MPI_SOURCE;
-
-            // Actually receive the message
-            ierr = MPI_Recv(buffer.data(), len, MPI_CHAR,
-                            rank, 21, comm, MPI_STATUS_IGNORE);
-            AssertThrowMPI(ierr);
-            Assert(received_objects.find(rank) == received_objects.end(),
-                   ExcInternalError("I should not receive again from this rank"));
-            received_objects[rank] = Utilities::unpack<T>(buffer);
-          }
-      }
-
-      // Wait to have sent all objects.
-      MPI_Waitall(send_to.size(), buffer_send_requests.data(),MPI_STATUSES_IGNORE);
-
-      return received_objects;
-#endif // deal.II with MPI
-    }
-
-
-
     template <typename T>
     T sum (const T &t,
            const MPI_Comm &mpi_communicator)
index f9319414ae06e40885e99e8340c1c224af858285..e5bca2c7b6905d2ad9f1dc5e77da7ee6335db0ae 100644 (file)
@@ -19,7 +19,7 @@
 #include "../tests.h"
 
 #include <deal.II/base/point.h>
-#include <deal.II/base/mpi.templates.h>
+#include <deal.II/base/mpi.h>
 
 #include <vector>
 
index 8a442b94003bc341d4bc7c204c290ba75bad8e57..383fb15f300abf32e00bd0fff219a6a93ba891df 100644 (file)
@@ -19,8 +19,8 @@
 #include "../tests.h"
 
 #include <deal.II/base/point.h>
-#include <deal.II/base/mpi.templates.h>
 #include <deal.II/base/mpi.h>
+
 #include <vector>
 #include <tuple>
 

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.