From 6a1b9ac41de03b4cbae0e1d5b937c2066b864c55 Mon Sep 17 00:00:00 2001
From: Russell Taylor <taylorrj@ornl.gov>
Date: Thu, 17 Mar 2011 18:35:15 +0000
Subject: [PATCH] This should get the windows unit tests passing reliably.
 Visual Studio compiler optimizations are now turned off in parts of
 BinaryOperation.cpp. Re #2669.

---
 Code/Mantid/Build/CMake/FindPythonLibs.cmake  |  2 +-
 .../inc/MantidAlgorithms/BinaryOperation.h    |  4 +-
 .../Algorithms/inc/MantidAlgorithms/Divide.h  |  2 +-
 .../Algorithms/inc/MantidAlgorithms/Minus.h   |  2 +-
 .../inc/MantidAlgorithms/Multiply.h           |  2 +-
 .../Algorithms/inc/MantidAlgorithms/Plus.h    |  2 +-
 .../inc/MantidAlgorithms/PoissonErrors.h      |  2 +-
 .../inc/MantidAlgorithms/WeightedMean.h       |  2 +-
 .../Algorithms/src/BinaryOperation.cpp        | 46 ++++++-------------
 .../Framework/Algorithms/src/Divide.cpp       |  2 +-
 .../Mantid/Framework/Algorithms/src/Minus.cpp |  2 +-
 .../Framework/Algorithms/src/Multiply.cpp     |  2 +-
 Code/Mantid/Framework/Algorithms/src/Plus.cpp |  2 +-
 .../Algorithms/src/PoissonErrors.cpp          |  2 +-
 .../Framework/Algorithms/src/WeightedMean.cpp |  2 +-
 .../Algorithms/test/BinaryOperationTest.h     |  2 +-
 .../test/CommutativeBinaryOperationTest.h     |  2 +-
 .../Framework/Algorithms/test/DivideTest.h    | 10 ++--
 18 files changed, 37 insertions(+), 53 deletions(-)

diff --git a/Code/Mantid/Build/CMake/FindPythonLibs.cmake b/Code/Mantid/Build/CMake/FindPythonLibs.cmake
index 91836f96b25..2dd0836fecf 100644
--- a/Code/Mantid/Build/CMake/FindPythonLibs.cmake
+++ b/Code/Mantid/Build/CMake/FindPythonLibs.cmake
@@ -62,7 +62,7 @@ FOREACH(_CURRENT_VERSION 2.7 2.6 2.5 2.4 2.3 2.2 2.1 2.0 1.6 1.5)
       [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs 
       [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs/Debug
       [HKEY_CURRENT_USER\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs 
-	  "${CMAKE_LIBRARY_PATH}/Python25")
+	  "${CMAKE_LIBRARY_PATH}/Python"${_CURRENT_VERSION_NO_DOTS})
   ENDIF(WIN32)
 
   FIND_LIBRARY(PYTHON_LIBRARY
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h
index b2b3b169ae6..0532125b355 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h
@@ -113,7 +113,7 @@ namespace Mantid
       /// Checks if the spectra at the given index of either input workspace is masked. If so then the output spectra has zeroed data
       /// and is also masked. The function returns true if further processing is not required on the spectra.
       virtual bool propagateSpectraMask(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs, 
-					const int index, API::MatrixWorkspace_sptr out);
+                                        const int index, API::MatrixWorkspace_sptr out);
 
       /** Carries out the binary operation on a single spectrum, with another spectrum as the right-hand operand.
        *
@@ -139,7 +139,7 @@ namespace Mantid
        *  @param EOut :: The vector to hold the error values resulting from the operation
        */
       virtual void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                          const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut) = 0;
