Skip to content

Commit

Permalink
Refs #4782 use parallel IMDIterator in SliceViewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Feb 10, 2012
1 parent c488944 commit bfa1005
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 28 deletions.
32 changes: 27 additions & 5 deletions Code/Mantid/Framework/MDEvents/src/MDBoxIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidMDEvents/MDBoxIterator.h"

using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::Geometry;

namespace Mantid
Expand Down Expand Up @@ -42,7 +43,8 @@ namespace MDEvents
m_max = m_boxes.size();
// Get the first box
if (m_max > 0)
m_current = m_boxes[0]; }
m_current = m_boxes[0];
}


//----------------------------------------------------------------------------------------------
Expand All @@ -68,7 +70,6 @@ namespace MDEvents
TMDE(
void MDBoxIterator)::init(std::vector<IMDBox<MDE,nd>*> & boxes, size_t begin, size_t end)
{
m_boxes.clear();
if (begin >= boxes.size())
throw std::runtime_error("MDBoxIterator::ctor(): invalid beginning position.");
size_t theEnd = end;
Expand All @@ -78,7 +79,8 @@ namespace MDEvents
theEnd = boxes.size();

// Copy the pointers to boxes in the range.
m_boxes.assign(boxes.begin() + begin, boxes.begin() + end);
m_boxes.clear();
m_boxes.insert(m_boxes.begin(), boxes.begin() + begin, boxes.begin() + theEnd);

m_max = m_boxes.size();
// Get the first box
Expand Down Expand Up @@ -200,13 +202,33 @@ namespace MDEvents
/// Returns the normalized signal for this box
TMDE(signal_t MDBoxIterator)::getNormalizedSignal() const
{
return m_current->getSignalNormalized();
// What is our normalization factor?
switch (m_normalization)
{
case NoNormalization:
return m_current->getSignal();
case VolumeNormalization:
return m_current->getSignal() * m_current->getInverseVolume();
case NumEventsNormalization:
return m_current->getSignal() * m_current->getNPoints();
}
return std::numeric_limits<signal_t>::quiet_NaN();
}

/// Returns the normalized error for this box
TMDE(signal_t MDBoxIterator)::getNormalizedError() const
{
return m_current->getError() * m_current->getInverseVolume();
// What is our normalization factor?
switch (m_normalization)
{
case NoNormalization:
return m_current->getError();
case VolumeNormalization:
return m_current->getError() * m_current->getInverseVolume();
case NumEventsNormalization:
return m_current->getError() * m_current->getNPoints();
}
return std::numeric_limits<signal_t>::quiet_NaN();
}

/// Returns the signal for this box
Expand Down
10 changes: 10 additions & 0 deletions Code/Mantid/MantidQt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

###########################################################################
# Add OpenMP flags here
###########################################################################
if ( OPENMP_FOUND )
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" )
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" )
endif ()

###########################################################################
# Now add the packages one-by-one, building up the dependencies as we go
###########################################################################
Expand All @@ -12,6 +21,7 @@ add_subdirectory ( DesignerPlugins )
add_subdirectory ( SliceViewer )
add_subdirectory ( Factory )


###########################################################################
# Add a custom target to build all of the MantidQt packages
###########################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public slots:
void updateDimensionSliceWidgets();
void resetAxis(int axis, Mantid::Geometry::IMDDimension_const_sptr dim);
QwtDoubleInterval getRange(Mantid::API::IMDIterator * it);
QwtDoubleInterval getRange(std::vector<Mantid::API::IMDIterator *> & iterators);
QwtDoubleInterval getRange(std::vector<Mantid::API::IMDIterator *> iterators);

void findRangeFull();
void findRangeSlice();
Expand Down
70 changes: 48 additions & 22 deletions Code/Mantid/MantidQt/SliceViewer/src/SliceViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "MantidKernel/V3D.h"
#include "MantidKernel/ReadLock.h"
#include "MantidQtAPI/SafeQwtPlot.h"
#include "MantidKernel/MultiThreaded.h"


using namespace Mantid;
Expand Down Expand Up @@ -922,7 +923,7 @@ void SliceViewer::resetAxis(int axis, Mantid::Geometry::IMDDimension_const_sptr
/** Get the range of signal given an iterator
*
* @param it :: IMDIterator of what to find
* @return the min/max range, or 0-1.0 if not found
* @return the min/max range, or INFINITY if not found
*/
QwtDoubleInterval SliceViewer::getRange(IMDIterator * it)
{
Expand All @@ -946,6 +947,47 @@ QwtDoubleInterval SliceViewer::getRange(IMDIterator * it)
}
} while (it->next());


if (minSignal == DBL_MAX)
{
minSignal = m_inf;
maxSignal = m_inf;
}
return QwtDoubleInterval(minSignal, maxSignal);
}

