Skip to content

Commit 18fdd0b

Browse files
mutex added
1 parent 7a981d3 commit 18fdd0b

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

Framework/Algorithms/inc/MantidAlgorithms/FindPeaksConvolve.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class MANTID_ALGORITHMS_DLL FindPeaksConvolve : public API::Algorithm {
6666
bool m_centreBins;
6767
Eigen::VectorXd m_pdf;
6868
std::vector<std::string> m_intermediateWsNames;
69-
std::mutex mtx;
69+
std::mutex m_mtx;
7070

7171
void init() override;
7272
void exec() override;

Framework/Algorithms/src/FindPeaksConvolve.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,54 +188,70 @@ void FindPeaksConvolve::performConvolution(const size_t dataIndex) {
188188
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
189189
const auto specNum{m_specNums[dataIndex]};
190190
const HistogramData::HistogramX *xData{&m_inputDataWS->x(specNum)};
191-
std::cout << "performConvolution 2" << std::endl; // TODO remove
191+
std::cout << "performConvolution 2"
192+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
192193
std::pair<const size_t, const bool> kernelBinCount{getKernelBinCount(xData)};
193-
std::cout << "performConvolution 3" << std::endl; // TODO remove
194+
std::cout << "performConvolution 3"
195+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
194196
if (kernelBinCount.second) {
195197
g_log.error("The kernel size for spectrum " + std::to_string(m_specNums[dataIndex]) +
196198
" exceeds the range of the x axis. Please reduce the peak extent.");
197199
} else {
198-
std::cout << "performConvolution 4" << std::endl; // TODO remove
200+
std::cout << "performConvolution 4"
201+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
199202
const Tensor1D kernel{createKernel(static_cast<int>(kernelBinCount.first))};
200-
std::cout << "performConvolution 5" << std::endl; // TODO remove
203+
std::cout << "performConvolution 5"
204+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
201205
const auto binCount{m_inputDataWS->getNumberBins(specNum)};
202206
// Edge handling is performed by padding the input data with 0 values. Each convolution requires a padding of kernel
203207
// size + 1. The 1st conv is performed with a kernel of size n, the second size n/2. The resultant pad is split
204208
// either side of the data.
205209
const double paddingSize = (std::ceil(static_cast<double>(kernelBinCount.first) * 1.5) - 2) / 2;
206-
std::cout << "performConvolution 6" << std::endl; // TODO remove
210+
std::cout << "performConvolution 6"
211+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
207212
const TensorMap_const yData{&m_inputDataWS->y(specNum).front(), binCount};
208-
std::cout << "performConvolution 7" << std::endl; // TODO remove
213+
std::cout << "performConvolution 7"
214+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
209215
Eigen::array<std::pair<double, double>, 1> paddings{
210216
std::make_pair(std::ceil(paddingSize), std::floor(paddingSize))};
211-
std::cout << "performConvolution 8" << std::endl; // TODO remove
217+
std::cout << "performConvolution 8"
218+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
212219
const auto yData_padded{yData.pad(paddings)};
213-
std::cout << "performConvolution 9" << std::endl; // TODO remove
220+
std::cout << "performConvolution 9"
221+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
214222
const Eigen::array<ptrdiff_t, 1> dims({0});
215-
std::cout << "performConvolution 10" << std::endl; // TODO remove
223+
std::cout << "performConvolution 10"
224+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
216225
const Tensor1D yConvOutput{yData_padded.convolve(kernel, dims)};
217-
std::cout << "performConvolution 11" << std::endl; // TODO remove
226+
std::cout << "performConvolution 11"
227+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
218228

219229
const auto eData{TensorMap_const{&m_inputDataWS->e(specNum).front(), binCount}.pad(paddings)};
220230
const Tensor1D eConvOutput{eData.square().convolve(kernel.square(), dims).sqrt()};
221-
std::cout << "performConvolution 12" << std::endl; // TODO remove
231+
std::cout << "performConvolution 12"
232+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
222233
const Tensor1D smoothKernel{
223234
createSmoothKernel(static_cast<size_t>(std::ceil(static_cast<double>(kernelBinCount.first) / 2.0)))};
224-
std::cout << "performConvolution 13" << std::endl; // TODO remove
235+
std::cout << "performConvolution 13"
236+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
225237
Tensor1D iOverSig{(yConvOutput / eConvOutput).unaryExpr([](double val) { return std::isfinite(val) ? val : 0.0; })};
226-
std::cout << "performConvolution 14" << std::endl; // TODO remove
238+
std::cout << "performConvolution 14"
239+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
227240
const Tensor1D iOverSigConvOutput{iOverSig.convolve(smoothKernel, dims)};
228-
std::cout << "performConvolution 15" << std::endl; // TODO remove
241+
std::cout << "performConvolution 15"
242+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
229243

230244
extractPeaks(dataIndex, iOverSigConvOutput, xData, yData, kernelBinCount.first / 2);
231245

232-
std::cout << "performConvolution 16" << std::endl; // TODO remove
246+
std::cout << "performConvolution 16"
247+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
233248
if (m_createIntermediateWorkspaces) {
234249
auto wsNames = createIntermediateWorkspaces(dataIndex, kernel, iOverSigConvOutput, xData);
235-
std::lock_guard<std::mutex> lock(mtx);
250+
std::lock_guard<std::mutex> lock(m_mtx);
236251
m_intermediateWsNames.insert(m_intermediateWsNames.end(), wsNames.cbegin(), wsNames.cend());
237252
}
238-
std::cout << "performConvolution 17" << std::endl; // TODO remove
253+
std::cout << "performConvolution 17"
254+
<< " by thread " << std::this_thread::get_id() << std::endl; // TODO remove
239255
}
240256
}
241257

@@ -332,6 +348,7 @@ void FindPeaksConvolve::storePeakResults(const size_t dataIndex,
332348
if (peakCount > m_maxPeakCount) {
333349
m_maxPeakCount = peakCount;
334350
}
351+
std::lock_guard<std::mutex> lock(m_mtx);
335352
m_peakResults[dataIndex] = std::move(peakCentres);
336353
}
337354
}
@@ -367,6 +384,7 @@ size_t FindPeaksConvolve::findPeakInRawData(const int xIndex, const TensorMap_co
367384

368385
void FindPeaksConvolve::generateNormalPDF(const int peakExtentBinNumber) {
369386
if (m_pdf.size() == 0) {
387+
std::lock_guard<std::mutex> lock(m_mtx);
370388
m_pdf.resize(peakExtentBinNumber);
371389
boost::math::normal_distribution<> dist(0.0,
372390
peakExtentBinNumber / 2.0); // assures 2 stddevs in the resultant vector

0 commit comments

Comments
 (0)