From e55750e1e03bdc167670fb07ac8d9074e539464c Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Sun, 11 Oct 2026 12:38:04 +0200 Subject: [PATCH] rugnux merge ingest: keep d beside zeta only under an energy bandwidth The partiality recompute reads d only to broaden the rocking curve by the energy bandwidth. On a large set the final ingest sits at the process's peak resident memory (8a1a: max RSS rose by the array's 4 bytes x 68 M observations), so the array is kept only where a bandwidth is set; with zeta in and the predicted-partiality copy out, the ingest's peak is then where it was. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EizBKhTqrAYago9KJG3dA3 --- .../scale_merge/RotationScaleMerge.cpp | 20 ++++++++++--------- .../scale_merge/RotationScaleMerge.h | 9 +++++---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/image_analysis/scale_merge/RotationScaleMerge.cpp b/image_analysis/scale_merge/RotationScaleMerge.cpp index 6cf694b13..d8be599f6 100644 --- a/image_analysis/scale_merge/RotationScaleMerge.cpp +++ b/image_analysis/scale_merge/RotationScaleMerge.cpp @@ -877,15 +877,17 @@ void RotationScaleMerge::BuildInRangeObservations(std::unique_ptr &ke // finiteness (immutable) - it lets ComputeAsuGroups stamp the ASU-group id per obs from a flat // 1-byte array instead of re-reading the fat Obs struct for every space group. // - // delta_phi is re-solved against the smoothed geometry right here, and zeta and d - the two fields - // the partiality recompute reads besides it - are kept beside it, so the smoothing that follows - // (SmoothMosaicityAndPartiality) does not sweep the source reflections again. + // delta_phi is re-solved against the smoothed geometry right here, and what the partiality + // recompute reads besides it - zeta, and d where an energy bandwidth broadens the rocking curve - + // is kept beside it, so the smoothing that follows (SmoothMosaicityAndPartiality) does not sweep + // the source reflections again. finite_ok.assign(n_keep, 0); ingest_delta_phi.reset(new float[n_keep]); ingest_partiality.reset(new float[n_keep]); ingest_image_number.reset(new float[n_keep]); ingest_zeta.reset(new float[n_keep]); - ingest_d.reset(new float[n_keep]); + if (x.GetBandwidthFWHM().value_or(0.0f) > 0.0f) + ingest_d.reset(new float[n_keep]); std::atomic n_resolved{0}; #ifdef JFJOCH_USE_CUDA if (resident_ingest) { @@ -905,7 +907,7 @@ void RotationScaleMerge::BuildInRangeObservations(std::unique_ptr &ke ingest_partiality[at] = r.partiality; ingest_image_number[at] = r.image_number; ingest_zeta[at] = r.zeta; - ingest_d[at] = r.d; + if (ingest_d) ingest_d[at] = r.d; const float prescaling_corr = static_cast( r.prescaling_corr * r.qe_corr * r.flight_corr / frame_flux[o]); corr_ingested[at] = r.image_scale_corr; @@ -954,7 +956,7 @@ void RotationScaleMerge::BuildInRangeObservations(std::unique_ptr &ke ingest_partiality[at] = r.partiality; ingest_image_number[at] = r.image_number; ingest_zeta[at] = r.zeta; - ingest_d[at] = r.d; + if (ingest_d) ingest_d[at] = r.d; corr_ingested[at] = r.image_scale_corr; ++at; } @@ -1283,10 +1285,10 @@ void RotationScaleMerge::SmoothMosaicityAndPartiality() { const double half_wavelength_A = x.GetWavelength_A() / 2.0; ParallelFor(n_frames, nthreads, [&](int f) { for (int i = frame_start[f]; i < frame_start[f] + frame_count[f]; ++i) { - const float d = ingest_d[i], zeta = ingest_zeta[i]; + const float zeta = ingest_zeta[i]; float mos = mos_smooth[f]; - if (bandwidth_sigma > 0.0 && d > 0.0f) { - const double sin_theta = half_wavelength_A / d; + if (bandwidth_sigma > 0.0 && ingest_d[i] > 0.0f) { // ingest_d is kept exactly then + const double sin_theta = half_wavelength_A / ingest_d[i]; const double sigma_bw = (180.0 / PI) * bandwidth_sigma * sin_theta / std::sqrt(1.0 - sin_theta * sin_theta); mos = static_cast(std::sqrt(mos * mos + sigma_bw * sigma_bw)); diff --git a/image_analysis/scale_merge/RotationScaleMerge.h b/image_analysis/scale_merge/RotationScaleMerge.h index 43a27a527..5ad12d9fb 100644 --- a/image_analysis/scale_merge/RotationScaleMerge.h +++ b/image_analysis/scale_merge/RotationScaleMerge.h @@ -337,10 +337,11 @@ private: bool resident_ingest = false; // What the ingest-time geometry smoothing (SmoothMosaicityAndPartiality) needs, one array per field // in `partials` order: the two fields it rewrites, the two the rocking-event walks read in raw-hkl - // order, and the two the partiality recompute reads besides them (zeta, d - handed back as soon as - // it is done). So on the resident path no per-observation record is built at all - on a - // fine-sliced long axis that record was gigabytes, held beside the source reflections it was copied - // from - and the smoothing does not sweep the source reflections again either. Filled by + // order, and what the partiality recompute reads besides them (zeta, and d under an energy + // bandwidth - handed back as soon as it is done). So on the resident path no per-observation + // record is built at all - on a fine-sliced long axis that record was gigabytes, held beside the + // source reflections it was copied from - and the smoothing does not sweep the source reflections + // again either. Filled by // BuildInRangeObservations and handed back at the end of Ingest. Plain arrays, not sized vectors, for // the reason the staging buffers are (see Ingest): the build writes every element, and a sized vector // would first zero all of them on one thread.