//------------------------------------------------------------------------------------
/** Get the range of signal, in parallel, given an iterator
*
* @param iterators :: vector of IMDIterator of what to find
* @return the min/max range, or 0-1.0 if not found
*/
QwtDoubleInterval SliceViewer::getRange(std::vector<IMDIterator *> iterators)
{
std::vector<QwtDoubleInterval> intervals(iterators.size());

PRAGMA_OMP( parallel for schedule(dynamic, 1))
for (int i=0; i < int(iterators.size()); i++)
{
IMDIterator * it = iterators[i];
QwtDoubleInterval range = this->getRange(iterators[i]);
intervals[i] = range;
delete it;
}

// Combine the overall min/max
double minSignal = DBL_MAX;
double maxSignal = -DBL_MAX;
for (size_t i=0; i < iterators.size(); i++)
{
double signal;
signal = intervals[i].minValue();
if (signal != m_inf && signal > 0 && signal < minSignal) minSignal = signal;

signal = intervals[i].maxValue();
if (signal != m_inf && signal > maxSignal) maxSignal = signal;
}

if (minSignal == DBL_MAX)
{
minSignal = 0.0;
Expand All @@ -959,25 +1001,11 @@ QwtDoubleInterval SliceViewer::getRange(IMDIterator * it)
// Possibly only one value in range
return QwtDoubleInterval(minSignal*0.5, minSignal*1.5);
else
// Other default value
return QwtDoubleInterval(0., 1.0);
}
}

//------------------------------------------------------------------------------------
/** Get the range of signal, in parallel, given an iterator
*
* @param iterators :: vector of IMDIterator of what to find
* @return the min/max range, or 0-1.0 if not found
*/
QwtDoubleInterval SliceViewer::getRange(std::vector<IMDIterator *> & iterators)
{
// PRAGMA_OMP( parallel for )
// for (int i=0; i < int(iterators.size(); i++)
// {
//
// }
}

//------------------------------------------------------------------------------------
/// Find the full range of values in the workspace
void SliceViewer::findRangeFull()
Expand All @@ -988,9 +1016,8 @@ void SliceViewer::findRangeFull()
ReadLock lock(*m_ws);

// Iterate through the entire workspace
IMDIterator * it = m_ws->createIterator();
m_colorRangeFull = getRange(it);
delete it;
std::vector<IMDIterator *> iterators = m_ws->createIterators(PARALLEL_GET_MAX_THREADS);
m_colorRangeFull = getRange(iterators);
}


Expand Down Expand Up @@ -1038,12 +1065,11 @@ void SliceViewer::findRangeSlice()
MDBoxImplicitFunction * function = new MDBoxImplicitFunction(min, max);

// Iterate through the slice
IMDIterator * it = m_ws->createIterator(function);
m_colorRangeSlice = getRange(it);
std::vector<IMDIterator *> iterators = m_ws->createIterators(PARALLEL_GET_MAX_THREADS, function);
m_colorRangeSlice = getRange(iterators);
// In case of failure, use the full range instead
if (m_colorRangeSlice == QwtDoubleInterval(0.0, 1.0))
m_colorRangeSlice = m_colorRangeFull;
delete it;
}


Expand Down

0 comments on commit bfa1005

Please sign in to comment.