]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move implementation of MPI::all_gather() 5820/head
authorbenjamin <benjamin.brands@fau.de>
Sat, 27 Jan 2018 21:25:55 +0000 (22:25 +0100)
committerbenjamin <benjamin.brands@fau.de>
Sat, 27 Jan 2018 21:25:55 +0000 (22:25 +0100)
include/deal.II/base/mpi.h
include/deal.II/base/mpi.templates.h
tests/base/mpi_all_gather_01.cc
tests/base/mpi_some_to_some_02.cc

index 9b59aa1b3db420d78af5e3bc84f7bd2890573eb9..0f6502153f79767b529d84da96818fe1db040d8b 100644 (file)
@@ -551,6 +551,55 @@ namespace Utilities
                            mpi_communicator, ArrayView<T>(minima, N));
     }
 
+    template<typename T>
+    std::vector<T> all_gather(const MPI_Comm       &comm,
+                              const T &object)
+    {
+#ifndef DEAL_II_WITH_MPI
+      (void)comm;
+      std::vector<T> v(1, object);
+      return v;
+#else
+      const auto n_procs = dealii::Utilities::MPI::n_mpi_processes(comm);
+
+      std::vector<char> buffer = Utilities::pack(object);
+
+      int n_local_data = buffer.size();
+
+      // Vector to store the size of loc_data_array for every process
+      std::vector<int> size_all_data(n_procs,0);
+
+      // Exchanging the size of each buffer
+      MPI_Allgather(&n_local_data, 1, MPI_INT,
+                    &(size_all_data[0]), 1, MPI_INT,
+                    comm);
+
+      // Now computing the the displacement, relative to recvbuf,
+      // at which to store the incoming buffer
+      std::vector<int> rdispls(n_procs);
+      rdispls[0] = 0;
+      for (unsigned int i=1; i < n_procs; ++i)
+        rdispls[i] = rdispls[i-1] + size_all_data[i-1];
+
+      // Step 3: exchange the buffer:
+      std::vector<char> received_unrolled_buffer(rdispls.back() + size_all_data.back());
+
+      MPI_Allgatherv(buffer.data(), n_local_data, MPI_CHAR,
+                     received_unrolled_buffer.data(), size_all_data.data(),
+                     rdispls.data(), MPI_CHAR, comm);
+
+      std::vector<T> received_objects(n_procs);
+      for (unsigned int i= 0; i < n_procs; ++i)
+        {
+          std::vector<char> local_buffer(received_unrolled_buffer.begin()+rdispls[i],
+                                         received_unrolled_buffer.begin()+rdispls[i]+size_all_data[i]);
+          received_objects[i] = Utilities::unpack<T>(local_buffer);
+        }
+
+      return received_objects;
+#endif
+    }
+
     template <typename T>
     std::vector<T>
     gather(const MPI_Comm &comm,
index 15162ed41c88805cbb54b37245f59d4b1ff7c23e..b3ce6235eb30edab7b82c764d29a490b1c02f18b 100644 (file)
@@ -271,57 +271,6 @@ namespace Utilities
 
 
 
-    template<typename T>
-    std::vector<T> all_gather(const MPI_Comm       &comm,
-                              const T &object)
-    {
-#ifndef DEAL_II_WITH_MPI
-      (void)comm;
-      std::vector<T> v(1, object);
-      return v;
-#else
-      const auto n_procs = dealii::Utilities::MPI::n_mpi_processes(comm);
-
-      std::vector<char> buffer = Utilities::pack(object);
-
-      int n_local_data = buffer.size();
-
-      // Vector to store the size of loc_data_array for every process
-      std::vector<int> size_all_data(n_procs,0);
-
-      // Exchanging the size of each buffer
-      MPI_Allgather(&n_local_data, 1, MPI_INT,
-                    &(size_all_data[0]), 1, MPI_INT,
-                    comm);
-
-      // Now computing the the displacement, relative to recvbuf,
-      // at which to store the incoming buffer
-      std::vector<int> rdispls(n_procs);
-      rdispls[0] = 0;
-      for (unsigned int i=1; i < n_procs; ++i)
-        rdispls[i] = rdispls[i-1] + size_all_data[i-1];
-
-      // Step 3: exchange the buffer:
-      std::vector<char> received_unrolled_buffer(rdispls.back() + size_all_data.back());
-
-      MPI_Allgatherv(buffer.data(), n_local_data, MPI_CHAR,
-                     received_unrolled_buffer.data(), size_all_data.data(),
-                     rdispls.data(), MPI_CHAR, comm);
-
-      std::vector<T> received_objects(n_procs);
-      for (unsigned int i= 0; i < n_procs; ++i)
-        {
-          std::vector<char> local_buffer(received_unrolled_buffer.begin()+rdispls[i],
-                                         received_unrolled_buffer.begin()+rdispls[i]+size_all_data[i]);
-          received_objects[i] = Utilities::unpack<T>(local_buffer);
-        }
-
-      return received_objects;
-#endif
-    }
-
-
-
     template <typename T>
     T sum (const T &t,
            const MPI_Comm &mpi_communicator)
index 803fe31f208ccd887e55f81d9aa174e6269bf5f0..f996b4092fe512ddef1272b1191e03d2dd8bd934 100644 (file)
@@ -18,7 +18,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>
 
 int main(int argc, char *argv[])
index e6e7a4e4408da22f6e3ba74269aaf58bfa4ca71f..8a442b94003bc341d4bc7c204c290ba75bad8e57 100644 (file)
@@ -20,7 +20,7 @@
 
 #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.