From d1f4c8629886eaeb5ad53ff4c001898b065d067c Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Wed, 14 Oct 2026 19:42:31 +0200 Subject: [PATCH] tNCS: the modulation null's searches on several workers, output unchanged The 20 shuffled copies are drawn in order from the one generator as before, then each greedy search runs on a worker of its own and reads only its copy, so the nulls are the serial loop's bit for bit. Measured on 4nwv (CPU-only): the analysis was ~3.9 s on the main thread, most of it these searches. Co-Authored-By: Claude Opus 5.5 --- .../scale_merge/TranslationalNCS.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/image_analysis/scale_merge/TranslationalNCS.cpp b/image_analysis/scale_merge/TranslationalNCS.cpp index ed2176762..8c9288435 100644 --- a/image_analysis/scale_merge/TranslationalNCS.cpp +++ b/image_analysis/scale_merge/TranslationalNCS.cpp @@ -582,21 +582,21 @@ TranslationalNCSResult AnalyzeTranslationalNCS(const std::vector permuted = mod_e2; - std::vector nulls; - nulls.reserve(kModulationNullDraws); - for (int draw = 0; draw < kModulationNullDraws; ++draw) { - permuted = mod_e2; + std::vector> permuted(kModulationNullDraws, mod_e2); + for (auto &p : permuted) for (size_t s = 1; s < mod_shell_bounds.size(); ++s) { const size_t lo = mod_shell_bounds[s - 1], hi = mod_shell_bounds[s]; for (size_t i = hi; i > lo + 1; --i) - std::swap(permuted[i - 1], permuted[lo + rng() % (i - lo)]); + std::swap(p[i - 1], p[lo + rng() % (i - lo)]); } - const auto [v, c] = refine(permuted, result.peak_frac); - (void) v; - nulls.push_back(std::isfinite(c) ? c : 1.0); - } + std::vector nulls(kModulationNullDraws); + ParallelFor(kModulationNullDraws, nthreads, [&](int draw) { + const double c = refine(permuted[draw], result.peak_frac).second; + nulls[draw] = std::isfinite(c) ? c : 1.0; + }); std::sort(nulls.begin(), nulls.end()); const size_t m = nulls.size(); result.modulation_null = m % 2 ? nulls[m / 2] : 0.5 * (nulls[m / 2 - 1] + nulls[m / 2]);