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 <noreply@anthropic.com>
This commit is contained in:
Filip LeonarskiandClaude Opus 5.5 committed 2026-10-14 19:42:31 +02:00
1 parent ec02b181db
commit d1f4c86298
1 file changed
+10 -10
+10 -10
View File
@@ -582,21 +582,21 @@ TranslationalNCSResult AnalyzeTranslationalNCS(const std::vector<MergedReflectio
// removes is a control that reads the same signal it is subtracted from, and with it the one
// way an upstream change can move the control while the modulation stands still.
{
// The shuffles are drawn in order from the one generator, then searched on several workers:
// each search reads only its own copy, so the nulls are the serial loop's, bit for bit.
std::mt19937 rng(seed + 7);
std::vector<double> permuted = mod_e2;
std::vector<double> nulls;
nulls.reserve(kModulationNullDraws);
for (int draw = 0; draw < kModulationNullDraws; ++draw) {
permuted = mod_e2;
std::vector<std::vector<double>> 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<double> 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]);