From 3dbecd9f87d27b02d77a865e433bce12de0e7c50 Mon Sep 17 00:00:00 2001
From: Simon Heybrock <simon.heybrock@esss.se>
Date: Fri, 17 Nov 2017 14:53:44 +0100
Subject: [PATCH] Re #21181. Non-distributed MPI support for CompareWorkspaces.

---
 .../inc/MantidAlgorithms/CompareWorkspaces.h     | 13 +++++++------
 Framework/Algorithms/src/CompareWorkspaces.cpp   | 16 ++++++++++++++++
 docs/source/development/AlgorithmMPISupport.rst  |  1 +
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CompareWorkspaces.h b/Framework/Algorithms/inc/MantidAlgorithms/CompareWorkspaces.h
index eaacfed5a82..daaf7336892 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/CompareWorkspaces.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/CompareWorkspaces.h
@@ -71,10 +71,6 @@ namespace Algorithms {
  */
 class DLLExport CompareWorkspaces : public API::Algorithm {
 public:
-  CompareWorkspaces()
-      : API::Algorithm(), m_result(false), m_parallelComparison(true) {}
-  ~CompareWorkspaces() override {}
-
   /// Algorithm's name
   const std::string name() const override { return "CompareWorkspaces"; }
 
@@ -91,6 +87,11 @@ public:
            "testing process.";
   }
 
+protected:
+  Parallel::ExecutionMode getParallelExecutionMode(
+      const std::map<std::string, Parallel::StorageMode> &storageModes)
+      const override;
+
 private:
   /// Initialise algorithm
   void init() override;
@@ -143,7 +144,7 @@ private:
   bool relErr(double x1, double x2, double errorVal) const;
 
   /// Result of comparison (true if equal, false otherwise)
-  bool m_result;
+  bool m_result{false};
 
   /// Mismatch messages that resulted from comparison
   API::ITableWorkspace_sptr m_messages;
@@ -156,7 +157,7 @@ private:
   /// comparison make things complicated as
   /// logs from different threads are mixed together.  In this case, it is
   /// better not to do parallell comparison.
-  bool m_parallelComparison;
+  bool m_parallelComparison{false};
 };
 
 } // namespace Algorithms
diff --git a/Framework/Algorithms/src/CompareWorkspaces.cpp b/Framework/Algorithms/src/CompareWorkspaces.cpp
index d03663a5bbd..f2c93adde18 100644
--- a/Framework/Algorithms/src/CompareWorkspaces.cpp
+++ b/Framework/Algorithms/src/CompareWorkspaces.cpp
@@ -1180,5 +1180,21 @@ bool CompareWorkspaces::relErr(double x1, double x2, double errorVal) const {
   return (num / den > errorVal);
 }
 
+Parallel::ExecutionMode CompareWorkspaces::getParallelExecutionMode(
+    const std::map<std::string, Parallel::StorageMode> &storageModes) const {
+  using namespace Parallel;
+  if (storageModes.at("Workspace1") == StorageMode::Cloned) {
+    if (storageModes.at("Workspace2") == StorageMode::Cloned)
+      return getCorrespondingExecutionMode(StorageMode::Cloned);
+    if (storageModes.at("Workspace2") == StorageMode::MasterOnly)
+      return getCorrespondingExecutionMode(StorageMode::MasterOnly);
+  }
+  if (storageModes.at("Workspace1") == StorageMode::MasterOnly) {
+    if (storageModes.at("Workspace2") != StorageMode::Distributed)
+      return getCorrespondingExecutionMode(StorageMode::MasterOnly);
+  }
+  return ExecutionMode::Invalid;
+}
+
 } // namespace Algorithms
 } // namespace Mantid
diff --git a/docs/source/development/AlgorithmMPISupport.rst b/docs/source/development/AlgorithmMPISupport.rst
index b5bd3875024..0a4ceda27ee 100644
--- a/docs/source/development/AlgorithmMPISupport.rst
+++ b/docs/source/development/AlgorithmMPISupport.rst
@@ -459,6 +459,7 @@ CalculateChiSquared               MasterOnly, Identical   see ``IFittingAlgorith
 CalculateCostFunction             MasterOnly, Identical   see ``IFittingAlgorithm``
 CloneWorkspace                    all
 CompressEvents                    all
+CompareWorkspace                  MasterOnly, Identical   if one input has ``StorageMode::Cloned`` and the other has ``StorageMode::MasterOnly`` then ``ExecutionMode::MasterOnly`` is used
 CreateSingleValuedWorkspace       Identical               ``OutputWorkspace`` has ``StorageMode::Cloned``, support of ``MasterOnly`` would require adding property for selecting the mode
 CreateWorkspace                   all
 CropToComponent                   all
-- 
GitLab