diff --git a/image_analysis/indexing/IndexerThreadPool.cpp b/image_analysis/indexing/IndexerThreadPool.cpp index d8efeb2e..668ae067 100644 --- a/image_analysis/indexing/IndexerThreadPool.cpp +++ b/image_analysis/indexing/IndexerThreadPool.cpp @@ -3,6 +3,7 @@ #include "IndexerThreadPool.h" #include "../common/CUDAWrapper.h" +#include "../common/Logger.h" #ifdef JFJOCH_USE_CUDA #include "FFBIDXIndexer.h" @@ -84,6 +85,8 @@ void IndexerThreadPool::Worker(int32_t threadIndex, const NUMAHWPolicy &numa_pol #else numa_policy.Bind(threadIndex); #endif + } catch (const std::exception &e) { + spdlog::error("Failed to bind thread to NUMA node: {}", e.what()); } catch (...) { // NUMA policy errors are not critical and should be ignored for the time being. } @@ -101,24 +104,37 @@ void IndexerThreadPool::Worker(int32_t threadIndex, const NUMAHWPolicy &numa_pol || settings.GetAlgorithm() == IndexingAlgorithmEnum::FFBIDX) ffbidx_indexer = std::make_unique(); } + } catch (const std::exception &e) { + spdlog::error("Failed to initialize GPU indexer: {}", e.what()); + failed_start = true; } catch (...) { + spdlog::error("Failed to initialize GPU indexer"); failed_start = true; } #endif #ifdef JFJOCH_USE_FFTW - if ((settings.GetAlgorithm() == IndexingAlgorithmEnum::Auto && (get_gpu_count() == 0)) - || settings.GetAlgorithm() == IndexingAlgorithmEnum::FFTW) - fftw_indexer = std::make_unique(settings); + try { + if ((settings.GetAlgorithm() == IndexingAlgorithmEnum::Auto && (get_gpu_count() == 0)) + || settings.GetAlgorithm() == IndexingAlgorithmEnum::FFTW) + fftw_indexer = std::make_unique(settings); + } catch (const std::exception &e) { + spdlog::error("Failed to initialize FFTW indexer: {}", e.what()); + failed_start = true; + } catch (...) { + spdlog::error("Failed to initialize FFTW indexer"); + failed_start = true; + } #endif workers_ready.count_down(); while (true) { - TaskPackage task; { + TaskPackage task; + { std::unique_lock lock(m); // Add a timeout to the wait to ensure we can exit even if no notification - cond.wait_for(lock, std::chrono::seconds(1), [this] { + cond.wait_for(lock, std::chrono::milliseconds(50), [this] { return stop || !taskQueue.empty(); }); @@ -145,6 +161,9 @@ void IndexerThreadPool::Worker(int32_t threadIndex, const NUMAHWPolicy &numa_pol indexer = ffbidx_indexer.get(); } else if (algorithm == IndexingAlgorithmEnum::FFTW && fftw_indexer) { indexer = fftw_indexer.get(); + } else if (algorithm == IndexingAlgorithmEnum::Auto) { + throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, + "Internal error: Invalid indexing algorithm provided"); } if (indexer) {