+                                          const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut) = 0;
 
 
       // ===================================== EVENT LIST BINARY OPERATIONS ==========================================
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h
index 98ae53c4f90..3ab99feeedd 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Divide.h
@@ -63,7 +63,7 @@ namespace Mantid
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                   const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                  const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                                  const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
       void setOutputUnits(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs,API::MatrixWorkspace_sptr out);
 
 
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Minus.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Minus.h
index b90fabf8629..3466a40d60d 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Minus.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Minus.h
@@ -63,7 +63,7 @@ namespace Mantid
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                   const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                  const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                                  const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const DataObjects::EventList & rhs);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const MantidVec& rhsX, const MantidVec& rhsY, const MantidVec& rhsE);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const double& rhsY, const double& rhsE);
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Multiply.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Multiply.h
index 22876ace986..62a98f3c6d7 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Multiply.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Multiply.h
@@ -63,7 +63,7 @@ namespace Mantid
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                   const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                  const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                                  const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
 
       virtual void performEventBinaryOperation(DataObjects::EventList & lhs,
           const DataObjects::EventList & rhs);
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Plus.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Plus.h
index 1f481cc41ed..dcb2eff5aeb 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Plus.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Plus.h
@@ -65,7 +65,7 @@ namespace Mantid
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                                   const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
       void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                  const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                                  const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const DataObjects::EventList & rhs);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const MantidVec& rhsX, const MantidVec& rhsY, const MantidVec& rhsE);
       void performEventBinaryOperation(DataObjects::EventList & lhs, const double& rhsY, const double& rhsE);
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/PoissonErrors.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/PoissonErrors.h
index dd44b0bd84d..cf89c91f935 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/PoissonErrors.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/PoissonErrors.h
@@ -65,7 +65,7 @@ private:
   void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                               const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
   void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                              const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                              const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
   virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
   
   /// The name of the first input workspace property for BinaryOperation
diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/WeightedMean.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/WeightedMean.h
index 45d66c71d46..c50b1f945f7 100644
--- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/WeightedMean.h
+++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/WeightedMean.h
@@ -60,7 +60,7 @@ private:
   void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
                               const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut);
   void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                              const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut);
+                              const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut);
   virtual bool checkCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
   virtual bool checkSizeCompatibility(const API::MatrixWorkspace_const_sptr lhs,const API::MatrixWorkspace_const_sptr rhs) const;
 
diff --git a/Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp b/Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
index 044bab5f2aa..8c6e3dfb6ff 100644
--- a/Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/BinaryOperation.cpp
@@ -369,6 +369,14 @@ namespace Mantid
     }
 
     //--------------------------------------------------------------------------------------------
