From ca0a6dd343b7aee88075ab7704678c8d2059b564 Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 26 Oct 2026 07:57:30 +0100 Subject: [PATCH] Refinement: each slot's likelihood fit on all of the run's threads Bitwise (the bins are fitted independently: the same bits at any thread count). The weight-trial slots Refit in lockstep while the GPU idles, each with its 1/slots share of -N for the ML bins; the bins now go to the shared worker pool with -N tasks per slot, so the threads of slots that are not fitting help the ones that are. After the Newton searches (previous commit) the ML fit is 0.1-0.5 s summed over a run, so the wall gain is within noise: 5reo 1.63-1.75 -> 1.72, 5f6m 2.60 -> 2.57, 9yl4 7.34 -> 7.28, 7d98 3.78 -> 3.78, 5f6m MD start 4.82 -> 4.76 s. Refined CIF md5 unchanged on 5reo, 5f6m, 9yl4, 7d98, 5f6m MD start (GPU) and 6o2h (CPU). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu (cherry picked from commit 56815f5390cc01e8da5d420fff73cdf4394c385c) --- image_analysis/structure_refinement/Refinement.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/image_analysis/structure_refinement/Refinement.cpp b/image_analysis/structure_refinement/Refinement.cpp index 60846728d..760b19f60 100644 --- a/image_analysis/structure_refinement/Refinement.cpp +++ b/image_analysis/structure_refinement/Refinement.cpp @@ -118,6 +118,9 @@ struct Context { std::unique_ptr scale_gpu; #endif size_t nthreads = 1; + // the likelihood fit's: all of the run's, also in a trial's slot - the slots refit at the same time, the GPU + // idles meanwhile, and the bins they queue on the shared worker pool are fitted by whichever thread is free + size_t ml_threads = 1; int device = -1; // the engine's GPU size_t engine_bytes = 0; // and what it holds there XrayRowModel rows; @@ -260,7 +263,7 @@ struct Context { } { const RefinementStage s4("refit.ml"); - EstimateLikelihoodParameters(refl, fmodel, rows, nthreads); + EstimateLikelihoodParameters(refl, fmodel, rows, ml_threads); } engine->SetRowModel(rows); return ComputeRFactors(refl, fmodel); @@ -967,6 +970,7 @@ std::unique_ptr MakeOwnSlot(const gemmi::Structure &before_topology, co ctx.d_min = main.d_min; ctx.refl = main.refl; ctx.nthreads = nthreads; + ctx.ml_threads = settings.nthreads; ctx.cancel = main.cancel; ctx.b_ceiling = main.b_ceiling; ctx.mask = std::make_unique(ctx.cell, *ctx.sg, ctx.d_min, nthreads); @@ -1158,6 +1162,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector(ctx.atoms.size());