From 5123cd2fd7ed90a0881d5ef0ac58c0cbf0cc4b76 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Mon, 17 Dec 2018 12:51:34 +0100
Subject: [PATCH] Added Communicator:: Prod Max Min

---
 src/tools/Communicator.cpp | 24 ++++++++++++++++++++++++
 src/tools/Communicator.h   | 18 ++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/tools/Communicator.cpp b/src/tools/Communicator.cpp
index 87968e7e7..bc2e04742 100644
--- a/src/tools/Communicator.cpp
+++ b/src/tools/Communicator.cpp
@@ -131,6 +131,30 @@ void Communicator::Sum(Data data) {
 #endif
 }
 
+void Communicator::Prod(Data data) {
+#if defined(__PLUMED_HAS_MPI)
+  if(initialized()) MPI_Allreduce(MPI_IN_PLACE,data.pointer,data.size,data.type,MPI_PROD,communicator);
+#else
+  (void) data;
+#endif
+}
+
+void Communicator::Max(Data data) {
+#if defined(__PLUMED_HAS_MPI)
+  if(initialized()) MPI_Allreduce(MPI_IN_PLACE,data.pointer,data.size,data.type,MPI_MAX,communicator);
+#else
+  (void) data;
+#endif
+}
+
+void Communicator::Min(Data data) {
+#if defined(__PLUMED_HAS_MPI)
+  if(initialized()) MPI_Allreduce(MPI_IN_PLACE,data.pointer,data.size,data.type,MPI_MIN,communicator);
+#else
+  (void) data;
+#endif
+}
+
 Communicator::Request Communicator::Isend(ConstData data,int source,int tag) {
   Request req;
 #ifdef __PLUMED_HAS_MPI
diff --git a/src/tools/Communicator.h b/src/tools/Communicator.h
index 97cc60fb8..eaf930541 100644
--- a/src/tools/Communicator.h
+++ b/src/tools/Communicator.h
@@ -175,6 +175,24 @@ public:
   template <class T> void Sum(T*buf,int count) {Sum(Data(buf,count));}
 /// Wrapper for MPI_Allreduce with MPI_SUM (reference)
   template <class T> void Sum(T&buf) {Sum(Data(buf));}
+/// Wrapper for MPI_Allreduce with MPI_PROD (data struct)
+  void Prod(Data);
+/// Wrapper for MPI_Allreduce with MPI_PROD (pointer)
+  template <class T> void Prod(T*buf,int count) {Prod(Data(buf,count));}
+/// Wrapper for MPI_Allreduce with MPI_PROD (reference)
+  template <class T> void Prod(T&buf) {Prod(Data(buf));}
+/// Wrapper for MPI_Allreduce with MPI_MAX (data struct)
+  void Max(Data);
+/// Wrapper for MPI_Allreduce with MPI_MAX (pointer)
+  template <class T> void Max(T*buf,int count) {Max(Data(buf,count));}
+/// Wrapper for MPI_Allreduce with MPI_MAX (reference)
+  template <class T> void Max(T&buf) {Max(Data(buf));}
+/// Wrapper for MPI_Allreduce with MPI_MIN (data struct)
+  void Min(Data);
+/// Wrapper for MPI_Allreduce with MPI_MIN (pointer)
+  template <class T> void Min(T*buf,int count) {Min(Data(buf,count));}
+/// Wrapper for MPI_Allreduce with MPI_MIN (reference)
+  template <class T> void Min(T&buf) {Min(Data(buf));}
 
 /// Wrapper for MPI_Bcast (data struct)
   void Bcast(Data,int);
-- 
GitLab