Skip to content

Optimize radial calculation for orthogonal cells - #1195

Merged
drroe merged 1 commit into
Amber-MD:masterfrom
whahnsr:optimize-radial-ortho
Oct 13, 2026
Merged

drroe merged 1 commit into
Amber-MD:masterfrom
whahnsr:optimize-radial-ortho

Conversation

@whahnsr

@whahnsr whahnsr commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Optimize the single-mask radial distribution calculation for orthogonal
cells.

Profiling showed that essentially all runtime for a representative radial
calculation was concentrated in Action_Radial::calcRDF_singleMask() and
the distance routines it calls.

For orthogonal cells, this change caches the box lengths once per frame and
performs the orthogonal minimum-image distance calculation directly in the
inner pair loop. Other imaging modes continue to use the existing DIST2()
path.

Using std::fabs() for the coordinate differences also allows the compiler
to generate branchless absolute-value operations in this hot loop.

Performance

Test case:

  • test/Test_AutoImage/walp_2.strip.dcd
  • 11,670 atoms
  • 71 frames
  • radial DOPC :DOPC out ... 0.25 15.0
  • Serial GNU build with -O3

CPU user time:

  • Before: 33.28 s
  • After: 20.54 s

This is approximately a 38.3% reduction in CPU time, or a 1.62x speedup.

Validation

  • All 17 comparisons in test/Test_Radial pass.
  • RDF output from the benchmark is byte-for-byte identical to the output
    produced by the original code.
  • The modified Action_Radial.cpp was also compiled successfully with
    -fopenmp to verify the OpenMP code path.
  • git diff --check reports no whitespace errors.

Non-orthogonal and no-image calculations retain the existing DIST2()
path.

@drroe

drroe commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@drroe
drroe merged commit 67df504 into Amber-MD:master Oct 13, 2026
12 of 13 checks passed
@drroe drroe mentioned this pull request Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants