From f08258f63a4a6baef92b4d48742f9b98b4266cb2 Mon Sep 17 00:00:00 2001
From: Steven Hahn <hahnse@ornl.gov>
Date: Fri, 14 Oct 2016 20:50:08 -0400
Subject: [PATCH] Replace PARALLEL_FOR2 with PARALLEL_FOR_IF.

---
 Framework/Algorithms/src/AbsorptionCorrection.cpp      |  2 +-
 .../Algorithms/src/ApplyTransmissionCorrection.cpp     |  2 +-
 Framework/Algorithms/src/CalculateFlatBackground.cpp   |  2 +-
 Framework/Algorithms/src/ChopData.cpp                  |  2 +-
 Framework/Algorithms/src/ConvertAxesToRealSpace.cpp    |  2 +-
 Framework/Algorithms/src/ConvertToMatrixWorkspace.cpp  |  2 +-
 Framework/Algorithms/src/CorrectFlightPaths.cpp        |  2 +-
 Framework/Algorithms/src/CorrectKiKf.cpp               |  2 +-
 Framework/Algorithms/src/CreatePSDBleedMask.cpp        |  5 ++---
 Framework/Algorithms/src/CrossCorrelate.cpp            |  2 +-
 Framework/Algorithms/src/DetectorEfficiencyCor.cpp     |  2 +-
 Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp |  2 +-
 Framework/Algorithms/src/DiffractionFocussing2.cpp     | 10 ++++------
 Framework/Algorithms/src/ExtractMask.cpp               |  2 +-
 Framework/Algorithms/src/ExtractSpectra.cpp            |  2 +-
 Framework/Algorithms/src/He3TubeEfficiency.cpp         |  2 +-
 Framework/Algorithms/src/Integration.cpp               |  2 +-
 Framework/Algorithms/src/MaxMin.cpp                    |  2 +-
 Framework/Algorithms/src/MedianDetectorTest.cpp        |  2 +-
 Framework/Algorithms/src/ModeratorTzero.cpp            |  2 +-
 Framework/Algorithms/src/ModeratorTzeroLinear.cpp      |  2 +-
 Framework/Algorithms/src/MonitorEfficiencyCorUser.cpp  |  2 +-
 Framework/Algorithms/src/MultiplyRange.cpp             |  2 +-
 Framework/Algorithms/src/NormaliseByDetector.cpp       |  2 +-
 Framework/Algorithms/src/Q1DWeighted.cpp               |  2 +-
 Framework/Algorithms/src/Qxy.cpp                       |  4 ----
 Framework/Algorithms/src/Rebin.cpp                     |  2 +-
 Framework/Algorithms/src/Rebin2D.cpp                   |  2 +-
 Framework/Algorithms/src/RebinByPulseTimes.cpp         |  2 +-
 Framework/Algorithms/src/RebinByTimeAtSample.cpp       |  2 +-
 Framework/Algorithms/src/Rebunch.cpp                   |  2 +-
 Framework/Algorithms/src/RemoveBackground.cpp          |  2 +-
 Framework/Algorithms/src/RemoveExpDecay.cpp            |  4 ++--
 Framework/Algorithms/src/ResampleX.cpp                 |  6 +++---
 Framework/Algorithms/src/ResetNegatives.cpp            |  6 +++---
 .../src/SampleCorrections/MayersSampleCorrection.cpp   |  2 +-
 Framework/Algorithms/src/ScaleX.cpp                    |  2 +-
 Framework/Algorithms/src/SetUncertainties.cpp          |  2 +-
 Framework/Algorithms/src/SmoothData.cpp                |  2 +-
 Framework/Algorithms/src/SmoothNeighbours.cpp          |  4 ++--
 Framework/Algorithms/src/SofQWNormalisedPolygon.cpp    |  2 +-
 Framework/Algorithms/src/SofQWPolygon.cpp              |  2 +-
 Framework/Algorithms/src/SolidAngle.cpp                |  2 +-
 Framework/Algorithms/src/Stitch1D.cpp                  |  2 +-
 Framework/Algorithms/src/TOFSANSResolution.cpp         |  2 +-
 Framework/Algorithms/src/Transpose.cpp                 |  2 +-
 Framework/Algorithms/src/UnaryOperation.cpp            |  2 +-
 Framework/Algorithms/src/UnwrapSNS.cpp                 |  6 +-----
 Framework/Algorithms/src/WorkspaceJoiners.cpp          |  4 ++--
 Framework/Algorithms/src/XDataConverter.cpp            |  4 ++--
 Framework/Crystal/src/AnvredCorrection.cpp             |  4 ++--
 Framework/Crystal/src/CentroidPeaks.cpp                |  4 ++--
 Framework/Crystal/src/NormaliseVanadium.cpp            |  2 +-
 Framework/Crystal/src/PeaksIntersection.cpp            |  2 +-
 .../CurveFitting/src/Algorithms/ConvertToYSpace.cpp    |  2 +-
 Framework/Kernel/inc/MantidKernel/MultiThreaded.h      | 10 ----------
 Framework/MDAlgorithms/src/ThresholdMD.cpp             |  2 +-
 .../src/SANSSolidAngleCorrection.cpp                   |  2 +-
 58 files changed, 70 insertions(+), 91 deletions(-)