+    // Disable optimization under the Visual Studio compiler
+    // Optimizing, in combination with openmp parallelization causes occasional miscalculations
+    // Re-enabled below, after the doSingleValue, doSingleSpectrum, doSingleColumn & do2D methods
+    #ifdef _WIN32
+      #pragma optimize( "", off )
+      #pragma warning(disable:4748)  // This is about /Gs being irrelevant when not optimizing
+    #endif
+
     /**
      * Called when the rhs operand is a single value.
      *  Loops over the lhs workspace calling the abstract binary operation function with a single number as the rhs operand.
@@ -701,40 +709,14 @@ namespace Mantid
         m_erhs->clearMRU();
     }
 
-
-
-
-
-//
-//
-//
-//
-//
-//    void BinaryOperation::do2D()
-//    {
-//      // Propagate any masking first or it could mess up the numbers
-//      propagateBinMasks(m_rhs,m_out);
-//      // Loop over the spectra calling the virtual function for each one
-//      const int numHists = m_lhs->getNumberHistograms();
-//      PARALLEL_FOR3(m_lhs,m_rhs,m_out)
-//      for (int i = 0; i < numHists; ++i)
-//      {
-//        PARALLEL_START_INTERUPT_REGION
-//        m_out->setX(i,m_lhs->refX(i));
-//        if( propagateSpectraMask(m_lhs, m_rhs, i, m_out) )
-//        {
-//          performBinaryOperation(m_lhs->readX(i),m_lhs->readY(i),m_lhs->readE(i),m_rhs->readY(i),m_rhs->readE(i),m_out->dataY(i),m_out->dataE(i));
-//        }
-//        m_progress->report();
-//        PARALLEL_END_INTERUPT_REGION
-//      }
-//      PARALLEL_CHECK_INTERUPT_REGION
-//    }
-//
-
-
+    // End of optimization disabling under Visual Studio
+    #ifdef _WIN32
+      #pragma optimize( "", on )
+      #pragma warning(default:4748)
+    #endif
 
     //---------------------------------------------------------------------------------------------
+
     /** Copies any bin masking from the smaller/rhs input workspace to the output.
      *  Masks on the other input workspace are copied automatically by the workspace factory.
      *  @param rhs :: The workspace which is the right hand operand
diff --git a/Code/Mantid/Framework/Algorithms/src/Divide.cpp b/Code/Mantid/Framework/Algorithms/src/Divide.cpp
index 7bc9da144dc..13590ede5c9 100644
--- a/Code/Mantid/Framework/Algorithms/src/Divide.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Divide.cpp
@@ -48,7 +48,7 @@ namespace Mantid
     }
 
     void Divide::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                       const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                        const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
     {
       (void) lhsX; //Avoid compiler warning
       // Do the right-hand part of the error calculation just once
diff --git a/Code/Mantid/Framework/Algorithms/src/Minus.cpp b/Code/Mantid/Framework/Algorithms/src/Minus.cpp
index 541054c361e..0b8c15132fc 100644
--- a/Code/Mantid/Framework/Algorithms/src/Minus.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Minus.cpp
@@ -31,7 +31,7 @@ namespace Mantid
     }
 
     void Minus::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                       const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                       const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
     {
       (void) lhsX; //Avoid compiler warning
       std::transform(lhsY.begin(),lhsY.end(),YOut.begin(),std::bind2nd(std::minus<double>(),rhsY));
diff --git a/Code/Mantid/Framework/Algorithms/src/Multiply.cpp b/Code/Mantid/Framework/Algorithms/src/Multiply.cpp
index ae2bd237c40..aaddb856367 100644
--- a/Code/Mantid/Framework/Algorithms/src/Multiply.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Multiply.cpp
@@ -46,7 +46,7 @@ namespace Mantid
     }
 
     void Multiply::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                          const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                          const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
     {
       (void) lhsX; //Avoid compiler warning
       const int bins = lhsE.size();
diff --git a/Code/Mantid/Framework/Algorithms/src/Plus.cpp b/Code/Mantid/Framework/Algorithms/src/Plus.cpp
index 7026467c29e..c2ed39c6718 100644
--- a/Code/Mantid/Framework/Algorithms/src/Plus.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/Plus.cpp
@@ -35,7 +35,7 @@ namespace Mantid
 
     //---------------------------------------------------------------------------------------------
     void Plus::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                       const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                       const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
     {
       (void) lhsX; //Avoid compiler warning
       std::transform(lhsY.begin(),lhsY.end(),YOut.begin(),std::bind2nd(std::plus<double>(),rhsY));
diff --git a/Code/Mantid/Framework/Algorithms/src/PoissonErrors.cpp b/Code/Mantid/Framework/Algorithms/src/PoissonErrors.cpp
index 77e2fc9f924..8c3993560ab 100644
--- a/Code/Mantid/Framework/Algorithms/src/PoissonErrors.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/PoissonErrors.cpp
@@ -49,7 +49,7 @@ namespace Mantid
     }
     
     void PoissonErrors::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                               const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                               const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
     {
       (void) lhsE; (void) lhsX; //Avoid compiler warning
 
diff --git a/Code/Mantid/Framework/Algorithms/src/WeightedMean.cpp b/Code/Mantid/Framework/Algorithms/src/WeightedMean.cpp
index 5dd73e0ac2d..66f203ad726 100644
--- a/Code/Mantid/Framework/Algorithms/src/WeightedMean.cpp
+++ b/Code/Mantid/Framework/Algorithms/src/WeightedMean.cpp
@@ -79,7 +79,7 @@ void WeightedMean::performBinaryOperation(const MantidVec& lhsX, const MantidVec
 }
 
 void WeightedMean::performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                                          const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                                          const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
 {
   assert( lhsX.size() == 1 );
   // If we get here we've got two single column workspaces so it's easy.
diff --git a/Code/Mantid/Framework/Algorithms/test/BinaryOperationTest.h b/Code/Mantid/Framework/Algorithms/test/BinaryOperationTest.h
index 7c4b57f47c5..58aa5517abb 100644
--- a/Code/Mantid/Framework/Algorithms/test/BinaryOperationTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/BinaryOperationTest.h
@@ -50,7 +50,7 @@ private:
       const Mantid::MantidVec&, const Mantid::MantidVec& , Mantid::MantidVec&, Mantid::MantidVec&)
   {}
   void performBinaryOperation(const Mantid::MantidVec& , const Mantid::MantidVec&, const Mantid::MantidVec&,
-      const double& , const double&, Mantid::MantidVec& , Mantid::MantidVec& )
+      const double , const double, Mantid::MantidVec& , Mantid::MantidVec& )
   {}
 };
 
diff --git a/Code/Mantid/Framework/Algorithms/test/CommutativeBinaryOperationTest.h b/Code/Mantid/Framework/Algorithms/test/CommutativeBinaryOperationTest.h
index 0a547cdf4f4..38da5f71961 100644
--- a/Code/Mantid/Framework/Algorithms/test/CommutativeBinaryOperationTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/CommutativeBinaryOperationTest.h
@@ -35,7 +35,7 @@ private:
                               const MantidVec& rhsY, const MantidVec& rhsE, MantidVec& YOut, MantidVec& EOut)
   {}
   void performBinaryOperation(const MantidVec& lhsX, const MantidVec& lhsY, const MantidVec& lhsE,
-                              const double& rhsY, const double& rhsE, MantidVec& YOut, MantidVec& EOut)
+                              const double rhsY, const double rhsE, MantidVec& YOut, MantidVec& EOut)
   {}
 };
 
diff --git a/Code/Mantid/Framework/Algorithms/test/DivideTest.h b/Code/Mantid/Framework/Algorithms/test/DivideTest.h
index 62e89cf42bc..f29b0c6e3e2 100644
--- a/Code/Mantid/Framework/Algorithms/test/DivideTest.h
+++ b/Code/Mantid/Framework/Algorithms/test/DivideTest.h
@@ -816,14 +816,16 @@ public:
       {
         for (int i=0; i<work_out1->blocksize(); i++)
         {
-          std::ostringstream mess;
-          mess << message << ", evaluated at wi " << wi << ", i " << i;
+          //std::ostringstream mess;
+          //mess << message << ", evaluated at wi " << wi << ", i " << i;
         
           TS_ASSERT_DELTA(work_in1->readX(wi)[i], work_out1->readX(wi)[i], 0.0001);
           double sig3 = work_out1->readY(wi)[i];
           double err3 = work_out1->readE(wi)[i];
-          TSM_ASSERT_DELTA(mess.str(), sig3, expectedValue, 0.0001);
-          TSM_ASSERT_DELTA(mess.str(), err3, expectedError, 0.0001);
+          TS_ASSERT_DELTA(sig3, expectedValue, 0.0001);
+          TS_ASSERT_DELTA(err3, expectedError, 0.0001);
+          //TSM_ASSERT_DELTA(mess.str(), sig3, expectedValue, 0.0001);
+          //TSM_ASSERT_DELTA(mess.str(), err3, expectedError, 0.0001);
           if (fabs(err3 - expectedError) > 0.001)
           {
             breakOut=true;
-- 
GitLab