From 5a830d7af6a20dfb9af6dff4fccd882257624c39 Mon Sep 17 00:00:00 2001 From: leonarski_f Date: Thu, 16 Apr 2026 19:40:27 +0200 Subject: [PATCH] IndexerThreadPool: IndexerThreadPool return value, not promise + if no spots or no indexing algorithm, don't queue --- image_analysis/IndexAndRefine.cpp | 2 +- image_analysis/RotationIndexer.cpp | 2 +- image_analysis/indexing/IndexerThreadPool.cpp | 14 ++++++++++---- image_analysis/indexing/IndexerThreadPool.h | 4 +++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/image_analysis/IndexAndRefine.cpp b/image_analysis/IndexAndRefine.cpp index fd19adbb..45f0e47c 100644 --- a/image_analysis/IndexAndRefine.cpp +++ b/image_analysis/IndexAndRefine.cpp @@ -56,7 +56,7 @@ IndexAndRefine::IndexingOutcome IndexAndRefine::DetermineLatticeAndSymmetry(Data recip.push_back(i.ReciprocalCoord(geom_)); } - auto indexer_result = indexer_->Run(experiment, recip).get(); + auto indexer_result = indexer_->Run(experiment, recip); msg.indexing_time_s = indexer_result.indexing_time_s; if (indexer_result.lattice.empty()) diff --git a/image_analysis/RotationIndexer.cpp b/image_analysis/RotationIndexer.cpp index df4d09f1..cd7a04ea 100644 --- a/image_analysis/RotationIndexer.cpp +++ b/image_analysis/RotationIndexer.cpp @@ -72,7 +72,7 @@ void RotationIndexer::TryIndex() { coords_sel = coords_; } - auto indexer_result = indexer_.Run(experiment, coords_sel).get(); + auto indexer_result = indexer_.Run(experiment, coords_sel); if (!indexer_result.lattice.empty()) { // Find lattice type search_result_ = LatticeSearch(indexer_result.lattice[0]); diff --git a/image_analysis/indexing/IndexerThreadPool.cpp b/image_analysis/indexing/IndexerThreadPool.cpp index ee6ff3ff..d8efeb2e 100644 --- a/image_analysis/indexing/IndexerThreadPool.cpp +++ b/image_analysis/indexing/IndexerThreadPool.cpp @@ -14,7 +14,9 @@ #endif IndexerThreadPool::IndexerThreadPool(const IndexingSettings &settings, const NUMAHWPolicy &numa_policy) - : stop(false), workers_ready(settings.GetIndexingThreads()) { + : workers_ready(settings.GetIndexingThreads()), + viable_cell_min_spots(settings.GetViableCellMinSpots()), + stop(false) { for (size_t i = 0; i < settings.GetIndexingThreads(); ++i) workers.emplace_back([this, i, numa_policy, settings] { Worker(i, numa_policy, settings); }); workers_ready.wait(); @@ -47,8 +49,12 @@ IndexerThreadPool::~IndexerThreadPool() { { } } -std::future IndexerThreadPool::Run(const DiffractionExperiment &experiment, - const std::vector& recip) { +IndexerResult IndexerThreadPool::Run(const DiffractionExperiment &experiment, const std::vector &recip) { + if (experiment.GetIndexingAlgorithm() == IndexingAlgorithmEnum::None) + return IndexerResult{.lattice = {}, .indexing_time_s = 0}; + if (recip.size() < viable_cell_min_spots) + return IndexerResult{.lattice = {}, .indexing_time_s = 0}; + // Create a promise/future pair auto promise = std::make_shared >(); std::future result = promise->get_future(); { @@ -64,7 +70,7 @@ std::future IndexerThreadPool::Run(const DiffractionExperiment &e } cond.notify_one(); - return result; + return result.get(); } void IndexerThreadPool::Worker(int32_t threadIndex, const NUMAHWPolicy &numa_policy, const IndexingSettings &settings) { diff --git a/image_analysis/indexing/IndexerThreadPool.h b/image_analysis/indexing/IndexerThreadPool.h index c2055aac..f4c42d75 100644 --- a/image_analysis/indexing/IndexerThreadPool.h +++ b/image_analysis/indexing/IndexerThreadPool.h @@ -38,13 +38,15 @@ class IndexerThreadPool { std::queue taskQueue; std::latch workers_ready; + const int64_t viable_cell_min_spots; + bool stop; void Worker(int32_t threadIndex, const NUMAHWPolicy &numa_policy, const IndexingSettings& settings); public: IndexerThreadPool(const IndexingSettings& settings, const NUMAHWPolicy &numa_policy = NUMAHWPolicy()); ~IndexerThreadPool(); - std::future Run(const DiffractionExperiment& experiment, const std::vector& recip); + IndexerResult Run(const DiffractionExperiment& experiment, const std::vector& recip); };