From 001d2d069f9c3b913158ffbb5d0ad1177888c7ac Mon Sep 17 00:00:00 2001
From: Markus Blatt <mblatt@dune-project.org>
Date: Wed, 17 Aug 2011 18:44:13 +0000
Subject: [PATCH] Added allgather.

[[Imported from SVN: r6489]]
---
 dune/common/collectivecommunication.hh    | 20 ++++++++++++++++++++
 dune/common/mpicollectivecommunication.hh | 10 ++++++++++
 2 files changed, 30 insertions(+)

diff --git a/dune/common/collectivecommunication.hh b/dune/common/collectivecommunication.hh
index 66c3a9b8a..6edc5daaf 100644
--- a/dune/common/collectivecommunication.hh
+++ b/dune/common/collectivecommunication.hh
@@ -180,6 +180,26 @@ namespace Dune
       return 0;
     }
 
+    /**
+     * @brief Gathers data from all tasks and distribute it to all.
+     *
+     * The block of data sent from the  jth  process  is  received  by  every
+     *  process and placed in the jth block of the buffer recvbuf.
+     *
+     * @param[in] sbuf The buffer with the data to send. Has to be the same for
+     *                 each task.
+     * @param[in] count The number of elements to send by any process.
+     * @param[out] rbuf The receive buffer for the data. Has to be of size
+     *  notasks*count, with notasks being the number of tasks in the communicator.
+     */
+    template<typename T>
+    int allgather(T* sbuf, int count, T* rbuf) const
+    {
+      for(T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
+        *sbuf=*rbuf;
+      return 0;
+    }
+
     /**
      * @brief Compute something over all processes
      * for each component of an array and return the result
diff --git a/dune/common/mpicollectivecommunication.hh b/dune/common/mpicollectivecommunication.hh
index 4bdbb1ec8..3cd725820 100644
--- a/dune/common/mpicollectivecommunication.hh
+++ b/dune/common/mpicollectivecommunication.hh
@@ -314,6 +314,15 @@ namespace Dune
       return communicator;
     }
 
+    //! @copydoc CollectiveCommunication::allgather()
+    template<typename T, typename T1>
+    int allgather(T* sbuf, int count, T1* rbuf) const
+    {
+      return MPI_Allgather(sbuf, count, MPITraits<T>::getType(),
+                           rbuf, count, MPITraits<T1>::getType(),
+                           communicator);
+    }
+
     template<typename BinaryFunction, typename Type>
     int allreduce(Type* inout, int len) const
     {
@@ -324,6 +333,7 @@ namespace Dune
       return ret;
     }
 
+    //! @copydoc CollectiveCommunication::allreduce()
     template<typename BinaryFunction, typename Type>
     int allreduce(Type* in, Type* out, int len) const
     {
-- 
GitLab