diff --git a/Framework/Algorithms/src/AbsorptionCorrection.cpp b/Framework/Algorithms/src/AbsorptionCorrection.cpp
index 9af5ead1ce2..6a8e5686d80 100644
--- a/Framework/Algorithms/src/AbsorptionCorrection.cpp
+++ b/Framework/Algorithms/src/AbsorptionCorrection.cpp
@@ -138,7 +138,7 @@ void AbsorptionCorrection::exec() {
 
   Progress prog(this, 0.0, 1.0, numHists);
   // Loop over the spectra
-  PARALLEL_FOR2(m_inputWS, correctionFactors)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *correctionFactors))
   for (int64_t i = 0; i < int64_t(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/ApplyTransmissionCorrection.cpp b/Framework/Algorithms/src/ApplyTransmissionCorrection.cpp
index 1dbaf00f3df..469c8d3e8fa 100644
--- a/Framework/Algorithms/src/ApplyTransmissionCorrection.cpp
+++ b/Framework/Algorithms/src/ApplyTransmissionCorrection.cpp
@@ -89,7 +89,7 @@ void ApplyTransmissionCorrection::exec() {
   const auto &spectrumInfo = inputWS->spectrumInfo();
 
   // Loop through the spectra and apply correction
-  PARALLEL_FOR2(inputWS, corrWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *corrWS))
   for (int i = 0; i < numHists; i++) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/CalculateFlatBackground.cpp b/Framework/Algorithms/src/CalculateFlatBackground.cpp
index 8e7d06c8edb..5de0b7ac98b 100644
--- a/Framework/Algorithms/src/CalculateFlatBackground.cpp
+++ b/Framework/Algorithms/src/CalculateFlatBackground.cpp
@@ -161,7 +161,7 @@ void CalculateFlatBackground::exec() {
   // the output
   if (outputWS != inputWS) {
     outputWS = WorkspaceFactory::Instance().create(inputWS);
-    PARALLEL_FOR2(inputWS, outputWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
     for (int i = 0; i < numHists; ++i) {
       PARALLEL_START_INTERUPT_REGION
       outputWS->setHistogram(i, inputWS->histogram(i));
diff --git a/Framework/Algorithms/src/ChopData.cpp b/Framework/Algorithms/src/ChopData.cpp
index a0e9556d92e..3867c529977 100644
--- a/Framework/Algorithms/src/ChopData.cpp
+++ b/Framework/Algorithms/src/ChopData.cpp
@@ -129,7 +129,7 @@ void ChopData::exec() {
                                                          nbins + 1, nbins);
 
     // Copy over X, Y and E data
-    PARALLEL_FOR2(inputWS, workspace)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *workspace))
     for (int j = 0; j < nHist; j++) {
 
       auto edges = inputWS->binEdges(j);
diff --git a/Framework/Algorithms/src/ConvertAxesToRealSpace.cpp b/Framework/Algorithms/src/ConvertAxesToRealSpace.cpp
index a04e46808a8..b3245bdb626 100644
--- a/Framework/Algorithms/src/ConvertAxesToRealSpace.cpp
+++ b/Framework/Algorithms/src/ConvertAxesToRealSpace.cpp
@@ -114,7 +114,7 @@ void ConvertAxesToRealSpace::exec() {
 
   const auto &spectrumInfo = summedWs->spectrumInfo();
   // for each spectra
-  PARALLEL_FOR2(summedWs, outputWs)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*summedWs, *outputWs))
   for (int i = 0; i < nHist; ++i) {
     try {
       V3D pos = spectrumInfo.position(i);
diff --git a/Framework/Algorithms/src/ConvertToMatrixWorkspace.cpp b/Framework/Algorithms/src/ConvertToMatrixWorkspace.cpp
index 0b861ef3f2b..41f179a671d 100644
--- a/Framework/Algorithms/src/ConvertToMatrixWorkspace.cpp
+++ b/Framework/Algorithms/src/ConvertToMatrixWorkspace.cpp
@@ -48,7 +48,7 @@ void ConvertToMatrixWorkspace::exec() {
     outputWorkspace = WorkspaceFactory::Instance().create(inputWorkspace);
 
     // ...but not the data, so do that here.
-    PARALLEL_FOR2(inputWorkspace, outputWorkspace)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWorkspace, *outputWorkspace))
     for (int64_t i = 0; i < static_cast<int64_t>(numHists); ++i) {
       PARALLEL_START_INTERUPT_REGION
       const auto &inSpec = inputWorkspace->getSpectrum(i);
diff --git a/Framework/Algorithms/src/CorrectFlightPaths.cpp b/Framework/Algorithms/src/CorrectFlightPaths.cpp
index de7c68a877b..10d156888ce 100644
--- a/Framework/Algorithms/src/CorrectFlightPaths.cpp
+++ b/Framework/Algorithms/src/CorrectFlightPaths.cpp
@@ -88,7 +88,7 @@ void CorrectFlightPaths::exec() {
 
   // Loop over the histograms (detector spectra)
 
-  PARALLEL_FOR2(m_inputWS, m_outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS))
   for (int64_t i = 0; i < numberOfSpectra_i; ++i) {
     PARALLEL_START_INTERUPT_REGION
     m_outputWS->setHistogram(i, m_outputWS->histogram(i));
diff --git a/Framework/Algorithms/src/CorrectKiKf.cpp b/Framework/Algorithms/src/CorrectKiKf.cpp
index 96b920a1348..ff2631863c6 100644
--- a/Framework/Algorithms/src/CorrectKiKf.cpp
+++ b/Framework/Algorithms/src/CorrectKiKf.cpp
@@ -96,7 +96,7 @@ void CorrectKiKf::exec() {
   // Get the parameter map
   const ParameterMap &pmap = outputWS->constInstrumentParameters();
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < int64_t(numberOfSpectra); ++i) {
     PARALLEL_START_INTERUPT_REGION
     double Efi = 0;
diff --git a/Framework/Algorithms/src/CreatePSDBleedMask.cpp b/Framework/Algorithms/src/CreatePSDBleedMask.cpp
index 6de7570375a..3c096be5f47 100644
--- a/Framework/Algorithms/src/CreatePSDBleedMask.cpp
+++ b/Framework/Algorithms/src/CreatePSDBleedMask.cpp
@@ -149,11 +149,10 @@ void CreatePSDBleedMask::exec() {
 
   progress.resetNumSteps(numTubes, 0, 1);
 
-  PARALLEL_FOR2(inputWorkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWorkspace, *outputWorkspace))
   for (int i = 0; i < numTubes; ++i) {
     PARALLEL_START_INTERUPT_REGION
-    auto current = tubeMap.begin();
-    std::advance(current, i);
+    auto current = std::next(tubeMap.begin(), i);
     const TubeIndex::mapped_type tubeIndices = current->second;
     bool mask = performBleedTest(tubeIndices, inputWorkspace, maxRate,
                                  numIgnoredPixels);
diff --git a/Framework/Algorithms/src/CrossCorrelate.cpp b/Framework/Algorithms/src/CrossCorrelate.cpp
index 1edbca62890..27a527d38c4 100644
--- a/Framework/Algorithms/src/CrossCorrelate.cpp
+++ b/Framework/Algorithms/src/CrossCorrelate.cpp
@@ -169,7 +169,7 @@ void CrossCorrelate::exec() {
   // Initialise the progress reporting object
   out->mutableX(0) = XX;
   m_progress = new Progress(this, 0.0, 1.0, nspecs);
-  PARALLEL_FOR2(inputWS, out)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *out))
   for (int i = 0; i < nspecs; ++i) // Now loop on all spectra
   {
     PARALLEL_START_INTERUPT_REGION
diff --git a/Framework/Algorithms/src/DetectorEfficiencyCor.cpp b/Framework/Algorithms/src/DetectorEfficiencyCor.cpp
index e396a47405e..f76796d8070 100644
--- a/Framework/Algorithms/src/DetectorEfficiencyCor.cpp
+++ b/Framework/Algorithms/src/DetectorEfficiencyCor.cpp
@@ -121,7 +121,7 @@ void DetectorEfficiencyCor::exec() {
   double numHists_d = static_cast<double>(numHists);
   const int64_t progStep = static_cast<int64_t>(ceil(numHists_d / 100.0));
 
-  PARALLEL_FOR2(m_inputWS, m_outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS))
   for (int64_t i = 0; i < numHists; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp b/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
index 6e63ff72590..0268ca3fdd3 100644
--- a/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
+++ b/Framework/Algorithms/src/DetectorEfficiencyCorUser.cpp
@@ -76,7 +76,7 @@ void DetectorEfficiencyCorUser::exec() {
       static_cast<int64_t>(numberOfSpectra); // cast to make openmp happy
 
   // Loop over the histograms (detector spectra)
-  PARALLEL_FOR2(m_outputWS, m_inputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_outputWS, *m_inputWS))
   for (int64_t i = 0; i < numberOfSpectra_i; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/DiffractionFocussing2.cpp b/Framework/Algorithms/src/DiffractionFocussing2.cpp
index b0f6575b906..f35dfe6ff89 100644
--- a/Framework/Algorithms/src/DiffractionFocussing2.cpp
+++ b/Framework/Algorithms/src/DiffractionFocussing2.cpp
@@ -170,9 +170,8 @@ void DiffractionFocussing2::exec() {
   Progress *prog;
   prog = new API::Progress(this, 0.2, 1.00,
                            static_cast<int>(totalHistProcess) + nGroups);
-#ifndef __APPLE__
-  PARALLEL_FOR2(m_matrixInputW, out)
-#endif
+
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_matrixInputW, *out))
   for (int outWorkspaceIndex = 0;
        outWorkspaceIndex < static_cast<int>(m_validGroups.size());
        outWorkspaceIndex++) {
@@ -181,9 +180,8 @@ void DiffractionFocussing2::exec() {
 
     // Get the group
     auto it = group2xvector.find(group);
-    group2vectormap::difference_type dif =
-        std::distance(group2xvector.begin(), it);
-    auto &Xout = (*it).second;
+    auto dif = std::distance(group2xvector.begin(), it);
+    auto &Xout = it->second;
 
     // Assign the new X axis only once (i.e when this group is encountered the
     // first time)
diff --git a/Framework/Algorithms/src/ExtractMask.cpp b/Framework/Algorithms/src/ExtractMask.cpp
index 31ba189d20e..e07e47e7a4a 100644
--- a/Framework/Algorithms/src/ExtractMask.cpp
+++ b/Framework/Algorithms/src/ExtractMask.cpp
@@ -74,7 +74,7 @@ void ExtractMask::exec() {
     MantidVecPtr xValues;
     xValues.access() = MantidVec(1, 0.0);
 
-    PARALLEL_FOR2(inputWS, maskWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe((*inputWS, *maskWS))
     for (int i = 0; i < nHist; ++i) {
       PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/ExtractSpectra.cpp b/Framework/Algorithms/src/ExtractSpectra.cpp
index 9581e735c9e..c2871a39620 100644
--- a/Framework/Algorithms/src/ExtractSpectra.cpp
+++ b/Framework/Algorithms/src/ExtractSpectra.cpp
@@ -293,7 +293,7 @@ void ExtractSpectra::execEvent() {
   Progress prog(this, 0.0, 1.0, 2 * m_workspaceIndexList.size());
   eventW->sortAll(Mantid::DataObjects::TOF_SORT, &prog);
   // Loop over the required workspace indices, copying in the desired bins
-  PARALLEL_FOR2(m_inputWorkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWorkspace, *outputWorkspace))
   for (int j = 0; j < static_cast<int>(m_workspaceIndexList.size()); ++j) {
     PARALLEL_START_INTERUPT_REGION
     auto i = m_workspaceIndexList[j];
diff --git a/Framework/Algorithms/src/He3TubeEfficiency.cpp b/Framework/Algorithms/src/He3TubeEfficiency.cpp
index aa3cbf5d2bd..72052a9840a 100644
--- a/Framework/Algorithms/src/He3TubeEfficiency.cpp
+++ b/Framework/Algorithms/src/He3TubeEfficiency.cpp
@@ -117,7 +117,7 @@ void He3TubeEfficiency::exec() {
   std::size_t numHists = this->inputWS->getNumberHistograms();
   this->progress = new API::Progress(this, 0.0, 1.0, numHists);
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int i = 0; i < static_cast<int>(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/Integration.cpp b/Framework/Algorithms/src/Integration.cpp
index b035bf502ef..0e06abbe111 100644
--- a/Framework/Algorithms/src/Integration.cpp
+++ b/Framework/Algorithms/src/Integration.cpp
@@ -141,7 +141,7 @@ void Integration::exec() {
   const bool axisIsNumeric = localworkspace->getAxis(1)->isNumeric();
 
   // Loop over spectra
-  PARALLEL_FOR2(localworkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*localworkspace, *outputWorkspace))
   for (int i = minSpec; i <= maxSpec; ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Workspace index on the output
diff --git a/Framework/Algorithms/src/MaxMin.cpp b/Framework/Algorithms/src/MaxMin.cpp
index 0e8bb126562..4b8142b6b81 100644
--- a/Framework/Algorithms/src/MaxMin.cpp
+++ b/Framework/Algorithms/src/MaxMin.cpp
@@ -88,7 +88,7 @@ void MaxMin::exec() {
                                                MaxSpec - MinSpec + 1, 2, 1);
 
   Progress progress(this, 0, 1, (MaxSpec - MinSpec + 1));
-  PARALLEL_FOR2(localworkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*localworkspace, *outputWorkspace))
   // Loop over spectra
   for (int i = MinSpec; i <= MaxSpec; ++i) {
     PARALLEL_START_INTERUPT_REGION
diff --git a/Framework/Algorithms/src/MedianDetectorTest.cpp b/Framework/Algorithms/src/MedianDetectorTest.cpp
index 98c72be2d03..ec1dd565999 100644
--- a/Framework/Algorithms/src/MedianDetectorTest.cpp
+++ b/Framework/Algorithms/src/MedianDetectorTest.cpp
@@ -314,7 +314,7 @@ int MedianDetectorTest::doDetectorTests(
                     (instrument->getSample() != nullptr));
   }
 
-  PARALLEL_FOR2(countsWS, maskWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*countsWS, *maskWS))
   for (int j = 0; j < static_cast<int>(indexmap.size()); ++j) {
     std::vector<size_t> hists = indexmap.at(j);
     double median = medianvec.at(j);
diff --git a/Framework/Algorithms/src/ModeratorTzero.cpp b/Framework/Algorithms/src/ModeratorTzero.cpp
index 97767babcff..ec95fa91037 100644
--- a/Framework/Algorithms/src/ModeratorTzero.cpp
+++ b/Framework/Algorithms/src/ModeratorTzero.cpp
@@ -127,7 +127,7 @@ void ModeratorTzero::exec() {
 
   const size_t numHists = static_cast<size_t>(inputWS->getNumberHistograms());
   Progress prog(this, 0.0, 1.0, numHists); // report progress of algorithm
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   // iterate over the spectra
   for (int i = 0; i < static_cast<int>(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
diff --git a/Framework/Algorithms/src/ModeratorTzeroLinear.cpp b/Framework/Algorithms/src/ModeratorTzeroLinear.cpp
index 6172b04da5c..4790a045253 100644
--- a/Framework/Algorithms/src/ModeratorTzeroLinear.cpp
+++ b/Framework/Algorithms/src/ModeratorTzeroLinear.cpp
@@ -131,7 +131,7 @@ void ModeratorTzeroLinear::exec() {
   // do the shift in X
   const size_t numHists = inputWS->getNumberHistograms();
   Progress prog(this, 0.0, 1.0, numHists); // report progress of algorithm
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int i = 0; i < static_cast<int>(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
     double t_f, L_i;
diff --git a/Framework/Algorithms/src/MonitorEfficiencyCorUser.cpp b/Framework/Algorithms/src/MonitorEfficiencyCorUser.cpp
index ee44bc929d7..bb91bd7c334 100644
--- a/Framework/Algorithms/src/MonitorEfficiencyCorUser.cpp
+++ b/Framework/Algorithms/src/MonitorEfficiencyCorUser.cpp
@@ -72,7 +72,7 @@ void MonitorEfficiencyCorUser::exec() {
 
   // Loop over the histograms (detector spectra)
   double factor = 1 / eff0;
-  PARALLEL_FOR2(m_outputWS, m_inputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_outputWS, *m_inputWS))
   for (int64_t i = 0; i < numberOfSpectra_i; ++i) {
     PARALLEL_START_INTERUPT_REGION
     m_outputWS->setHistogram(i, m_inputWS->histogram(i) * factor);
diff --git a/Framework/Algorithms/src/MultiplyRange.cpp b/Framework/Algorithms/src/MultiplyRange.cpp
index 817fd188d40..877e9bb95cb 100644
--- a/Framework/Algorithms/src/MultiplyRange.cpp
+++ b/Framework/Algorithms/src/MultiplyRange.cpp
@@ -71,7 +71,7 @@ void MultiplyRange::exec() {
   const int histogramCount = static_cast<int>(inputWS->getNumberHistograms());
   Progress progress(this, 0.0, 1.0, histogramCount);
   // Loop over spectra
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int i = 0; i < histogramCount; ++i) {
     PARALLEL_START_INTERUPT_REGION
     outputWS->setHistogram(i, inputWS->histogram(i));
diff --git a/Framework/Algorithms/src/NormaliseByDetector.cpp b/Framework/Algorithms/src/NormaliseByDetector.cpp
index 3b2ff40bd6a..91430566a62 100644
--- a/Framework/Algorithms/src/NormaliseByDetector.cpp
+++ b/Framework/Algorithms/src/NormaliseByDetector.cpp
@@ -178,7 +178,7 @@ NormaliseByDetector::processHistograms(MatrixWorkspace_sptr inWS) {
   // Choose between parallel execution and sequential execution then, process
   // histograms accordingly.
   if (m_parallelExecution) {
-    PARALLEL_FOR2(inWS, denominatorWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *denominatorWS))
     for (int wsIndex = 0; wsIndex < static_cast<int>(nHistograms); ++wsIndex) {
       PARALLEL_START_INTERUPT_REGION
       this->processHistogram(wsIndex, denominatorWS, inWS, prog);
diff --git a/Framework/Algorithms/src/Q1DWeighted.cpp b/Framework/Algorithms/src/Q1DWeighted.cpp
index 5f717b8dd3f..e150a719988 100644
--- a/Framework/Algorithms/src/Q1DWeighted.cpp
+++ b/Framework/Algorithms/src/Q1DWeighted.cpp
@@ -160,7 +160,7 @@ void Q1DWeighted::exec() {
 
   const auto &spectrumInfo = inputWS->spectrumInfo();
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   // Loop over all xLength-1 detector channels
   // Note: xLength -1, because X is a histogram and has a number of boundaries
   // equal to the number of detector channels + 1.
diff --git a/Framework/Algorithms/src/Qxy.cpp b/Framework/Algorithms/src/Qxy.cpp
index 8f5389434b3..8e373a1f637 100644
--- a/Framework/Algorithms/src/Qxy.cpp
+++ b/Framework/Algorithms/src/Qxy.cpp
@@ -123,9 +123,7 @@ void Qxy::exec() {
 
   const auto &spectrumInfo = inputWorkspace->spectrumInfo();
 
-  //  PARALLEL_FOR2(inputWorkspace,outputWorkspace)
   for (int64_t i = 0; i < int64_t(numSpec); ++i) {
-    //    PARALLEL_START_INTERUPT_REGION
     // Get the pixel relating to this spectrum
     IDetector_const_sptr det;
     try {
@@ -290,9 +288,7 @@ void Qxy::exec() {
 
     prog.report("Calculating Q");
 
-    //    PARALLEL_END_INTERUPT_REGION
   } // loop over all spectra
-  //  PARALLEL_CHECK_INTERUPT_REGION
 
   // take sqrt of error weight values
   // left to be executed here for computational efficiency
diff --git a/Framework/Algorithms/src/Rebin.cpp b/Framework/Algorithms/src/Rebin.cpp
index 64388219cf6..b7729e557e1 100644
--- a/Framework/Algorithms/src/Rebin.cpp
+++ b/Framework/Algorithms/src/Rebin.cpp
@@ -247,7 +247,7 @@ void Rebin::exec() {
       outputWS->replaceAxis(1, inputWS->getAxis(1)->clone(outputWS.get()));
 
     Progress prog(this, 0.0, 1.0, histnumber);
-    PARALLEL_FOR2(inputWS, outputWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
     for (int hist = 0; hist < histnumber; ++hist) {
       PARALLEL_START_INTERUPT_REGION
       // get const references to input Workspace arrays (no copying)
diff --git a/Framework/Algorithms/src/Rebin2D.cpp b/Framework/Algorithms/src/Rebin2D.cpp
index f1a38bd712b..dbfe5460447 100644
--- a/Framework/Algorithms/src/Rebin2D.cpp
+++ b/Framework/Algorithms/src/Rebin2D.cpp
@@ -118,7 +118,7 @@ void Rebin2D::exec() {
   m_progress = boost::shared_ptr<API::Progress>(
       new API::Progress(this, 0.0, 1.0, nreports));
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < static_cast<int64_t>(numYBins);
        ++i) // signed for openmp
   {
diff --git a/Framework/Algorithms/src/RebinByPulseTimes.cpp b/Framework/Algorithms/src/RebinByPulseTimes.cpp
index c52af972f76..6067ef19a52 100644
--- a/Framework/Algorithms/src/RebinByPulseTimes.cpp
+++ b/Framework/Algorithms/src/RebinByPulseTimes.cpp
@@ -50,7 +50,7 @@ void RebinByPulseTimes::doHistogramming(IEventWorkspace_sptr inWS,
 
   auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
 
-  PARALLEL_FOR2(inWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
   for (int i = 0; i < histnumber; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/RebinByTimeAtSample.cpp b/Framework/Algorithms/src/RebinByTimeAtSample.cpp
index e6e0446fb71..cb0445ff596 100644
--- a/Framework/Algorithms/src/RebinByTimeAtSample.cpp
+++ b/Framework/Algorithms/src/RebinByTimeAtSample.cpp
@@ -61,7 +61,7 @@ void RebinByTimeAtSample::doHistogramming(IEventWorkspace_sptr inWS,
   auto x = Kernel::make_cow<HistogramData::HistogramX>(OutXValues_scaled);
 
   // Go through all the histograms and set the data
-  PARALLEL_FOR2(inWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outputWS))
   for (int i = 0; i < histnumber; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/Rebunch.cpp b/Framework/Algorithms/src/Rebunch.cpp
index 8dfa51318a3..a7fb024357b 100644
--- a/Framework/Algorithms/src/Rebunch.cpp
+++ b/Framework/Algorithms/src/Rebunch.cpp
@@ -79,7 +79,7 @@ void Rebunch::exec() {
   int progress_step = histnumber / 100;
   if (progress_step == 0)
     progress_step = 1;
-  PARALLEL_FOR2(inputW, outputW)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputW, *outputW))
   for (int hist = 0; hist < histnumber; hist++) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/RemoveBackground.cpp b/Framework/Algorithms/src/RemoveBackground.cpp
index b63c667ae70..ffc385ad655 100644
--- a/Framework/Algorithms/src/RemoveBackground.cpp
+++ b/Framework/Algorithms/src/RemoveBackground.cpp
@@ -116,7 +116,7 @@ void RemoveBackground::exec() {
                                 inPlace, nullifyNegative);
 
   Progress prog(this, 0.0, 1.0, histnumber);
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int hist = 0; hist < histnumber; ++hist) {
     PARALLEL_START_INTERUPT_REGION
     // get references to output Workspace X-arrays.
diff --git a/Framework/Algorithms/src/RemoveExpDecay.cpp b/Framework/Algorithms/src/RemoveExpDecay.cpp
index f8b53edef4b..c8e7dc7edff 100644
--- a/Framework/Algorithms/src/RemoveExpDecay.cpp
+++ b/Framework/Algorithms/src/RemoveExpDecay.cpp
@@ -77,7 +77,7 @@ void MuonRemoveExpDecay::exec() {
   if (inputWS != outputWS) {
 
     // Copy all the Y and E data
-    PARALLEL_FOR2(inputWS, outputWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
     for (int64_t i = 0; i < int64_t(numSpectra); ++i) {
       PARALLEL_START_INTERUPT_REGION
       const auto index = static_cast<size_t>(i);
@@ -91,7 +91,7 @@ void MuonRemoveExpDecay::exec() {
 
   // Do the specified spectra only
   int specLength = static_cast<int>(spectra.size());
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int i = 0; i < specLength; ++i) {
     PARALLEL_START_INTERUPT_REGION
     const auto specNum = static_cast<size_t>(spectra[i]);
diff --git a/Framework/Algorithms/src/ResampleX.cpp b/Framework/Algorithms/src/ResampleX.cpp
index b40eaafee21..9e13cdf4d6e 100644
--- a/Framework/Algorithms/src/ResampleX.cpp
+++ b/Framework/Algorithms/src/ResampleX.cpp
@@ -340,7 +340,7 @@ void ResampleX::exec() {
         Progress prog(this, 0.0, 1.0, numSpectra);
 
         // do the rebinning
-        PARALLEL_FOR2(inputEventWS, outputWS)
+        PARALLEL_FOR_IF(Kernel::threadSafe(*inputEventWS, *outputWS))
         for (int wkspIndex = 0; wkspIndex < numSpectra; ++wkspIndex) {
           PARALLEL_START_INTERUPT_REGION
           BinEdges xValues(0);
@@ -375,7 +375,7 @@ void ResampleX::exec() {
       Progress prog(this, 0.0, 1.0, numSpectra);
 
       // Go through all the histograms and set the data
-      PARALLEL_FOR2(inputEventWS, outputWS)
+      PARALLEL_FOR_IF(Kernel::threadSafe(*inputEventWS, *outputWS))
       for (int wkspIndex = 0; wkspIndex < numSpectra; ++wkspIndex) {
         PARALLEL_START_INTERUPT_REGION
 
@@ -445,7 +445,7 @@ void ResampleX::exec() {
       outputWS->replaceAxis(1, inputWS->getAxis(1)->clone(outputWS.get()));
 
     Progress prog(this, 0.0, 1.0, numSpectra);
-    PARALLEL_FOR2(inputWS, outputWS)
+    PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
     for (int wkspIndex = 0; wkspIndex < numSpectra; ++wkspIndex) {
       PARALLEL_START_INTERUPT_REGION
       // get const references to input Workspace arrays (no copying)
diff --git a/Framework/Algorithms/src/ResetNegatives.cpp b/Framework/Algorithms/src/ResetNegatives.cpp
index c1e0ce16578..5cb840c07c2 100644
--- a/Framework/Algorithms/src/ResetNegatives.cpp
+++ b/Framework/Algorithms/src/ResetNegatives.cpp
@@ -93,7 +93,7 @@ void ResetNegatives::exec() {
 
   // generate output workspace - copy X and dY
   outputWS = API::WorkspaceFactory::Instance().create(inputWS);
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < nHist; i++) {
     PARALLEL_START_INTERUPT_REGION
     const auto index = static_cast<size_t>(i);
@@ -138,7 +138,7 @@ inline double fixZero(const double value) {
 void ResetNegatives::pushMinimum(MatrixWorkspace_const_sptr minWS,
                                  MatrixWorkspace_sptr wksp, Progress &prog) {
   int64_t nHist = minWS->getNumberHistograms();
-  PARALLEL_FOR2(wksp, minWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*wksp, *minWS))
   for (int64_t i = 0; i < nHist; i++) {
     PARALLEL_START_INTERUPT_REGION
     double minValue = minWS->y(i)[0];
@@ -170,7 +170,7 @@ void ResetNegatives::changeNegatives(MatrixWorkspace_const_sptr minWS,
                                      MatrixWorkspace_sptr wksp,
                                      Progress &prog) {
   int64_t nHist = wksp->getNumberHistograms();
-  PARALLEL_FOR2(minWS, wksp)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*minWS, *wksp))
   for (int64_t i = 0; i < nHist; i++) {
     PARALLEL_START_INTERUPT_REGION
     if (minWS->y(i)[0] <=
diff --git a/Framework/Algorithms/src/SampleCorrections/MayersSampleCorrection.cpp b/Framework/Algorithms/src/SampleCorrections/MayersSampleCorrection.cpp
index 3792bcd460a..8fbb84a2d88 100644
--- a/Framework/Algorithms/src/SampleCorrections/MayersSampleCorrection.cpp
+++ b/Framework/Algorithms/src/SampleCorrections/MayersSampleCorrection.cpp
@@ -101,7 +101,7 @@ void MayersSampleCorrection::exec() {
   Progress prog(this, 0., 1., nhist);
   prog.setNotifyStep(0.01);
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < static_cast<int64_t>(nhist); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/ScaleX.cpp b/Framework/Algorithms/src/ScaleX.cpp
index f80e8b9b6b1..3f6b646782e 100644
--- a/Framework/Algorithms/src/ScaleX.cpp
+++ b/Framework/Algorithms/src/ScaleX.cpp
@@ -123,7 +123,7 @@ void ScaleX::exec() {
   }
 
   // do the shift in X
-  PARALLEL_FOR2(inputW, outputW)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputW, *outputW))
   for (int i = 0; i < histnumber; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/SetUncertainties.cpp b/Framework/Algorithms/src/SetUncertainties.cpp
index c50c15891b0..c9c597c01bb 100644
--- a/Framework/Algorithms/src/SetUncertainties.cpp
+++ b/Framework/Algorithms/src/SetUncertainties.cpp
@@ -111,7 +111,7 @@ void SetUncertainties::exec() {
   const size_t numHists = inputWorkspace->getNumberHistograms();
   Progress prog(this, 0.0, 1.0, numHists);
 
-  PARALLEL_FOR2(inputWorkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWorkspace, *outputWorkspace))
   for (int64_t i = 0; i < int64_t(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/SmoothData.cpp b/Framework/Algorithms/src/SmoothData.cpp
index 9d29d867e13..4a70205ccf0 100644
--- a/Framework/Algorithms/src/SmoothData.cpp
+++ b/Framework/Algorithms/src/SmoothData.cpp
@@ -62,7 +62,7 @@ void SmoothData::exec() {
       WorkspaceFactory::Instance().create(inputWorkspace);
 
   Progress progress(this, 0.0, 1.0, inputWorkspace->getNumberHistograms());
-  PARALLEL_FOR2(inputWorkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWorkspace, *outputWorkspace)
   // Loop over all the spectra in the workspace
   for (int i = 0; i < static_cast<int>(inputWorkspace->getNumberHistograms());
        ++i) {
diff --git a/Framework/Algorithms/src/SmoothNeighbours.cpp b/Framework/Algorithms/src/SmoothNeighbours.cpp
index 66ebfbc23b5..51b23fd3a28 100644
--- a/Framework/Algorithms/src/SmoothNeighbours.cpp
+++ b/Framework/Algorithms/src/SmoothNeighbours.cpp
@@ -620,7 +620,7 @@ void SmoothNeighbours::execWorkspace2D() {
   // API::WorkspaceFactory::Instance().initializeFromParent(inWS, outWS, false);
 
   // Go through all the output workspace
-  PARALLEL_FOR2(inWS, outWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *outWS))
   for (int outWIi = 0; outWIi < int(numberOfSpectra); outWIi++) {
     PARALLEL_START_INTERUPT_REGION
 
@@ -772,7 +772,7 @@ void SmoothNeighbours::execEvent(Mantid::DataObjects::EventWorkspace_sptr ws) {
                     boost::dynamic_pointer_cast<MatrixWorkspace>(outWS));
 
   // Go through all the output workspace
-  PARALLEL_FOR2(ws, outWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*ws, *outWS))
   for (int outWIi = 0; outWIi < int(numberOfSpectra); outWIi++) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp
index 40425927825..aa3c21d4153 100644
--- a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp
+++ b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp
@@ -103,7 +103,7 @@ void SofQWNormalisedPolygon::exec() {
   const auto &X = inputWS->x(0);
   int emode = m_EmodeProperties.m_emode;
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < static_cast<int64_t>(nHistos);
        ++i) // signed for openmp
   {
diff --git a/Framework/Algorithms/src/SofQWPolygon.cpp b/Framework/Algorithms/src/SofQWPolygon.cpp
index 1e55da72e90..cceb6adc60c 100644
--- a/Framework/Algorithms/src/SofQWPolygon.cpp
+++ b/Framework/Algorithms/src/SofQWPolygon.cpp
@@ -75,7 +75,7 @@ void SofQWPolygon::exec() {
     qCalculator = &SofQWPolygon::calculateIndirectQ;
   }
 
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int64_t i = 0; i < static_cast<int64_t>(nTheta);
        ++i) // signed for openmp
   {
diff --git a/Framework/Algorithms/src/SolidAngle.cpp b/Framework/Algorithms/src/SolidAngle.cpp
index d9a5464c223..06c60b3f0be 100644
--- a/Framework/Algorithms/src/SolidAngle.cpp
+++ b/Framework/Algorithms/src/SolidAngle.cpp
@@ -101,7 +101,7 @@ void SolidAngle::exec() {
   Progress prog(this, 0.0, 1.0, numberOfSpectra);
 
   // Loop over the histograms (detector spectra)
-  PARALLEL_FOR2(outputWS, inputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS, *inputWS))
   for (int j = 0; j <= loopIterations; ++j) {
     PARALLEL_START_INTERUPT_REGION
     int i = j + m_MinSpec;
diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp
index 247c7dc2166..eafb16cae72 100644
--- a/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Framework/Algorithms/src/Stitch1D.cpp
@@ -60,7 +60,7 @@ MatrixWorkspace_sptr Stitch1D::maskAllBut(int a1, int a2,
                                           MatrixWorkspace_sptr &source) {
   MatrixWorkspace_sptr product = WorkspaceFactory::Instance().create(source);
   const int histogramCount = static_cast<int>(source->getNumberHistograms());
-  PARALLEL_FOR2(source, product)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*source, *product))
   for (int i = 0; i < histogramCount; ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Copy over the bin boundaries
diff --git a/Framework/Algorithms/src/TOFSANSResolution.cpp b/Framework/Algorithms/src/TOFSANSResolution.cpp
index 6ec683c5a0c..d5e283b604d 100644
--- a/Framework/Algorithms/src/TOFSANSResolution.cpp
+++ b/Framework/Algorithms/src/TOFSANSResolution.cpp
@@ -131,7 +131,7 @@ void TOFSANSResolution::exec() {
   const auto &spectrumInfo = reducedWS->spectrumInfo();
   const double L1 = spectrumInfo.l1();
 
-  PARALLEL_FOR2(reducedWS, iqWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*reducedWS, *iqWS))
   for (int i = 0; i < numberOfSpectra; i++) {
     PARALLEL_START_INTERUPT_REGION
     if (!spectrumInfo.hasDetectors(i)) {
diff --git a/Framework/Algorithms/src/Transpose.cpp b/Framework/Algorithms/src/Transpose.cpp
index 79e77ea269c..2d834bc6c27 100644
--- a/Framework/Algorithms/src/Transpose.cpp
+++ b/Framework/Algorithms/src/Transpose.cpp
@@ -52,7 +52,7 @@ void Transpose::exec() {
       Kernel::make_cow<HistogramData::HistogramX>(std::move(newXValues));
 
   Progress progress(this, 0.0, 1.0, newNhist * newYsize);
-  PARALLEL_FOR2(inputWorkspace, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWorkspace, *outputWorkspace))
   for (int64_t i = 0; i < static_cast<int64_t>(newNhist); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Algorithms/src/UnaryOperation.cpp b/Framework/Algorithms/src/UnaryOperation.cpp
index ebeb073f94f..9f62f1e0901 100644
--- a/Framework/Algorithms/src/UnaryOperation.cpp
+++ b/Framework/Algorithms/src/UnaryOperation.cpp
@@ -76,7 +76,7 @@ void UnaryOperation::exec() {
 
   // Loop over every cell in the workspace, calling the abstract correction
   // function
-  PARALLEL_FOR2(in_work, out_work)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*in_work, *out_work))
   for (int64_t i = 0; i < int64_t(numSpec); ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Copy the X values over
diff --git a/Framework/Algorithms/src/UnwrapSNS.cpp b/Framework/Algorithms/src/UnwrapSNS.cpp
index b58faed5ae2..52cb486887e 100644
--- a/Framework/Algorithms/src/UnwrapSNS.cpp
+++ b/Framework/Algorithms/src/UnwrapSNS.cpp
@@ -136,7 +136,7 @@ void UnwrapSNS::exec() {
   const auto &spectrumInfo = m_inputWS->spectrumInfo();
   const double L1 = spectrumInfo.l1();
 
-  PARALLEL_FOR2(m_inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *outputWS))
   for (int workspaceIndex = 0; workspaceIndex < m_numberOfSpectra;
        workspaceIndex++) {
     PARALLEL_START_INTERUPT_REGION
@@ -199,10 +199,8 @@ void UnwrapSNS::execEvent() {
   const double L1 = spectrumInfo.l1();
 
   // do the actual work
-  //  PARALLEL_FOR2(m_inputWS, outW)
   for (int workspaceIndex = 0; workspaceIndex < m_numberOfSpectra;
        workspaceIndex++) {
-    //    PARALLEL_START_INTERUPT_REGION
     std::size_t numEvents = outW->getSpectrum(workspaceIndex).getNumberEvents();
     double Ld = -1.0;
     if (spectrumInfo.hasDetectors(workspaceIndex))
@@ -228,9 +226,7 @@ void UnwrapSNS::execEvent() {
       outW->getSpectrum(workspaceIndex).setTofs(times);
     }
     m_progress->report();
-    //    PARALLEL_END_INTERUPT_REGION
   }
-  //  PARALLEL_CHECK_INTERUPT_REGION
 
   outW->clearMRU();
   this->runMaskDetectors();
diff --git a/Framework/Algorithms/src/WorkspaceJoiners.cpp b/Framework/Algorithms/src/WorkspaceJoiners.cpp
index c767982fc2b..28bb6d13ce9 100644
--- a/Framework/Algorithms/src/WorkspaceJoiners.cpp
+++ b/Framework/Algorithms/src/WorkspaceJoiners.cpp
@@ -50,7 +50,7 @@ WorkspaceJoiners::execWS2D(API::MatrixWorkspace_const_sptr ws1,
 
   // Loop over the input workspaces in turn copying the data into the output one
   const int64_t &nhist1 = ws1->getNumberHistograms();
-  PARALLEL_FOR2(ws1, output)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*ws1, *output))
   for (int64_t i = 0; i < nhist1; ++i) {
     PARALLEL_START_INTERUPT_REGION
     auto &outSpec = output->getSpectrum(i);
@@ -80,7 +80,7 @@ WorkspaceJoiners::execWS2D(API::MatrixWorkspace_const_sptr ws1,
   // For second loop we use the offset from the first
   const int64_t &nhist2 = ws2->getNumberHistograms();
   const auto &spectrumInfo = ws2->spectrumInfo();
-  PARALLEL_FOR2(ws2, output)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*ws2, *output))
   for (int64_t j = 0; j < nhist2; ++j) {
     PARALLEL_START_INTERUPT_REGION
     // The spectrum in the output workspace
diff --git a/Framework/Algorithms/src/XDataConverter.cpp b/Framework/Algorithms/src/XDataConverter.cpp
index 0e893f24b42..290cc76352d 100644
--- a/Framework/Algorithms/src/XDataConverter.cpp
+++ b/Framework/Algorithms/src/XDataConverter.cpp
@@ -61,7 +61,7 @@ void XDataConverter::exec() {
     outputWS->replaceAxis(1, inputWS->getAxis(1)->clone(outputWS.get()));
 
   Progress prog(this, 0.0, 1.0, numSpectra);
-  PARALLEL_FOR2(inputWS, outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outputWS))
   for (int i = 0; i < int(numSpectra); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
@@ -102,4 +102,4 @@ void XDataConverter::setXData(API::MatrixWorkspace_sptr outputWS,
   }
 }
 }
-}
\ No newline at end of file
+}
diff --git a/Framework/Crystal/src/AnvredCorrection.cpp b/Framework/Crystal/src/AnvredCorrection.cpp
index 93b633615f0..b475e3df600 100644
--- a/Framework/Crystal/src/AnvredCorrection.cpp
+++ b/Framework/Crystal/src/AnvredCorrection.cpp
@@ -169,7 +169,7 @@ void AnvredCorrection::exec() {
 
   Progress prog(this, 0.0, 1.0, numHists);
   // Loop over the spectra
-  PARALLEL_FOR2(m_inputWS, correctionFactors)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *correctionFactors))
   for (int64_t i = 0; i < int64_t(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
@@ -282,7 +282,7 @@ void AnvredCorrection::execEvent() {
 
   Progress prog(this, 0.0, 1.0, numHists);
   // Loop over the spectra
-  PARALLEL_FOR2(eventW, correctionFactors)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*eventW, *correctionFactors))
   for (int64_t i = 0; i < int64_t(numHists); ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Crystal/src/CentroidPeaks.cpp b/Framework/Crystal/src/CentroidPeaks.cpp
index 73ea7b93305..8f59c8e22a0 100644
--- a/Framework/Crystal/src/CentroidPeaks.cpp
+++ b/Framework/Crystal/src/CentroidPeaks.cpp
@@ -87,7 +87,7 @@ void CentroidPeaks::integrate() {
 
   int Edge = getProperty("EdgePixels");
   Progress prog(this, MinPeaks, 1.0, MaxPeaks);
-  PARALLEL_FOR2(inWS, peakWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *peakWS))
   for (int i = MinPeaks; i <= MaxPeaks; i++) {
     PARALLEL_START_INTERUPT_REGION
     // Get a direct ref to that peak.
@@ -223,7 +223,7 @@ void CentroidPeaks::integrateEvent() {
 
   int Edge = getProperty("EdgePixels");
   Progress prog(this, MinPeaks, 1.0, MaxPeaks);
-  PARALLEL_FOR2(inWS, peakWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *peakWS))
   for (int i = MinPeaks; i <= MaxPeaks; i++) {
     PARALLEL_START_INTERUPT_REGION
     // Get a direct ref to that peak.
diff --git a/Framework/Crystal/src/NormaliseVanadium.cpp b/Framework/Crystal/src/NormaliseVanadium.cpp
index 08cbfb59c94..26423a185c5 100644
--- a/Framework/Crystal/src/NormaliseVanadium.cpp
+++ b/Framework/Crystal/src/NormaliseVanadium.cpp
@@ -67,7 +67,7 @@ void NormaliseVanadium::exec() {
 
   Progress prog(this, 0.0, 1.0, numHists);
   // Loop over the spectra
-  PARALLEL_FOR2(m_inputWS, correctionFactors)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *correctionFactors))
   for (int64_t i = 0; i < int64_t(numHists); ++i) {
     //    PARALLEL_START_INTERUPT_REGION //FIXME: Restore
 
diff --git a/Framework/Crystal/src/PeaksIntersection.cpp b/Framework/Crystal/src/PeaksIntersection.cpp
index 833a6d292a9..6051f4e2f2e 100644
--- a/Framework/Crystal/src/PeaksIntersection.cpp
+++ b/Framework/Crystal/src/PeaksIntersection.cpp
@@ -104,7 +104,7 @@ void PeaksIntersection::executePeaksIntersection(const bool checkPeakExtents) {
   }
   Progress prog(this, 0, 1, 100);
 
-  PARALLEL_FOR2(ws, outputWorkspace)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*ws, *outputWorkspace))
   for (int i = 0; i < nPeaks; ++i) {
     PARALLEL_START_INTERUPT_REGION
     IPeak *peak = ws->getPeakPtr(i);
diff --git a/Framework/CurveFitting/src/Algorithms/ConvertToYSpace.cpp b/Framework/CurveFitting/src/Algorithms/ConvertToYSpace.cpp
index 51f88a0f47b..fe99f86d374 100644
--- a/Framework/CurveFitting/src/Algorithms/ConvertToYSpace.cpp
+++ b/Framework/CurveFitting/src/Algorithms/ConvertToYSpace.cpp
@@ -196,7 +196,7 @@ void ConvertToYSpace::exec() {
   const int64_t nreports = nhist;
   auto progress = boost::make_shared<Progress>(this, 0.0, 1.0, nreports);
 
-  PARALLEL_FOR2(m_inputWS, m_outputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS))
   for (int64_t i = 0; i < nhist; ++i) {
     PARALLEL_START_INTERUPT_REGION
 
diff --git a/Framework/Kernel/inc/MantidKernel/MultiThreaded.h b/Framework/Kernel/inc/MantidKernel/MultiThreaded.h
index 07014cbba03..f85c13d73de 100644
--- a/Framework/Kernel/inc/MantidKernel/MultiThreaded.h
+++ b/Framework/Kernel/inc/MantidKernel/MultiThreaded.h
@@ -153,15 +153,6 @@ threadSafe(const Arg &workspace, Args &&... others) {
 #define PARALLEL_FOR1(workspace1)                                              \
     PRAGMA(omp parallel for if ( !workspace1 || workspace1->threadSafe() ) )
 
-/** Includes code to add OpenMP commands to run the next for loop in parallel.
-*	 Both workspaces are checked to ensure they suitable for multithreaded
-*access
-*  or equal to NULL which is also safe
-*/
-#define PARALLEL_FOR2(workspace1, workspace2)                                   \
-    PRAGMA(omp parallel for if ( ( !workspace1 || workspace1->threadSafe() ) && \
-    ( !workspace2 || workspace2->threadSafe() ) ))
-
 /** Ensures that the next execution line or block is only executed if
 * there are multple threads execting in this region
 */
@@ -217,7 +208,6 @@ threadSafe(const Arg &workspace, Args &&... others) {
 #define PARALLEL_FOR_NOWS_CHECK_FIRSTPRIVATE(variable)
 #define PARALLEL_FOR_NO_WSP_CHECK_FIRSTPRIVATE2(variable1, variable2)
 #define PARALLEL_FOR1(workspace1)
-#define PARALLEL_FOR2(workspace1, workspace2)
 #define IF_PARALLEL if (false)
 #define IF_NOT_PARALLEL
 #define PARALLEL_CRITICAL(name)
diff --git a/Framework/MDAlgorithms/src/ThresholdMD.cpp b/Framework/MDAlgorithms/src/ThresholdMD.cpp
index 392fdf68750..d760285d3e0 100644
--- a/Framework/MDAlgorithms/src/ThresholdMD.cpp
+++ b/Framework/MDAlgorithms/src/ThresholdMD.cpp
@@ -109,7 +109,7 @@ void ThresholdMD::exec() {
     frequency = nPoints / 100;
   }
 
-  PARALLEL_FOR2(inputWS, outWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *outWS))
   for (int64_t i = 0; i < nPoints; ++i) {
     PARALLEL_START_INTERUPT_REGION
     const double signalAt = inputWS->getSignalAt(i);
diff --git a/Framework/WorkflowAlgorithms/src/SANSSolidAngleCorrection.cpp b/Framework/WorkflowAlgorithms/src/SANSSolidAngleCorrection.cpp
index 41accef33b2..4de89057f6f 100644
--- a/Framework/WorkflowAlgorithms/src/SANSSolidAngleCorrection.cpp
+++ b/Framework/WorkflowAlgorithms/src/SANSSolidAngleCorrection.cpp
@@ -110,7 +110,7 @@ void SANSSolidAngleCorrection::exec() {
   // Number of X bins
   const int xLength = static_cast<int>(inputWS->readY(0).size());
 
-  PARALLEL_FOR2(outputWS, inputWS)
+  PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS, *inputWS))
   for (int i = 0; i < numHists; ++i) {
     PARALLEL_START_INTERUPT_REGION
     outputWS->dataX(i) = inputWS->readX(i);
-- 
GitLab