AzimuthalIntegrationMapping: Clean-up threading code
This commit is contained in:
@@ -40,9 +40,9 @@ AzimuthalIntegrationMapping::AzimuthalIntegrationMapping(const DiffractionExperi
|
||||
nthreads = std::clamp<size_t>(nthreads, 1, 64);
|
||||
|
||||
if (!experiment.IsGeometryTransformed())
|
||||
SetupRawGeom(experiment, mask.GetMaskRaw(), nthreads);
|
||||
SetupRawGeom(experiment, mask.GetMaskRaw());
|
||||
else
|
||||
SetupConvGeom(experiment.GetDiffractionGeometry(),mask.GetMask(), nthreads);
|
||||
SetupConvGeom(experiment.GetDiffractionGeometry(),mask.GetMask());
|
||||
|
||||
UpdateMaxBinNumber();
|
||||
}
|
||||
@@ -55,9 +55,7 @@ void AzimuthalIntegrationMapping::SetupConvGeomRows(const DiffractionGeometry &g
|
||||
}
|
||||
}
|
||||
|
||||
void AzimuthalIntegrationMapping::SetupConvGeom(const DiffractionGeometry &geom,
|
||||
const std::vector<uint32_t> &mask,
|
||||
size_t nthreads) {
|
||||
void AzimuthalIntegrationMapping::SetupConvGeom(const DiffractionGeometry &geom, const std::vector<uint32_t> &mask) {
|
||||
pixel_to_bin.resize(width * height, UINT16_MAX);
|
||||
pixel_resolution.resize(width * height, 0);
|
||||
corrections.resize(width * height, 0);
|
||||
@@ -68,13 +66,15 @@ void AzimuthalIntegrationMapping::SetupConvGeom(const DiffractionGeometry &geom,
|
||||
if (nthreads <= 1) {
|
||||
SetupConvGeomRows(geom, mask, 0, height);
|
||||
} else {
|
||||
nthreads = std::min(nthreads, height);
|
||||
auto local_nthreads = std::min(nthreads, height);
|
||||
std::vector<std::future<void>> futures;
|
||||
|
||||
for (size_t t = 0; t < nthreads; ++t)
|
||||
for (size_t t = 0; t < local_nthreads; ++t)
|
||||
futures.emplace_back(std::async(std::launch::async,
|
||||
&AzimuthalIntegrationMapping::SetupConvGeomRows,
|
||||
this, std::cref(geom), std::cref(mask), t * height / nthreads, (t + 1) * height / nthreads));
|
||||
this, std::cref(geom), std::cref(mask),
|
||||
t * height / local_nthreads,
|
||||
(t + 1) * height / local_nthreads));
|
||||
|
||||
for (auto &f: futures)
|
||||
f.get();
|
||||
@@ -82,7 +82,7 @@ void AzimuthalIntegrationMapping::SetupConvGeom(const DiffractionGeometry &geom,
|
||||
}
|
||||
|
||||
void AzimuthalIntegrationMapping::SetupRawGeom(const DiffractionExperiment &experiment,
|
||||
const std::vector<uint32_t> &mask, size_t nthreads) {
|
||||
const std::vector<uint32_t> &mask) {
|
||||
if (mask.size() != RAW_MODULE_SIZE * experiment.GetModulesNum())
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Mask size invalid");
|
||||
|
||||
@@ -100,13 +100,13 @@ void AzimuthalIntegrationMapping::SetupRawGeom(const DiffractionExperiment &expe
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nthreads = std::min<size_t>(nthreads, experiment.GetModulesNum());
|
||||
auto local_nthreads = std::min<size_t>(nthreads, experiment.GetModulesNum());
|
||||
std::vector<std::future<void>> futures;
|
||||
futures.reserve(nthreads);
|
||||
futures.reserve(local_nthreads);
|
||||
|
||||
for (size_t t = 0; t < nthreads; ++t) {
|
||||
const size_t module_begin = t * experiment.GetModulesNum() / nthreads;
|
||||
const size_t module_end = (t + 1) * experiment.GetModulesNum() / nthreads;
|
||||
for (size_t t = 0; t < local_nthreads; ++t) {
|
||||
const size_t module_begin = t * experiment.GetModulesNum() / local_nthreads;
|
||||
const size_t module_end = (t + 1) * experiment.GetModulesNum() / local_nthreads;
|
||||
|
||||
futures.emplace_back(std::async(std::launch::async, [&, module_begin, module_end] {
|
||||
for (size_t m = module_begin; m < module_end; ++m) {
|
||||
|
||||
@@ -29,9 +29,9 @@ protected:
|
||||
|
||||
void UpdateMaxBinNumber();
|
||||
|
||||
void SetupRawGeom(const DiffractionExperiment& experiment, const std::vector<uint32_t> &mask, size_t nthreads);
|
||||
void SetupRawGeom(const DiffractionExperiment& experiment, const std::vector<uint32_t> &mask);
|
||||
void SetupConvGeomRows(const DiffractionGeometry &geom, const std::vector<uint32_t> &mask, size_t row0, size_t row_end);
|
||||
void SetupConvGeom(const DiffractionGeometry &geom, const std::vector<uint32_t> &mask, size_t nthreads);
|
||||
void SetupConvGeom(const DiffractionGeometry &geom, const std::vector<uint32_t> &mask);
|
||||
|
||||
void SetupPixel(const DiffractionGeometry &geom, const std::vector<uint32_t> &mask,
|
||||
uint32_t pxl, uint32_t col, uint32_t row);
|
||||
|
||||
Reference in New Issue
Block a user