Refinement: time per stage - an NVTX range per call and one TIMING line per stage with its sum and calls

RefinementStage sums the time of each stage over a refinement (Refit and its parts, the evaluations and
their X-ray, restraint, host and upload shares, the repulsion build, the riding hydrogens, the rungs) and
logs it at debug level at the end; rugnux_refine_test -v shows it. No change to any result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015CeEGgpKdfkCTJb3YNMJcu
(cherry picked from commit 9491f54e0beccf36c65ebcec9afff90d08485f86)
(cherry picked from commit 0ce206a88df960754476ce2f75ffaed90fbf3123)
This commit is contained in:
leonarski_f committed 2026-10-26 01:38:22 +01:00
1 parent 07ae590e54
commit 24b1711d64
5 files changed
+123 -13

No files matched your search

@@ -6,6 +6,7 @@
#include <algorithm>
#include <cmath>
#include <map>
#include <mutex>
#include <fftw3.h>
@@ -13,6 +14,7 @@
#include "gemmi/it92.hpp"
#include "gemmi/math.hpp"
#include "../../common/Logger.h"
#include "../../common/ParallelFor.h"
#include "ModelFFT.h"
#include "ModelGrid.h"
@@ -310,6 +312,30 @@ RFactors ComputeRFactors(const RefinementReflections &refl, const std::vector<st
return r;
}
namespace {
std::mutex stage_mutex;
std::map<std::string, std::pair<double, int>> stage_times;
} // namespace
RefinementStage::RefinementStage(const char *name)
: name_(name), start_(std::chrono::steady_clock::now()), nvtx_(NvtxRangeStart(name)) {}
RefinementStage::~RefinementStage() {
NvtxRangeEnd(nvtx_);
const double seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - start_).count();
std::lock_guard lock(stage_mutex);
std::pair<double, int> &t = stage_times[name_];
t.first += seconds;
t.second++;
}
void RefinementStage::Log(Logger &logger) {
std::lock_guard lock(stage_mutex);
for (const auto &[name, t] : stage_times)
logger.Debug("TIMING refine.{} {:.3f} {}", name, t.first, t.second);
stage_times.clear();
}
double RefinementBlur(const gemmi::UnitCell &cell, const gemmi::SpaceGroup &sg, double d_min, double b_floor) {
// set_refmac_compatible_blur(): u_to_b / 1.1 * spacing^2 - b_min, not below 0, the spacing the one asked for
const gemmi::DensityCalculator<Table, float> dc = Calculator(cell, sg, d_min, 0);