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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit 56815f5390cc01e8da5d420fff73cdf4394c385c)
This commit is contained in:
leonarski_f committed 2026-10-26 09:16:34 +01:00
1 parent 2c1df0ebfa
commit ca0a6dd343
1 file changed
+6 -1
@@ -118,6 +118,9 @@ struct Context {
std::unique_ptr<ModelScaleGPUPool> 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<OwnSlot> 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<BulkSolventMask>(ctx.cell, *ctx.sg, ctx.d_min, nthreads);
@@ -1158,6 +1162,7 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector<M
ctx.cell = cell;
ctx.sg = &sg;
ctx.nthreads = settings.nthreads;
ctx.ml_threads = settings.nthreads;
ctx.cancel = settings.cancel;
ctx.atoms = AtomList(ctx.Model());
result.atoms = static_cast<int>(ctx.atoms.size());