Skip to content

Commit 06055cd

Browse files
authored
Merge pull request #38865 from mantidproject/bugfix_smoothNeighbours_ornl-next
Fix performance issue with smoothNeighbours
2 parents 3987545 + 3e7c3e1 commit 06055cd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Framework/Algorithms/src/SmoothNeighbours.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,24 @@ void SmoothNeighbours::execEvent(Mantid::DataObjects::EventWorkspace_sptr &ws) {
678678

679679
this->setProperty("OutputWorkspace", std::dynamic_pointer_cast<MatrixWorkspace>(outWS));
680680

681+
// Calculate total number of events for each EventList
682+
std::vector<size_t> outputEvents(numberOfSpectra, 0);
683+
for (int i = 0; i < int(numberOfSpectra); i++) {
684+
const std::vector<weightedNeighbour> &neighbours = m_neighbours[i];
685+
for (const auto &neighbour : neighbours) {
686+
size_t inWI = neighbour.first;
687+
outputEvents[i] += ws->getSpectrum(inWI).getNumberEvents();
688+
}
689+
}
690+
681691
// Go through all the output workspace
682692
PARALLEL_FOR_IF(Kernel::threadSafe(*ws, *outWS))
683693
for (int outWIi = 0; outWIi < int(numberOfSpectra); outWIi++) {
684694
PARALLEL_START_INTERRUPT_REGION
685695

686696
// Create the output event list (empty)
687697
EventList &outEL = outWS->getSpectrum(outWIi);
698+
outEL.reserve(outputEvents[outWIi]);
688699

689700
// Which are the neighbours?
690701
std::vector<weightedNeighbour> &neighbours = m_neighbours[outWIi];

0 commit comments

Comments
 (0)