IndexerThreadPool: IndexerThreadPool return value, not promise + if no spots or no indexing algorithm, don't queue
This commit is contained in:
@@ -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())
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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<IndexerResult> IndexerThreadPool::Run(const DiffractionExperiment &experiment,
|
||||
const std::vector<Coord>& recip) {
|
||||
IndexerResult IndexerThreadPool::Run(const DiffractionExperiment &experiment, const std::vector<Coord> &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::promise<IndexerResult > >();
|
||||
std::future<IndexerResult> result = promise->get_future(); {
|
||||
@@ -64,7 +70,7 @@ std::future<IndexerResult> 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) {
|
||||
|
||||
@@ -38,13 +38,15 @@ class IndexerThreadPool {
|
||||
std::queue<TaskPackage> 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<IndexerResult> Run(const DiffractionExperiment& experiment, const std::vector<Coord>& recip);
|
||||
IndexerResult Run(const DiffractionExperiment& experiment, const std::vector<Coord>& recip);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user