Skip to content

Commit

Permalink
refs #5639. Parallel reporting working
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jul 24, 2012
1 parent f68505d commit 717ccb5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace API
{
/// Forward declaration for MatrixWorkspace.
class MatrixWorkspace;
class Progress;
}
namespace Algorithms
{
Expand Down Expand Up @@ -60,7 +61,7 @@ namespace Algorithms
/// Block to process histograms.
boost::shared_ptr<Mantid::API::MatrixWorkspace> processHistograms(boost::shared_ptr<Mantid::API::MatrixWorkspace> inWS);
/// Process indivdual histogram.
void processHistogram(size_t wsIndex, boost::shared_ptr<Mantid::API::MatrixWorkspace> denominatorWS, boost::shared_ptr<const Mantid::API::MatrixWorkspace> inWS);
void processHistogram(size_t wsIndex, boost::shared_ptr<Mantid::API::MatrixWorkspace> denominatorWS, boost::shared_ptr<const Mantid::API::MatrixWorkspace> inWS, Mantid::API::Progress& prog);
virtual void initDocs();
void init();
void exec();
Expand Down
17 changes: 11 additions & 6 deletions Code/Mantid/Framework/Algorithms/src/NormaliseByDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ A1 coefficient is provided for each detector. In this way the Algorithm sees a c
#include "MantidAPI/FunctionDomain1D.h"
#include "MantidAPI/FunctionValues.h"
#include "MantidAPI/WorkspaceValidators.h"
#include "MantidAPI/Progress.h"
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidGeometry/Instrument/Component.h"
#include "MantidGeometry/Instrument/DetectorGroup.h"
Expand Down Expand Up @@ -194,8 +195,9 @@ namespace Mantid
@param wsIndex: The index of the histogram in the input workspace to process.
@param denominatorWS : Workspace that will become the denominator in the normalisation routine.
@param inputWorkspace: Workspace input. Contains instrument to use as well as X data to use.
@param prog: progress reporting object.
*/
void NormaliseByDetector::processHistogram(size_t wsIndex, MatrixWorkspace_sptr denominatorWS, MatrixWorkspace_const_sptr inWS)
void NormaliseByDetector::processHistogram(size_t wsIndex, MatrixWorkspace_sptr denominatorWS, MatrixWorkspace_const_sptr inWS, Progress& prog)
{
const Geometry::ParameterMap& paramMap = inWS->instrumentParameters();
Geometry::IDetector_const_sptr det = inWS->getDetector( wsIndex );
Expand Down Expand Up @@ -252,6 +254,7 @@ namespace Mantid
}
denominatorWS->dataY(wsIndex) = outIntensity;
denominatorWS->dataE(wsIndex) = MantidVec(nInputBins, 0);
prog.report();
}

/**
Expand All @@ -261,23 +264,25 @@ namespace Mantid
*/
MatrixWorkspace_sptr NormaliseByDetector::processHistograms(MatrixWorkspace_sptr inWS)
{
const size_t nHistograms = inWS->getNumberHistograms();
const size_t progress_items = nHistograms * 1.2;
Progress prog(this,0.0,1.0, progress_items);
// Clone the input workspace to create a template for the denominator workspace.
IAlgorithm_sptr cloneAlg = this->createSubAlgorithm("CloneWorkspace", 0.0, 1.0, true);
IAlgorithm_sptr cloneAlg = this->createSubAlgorithm("CloneWorkspace", 0.0, 0.1, true);
cloneAlg->setProperty("InputWorkspace", inWS);
cloneAlg->setPropertyValue("OutputWorkspace", "temp");
cloneAlg->executeAsSubAlg();
Workspace_sptr temp = cloneAlg->getProperty("OutputWorkspace");
MatrixWorkspace_sptr denominatorWS = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);

// Choose between parallel execution and sequential execution then, process histograms accordingly.
const size_t nHistograms = inWS->getNumberHistograms();
if(m_parallelExecution == true)
{
PARALLEL_FOR2(inWS, denominatorWS)
for(int wsIndex = 0; wsIndex < static_cast<int>(nHistograms); ++wsIndex)
{
PARALLEL_START_INTERUPT_REGION
this->processHistogram(wsIndex, denominatorWS, inWS);
this->processHistogram(wsIndex, denominatorWS, inWS, prog);
PARALLEL_END_INTERUPT_REGION
}
PARALLEL_CHECK_INTERUPT_REGION
Expand All @@ -286,7 +291,7 @@ namespace Mantid
{
for(size_t wsIndex = 0; wsIndex < nHistograms; ++wsIndex)
{
this->processHistogram(wsIndex, denominatorWS, inWS);
this->processHistogram(wsIndex, denominatorWS, inWS, prog);
}
}

Expand All @@ -304,7 +309,7 @@ namespace Mantid
MatrixWorkspace_sptr denominatorWS = processHistograms(inWS);

// Perform the normalisation.
IAlgorithm_sptr divideAlg = this->createSubAlgorithm("Divide", 0.0, 1.0, true);
IAlgorithm_sptr divideAlg = this->createSubAlgorithm("Divide", 0.9, 1.0, true);
divideAlg->setRethrows(true);
divideAlg->setProperty("LHSWorkspace", inWS);
divideAlg->setProperty("RHSWorkspace", denominatorWS);
Expand Down

0 comments on commit 717ccb5

Please sign in to comment.