Skip to content
Snippets Groups Projects
Commit 2ea79abe authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #11393. Use OMP macros.

parent 1b51c6b6
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,14 @@
#include "MantidKernel/System.h"
#include "MantidAPI/Algorithm.h"
#include <boost/shared_ptr.hpp>
namespace Mantid
{
namespace API
{
class IMDHistoWorkspace;
}
namespace MDAlgorithms
{
......@@ -43,7 +48,11 @@ namespace MDAlgorithms
virtual const std::string summary() const;
std::map<std::string, std::string> validateInputs();
boost::shared_ptr<Mantid::API::IMDHistoWorkspace> hatSmooth(boost::shared_ptr<const Mantid::API::IMDHistoWorkspace> toSmooth,
const std::vector<int> &widthVector);
private:
void init();
void exec();
......
......@@ -18,6 +18,7 @@
#include <sstream>
#include <utility>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/tuple/tuple.hpp>
......@@ -27,7 +28,7 @@ using namespace Mantid::MDEvents;
typedef std::vector<int> WidthVector;
typedef boost::function<IMDHistoWorkspace_sptr(
IMDHistoWorkspace_const_sptr, const WidthVector &, Progress& )> SmoothFunction;
IMDHistoWorkspace_const_sptr, const WidthVector &)> SmoothFunction;
typedef std::map<std::string, SmoothFunction> SmoothFunctionMap;
namespace {
......@@ -43,17 +44,61 @@ std::vector<std::string> functions() {
return propOptions;
}
/**
* Maps a function name to a smoothing function
* @return function map
*/
SmoothFunctionMap makeFunctionMap(Mantid::MDAlgorithms::SmoothMD * instance) {
SmoothFunctionMap map;
map.insert(std::make_pair("Hat", boost::bind( &Mantid::MDAlgorithms::SmoothMD::hatSmooth, instance, _1, _2 )));
return map;
}
}
namespace Mantid {
namespace MDAlgorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(SmoothMD)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SmoothMD::SmoothMD() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
SmoothMD::~SmoothMD() {}
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const std::string SmoothMD::name() const { return "SmoothMD"; }
/// Algorithm's version for identification. @see Algorithm::version
int SmoothMD::version() const { return 1; };
/// Algorithm's category for identification. @see Algorithm::category
const std::string SmoothMD::category() const { return "MDAlgorithms"; }
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string SmoothMD::summary() const {
return "Smooth an MDHistoWorkspace according to a weight function";
};
/**
* Hat function smoothing. All weights even. Hat function boundaries beyond
* width.
* @param toSmooth : Workspace to smooth
* @param widthVector : Width vector
* @param progress : progress object
* @return Smoothed MDHistoWorkspace
*/
IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
const WidthVector &widthVector, Progress& progress) {
IMDHistoWorkspace_sptr SmoothMD::hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
const WidthVector &widthVector) {
Progress progress(this, 0, 1, size_t( toSmooth->getNPoints() ) );
// Create the output workspace.
IMDHistoWorkspace_sptr outWS = toSmooth->clone();
......@@ -62,11 +107,13 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
auto iterators = toSmooth->createIterators(nThreads, NULL);
PRAGMA_OMP( parallel for schedule(dynamic, 1))
for (int it = 0; it < iterators.size(); ++it) {
PARALLEL_FOR_NO_WSP_CHECK()
for (int it = 0; it < int(iterators.size()); ++it) {
boost::scoped_ptr<MDHistoWorkspaceIterator> iterator(
dynamic_cast<MDHistoWorkspaceIterator *>(iterators[it]));
size_t counter = 0;
do {
// Gets all vertex-touching neighbours
......@@ -90,7 +137,10 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
outWS->setErrorSquaredAt(iterator->getLinearIndex(),
sumSqError / (nNeighbours + 1));
progress.report();
if(counter % 1000 == 0) {
progress.report();
}
++counter;
} while (iterator->next());
}
......@@ -98,48 +148,6 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
return outWS;
}
/**
* Maps a function name to a smoothing function
* @return function map
*/
SmoothFunctionMap makeFunctionMap() {
SmoothFunctionMap map;
map.insert(std::make_pair("Hat", hatSmooth));
return map;
}
}
namespace Mantid {
namespace MDAlgorithms {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(SmoothMD)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SmoothMD::SmoothMD() {}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
SmoothMD::~SmoothMD() {}
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const std::string SmoothMD::name() const { return "SmoothMD"; }
/// Algorithm's version for identification. @see Algorithm::version
int SmoothMD::version() const { return 1; };
/// Algorithm's category for identification. @see Algorithm::category
const std::string SmoothMD::category() const { return "MDAlgorithms"; }
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string SmoothMD::summary() const {
return "Smooth an MDHistoWorkspace according to a weight function";
};
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
......@@ -191,12 +199,10 @@ void SmoothMD::exec() {
// Find the choosen smooth operation
const std::string smoothFunctionName = this->getProperty("Function");
SmoothFunctionMap functionMap = makeFunctionMap();
SmoothFunctionMap functionMap = makeFunctionMap(this);
SmoothFunction smoothFunction = functionMap[smoothFunctionName];
Progress progress(this, 0, 1, size_t(toSmooth->getNPoints() ) );
// invoke the smoothing operation
auto smoothed = smoothFunction(toSmooth, widthVector, progress);
auto smoothed = smoothFunction(toSmooth, widthVector);
setProperty("OutputWorkspace", smoothed);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment