From 709b8af66236d0f9918936ea3399e61555ff158f Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Thu, 31 Oct 2024 15:42:07 +0100
Subject: [PATCH] [BL/MPI] allreduce version for vectors

---
 BaseLib/MPI.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/BaseLib/MPI.h b/BaseLib/MPI.h
index 8939563ae2c..891b81f98b3 100644
--- a/BaseLib/MPI.h
+++ b/BaseLib/MPI.h
@@ -112,6 +112,18 @@ static T allreduce(T const& value, MPI_Op const& mpi_op, Mpi const& mpi)
     return result;
 }
 
+template <typename T>
+static std::vector<T> allreduce(std::vector<T> const& vector,
+                                MPI_Op const& mpi_op, Mpi const& mpi)
+{
+    std::size_t const size = vector.size();
+    std::vector<T> result(vector.size());
+
+    MPI_Allreduce(vector.data(), result.data(), size, mpiType<T>(), mpi_op,
+                  mpi.communicator);
+    return result;
+}
+
 template <typename T>
 static void allreduceInplace(std::vector<T>& vector,
                              MPI_Op const& mpi_op,
-- 
GitLab