From 783b10ad36c48046ea9f8d5c655ffdfb2617aecc Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Mon, 16 Nov 2026 05:36:50 +0100 Subject: [PATCH] Refinement on the CPU without a population: the untwinned and the twinned arm side by side The twinned arm waited for the untwinned one on the CPU ("a second arm only shares its threads"), so a crystal with a twin law refined twice in a row, and each arm's phases with few trials left threads idle. Where nothing in an arm depends on its threads - no population, whose members are as many as the trial slots (the CPU protocol of RefinementSettings::lean_on_cpu) - the arms now run side by side on half of the threads each. The same refined models bit for bit (cytC, 7ris, myob and the live cytC placement); --mode refine --no-gpu -N 16: cytC 150 -> 137 s, the live cytC set 182 -> 146 s, 7ris 154 -> 141 s, myob 72 -> 65 s (the last three also with the commit before). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK --- .../structure_refinement/Refinement.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/image_analysis/structure_refinement/Refinement.cpp b/image_analysis/structure_refinement/Refinement.cpp index 2ade4b84b..924ed0803 100644 --- a/image_analysis/structure_refinement/Refinement.cpp +++ b/image_analysis/structure_refinement/Refinement.cpp @@ -4230,10 +4230,18 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector 1; + RefinementSettings untwinned_settings = settings, twin_settings = settings; + if (halves) { + twin_settings.nthreads = settings.nthreads / 2; + untwinned_settings.nthreads = settings.nthreads - twin_settings.nthreads; + } Logger twin_logger = Logger::Buffered(); CardHeld held; std::future held_bytes = held.bytes.get_future(); @@ -4251,19 +4259,20 @@ RefinementResult RefineModel(const gemmi::Structure &placed, const std::vector budget) + if (!halves && (held_on_card == 0 || 2 * held_on_card > budget)) untwinned.wait(); // A failure here (the card's memory, shared with the untwinned arm) leaves the untwinned result standing. try { - DecideTwin(placed, data, cell, sg, wavelength_A, twin_logger, settings, result, untwinned); + DecideTwin(placed, data, cell, sg, wavelength_A, twin_logger, twin_settings, result, untwinned); } catch (const std::exception &e) { twin_logger.Warning("Refinement: twin hypothesis not tested - {}", e.what()); } }); try { - result = RefineOnce(placed, data, cell, sg, wavelength_A, logger, settings, {}, 0, &held); + result = RefineOnce(placed, data, cell, sg, wavelength_A, logger, untwinned_settings, {}, 0, &held); } catch (...) { result = RefinementResult(); // not ok: the twinned arm decides nothing held.Say(0);