Skip to content

Optimize PairDist using cached Dcalc distance calculations - #1204

Open
whahnsr wants to merge 1 commit into
Amber-MD:masterfrom
whahnsr:optimize-pairdist
Open

whahnsr wants to merge 1 commit into
Amber-MD:masterfrom
whahnsr:optimize-pairdist

Conversation

@whahnsr

@whahnsr whahnsr commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Use the existing Cpptraj::Dcalc class in Action_PairDist
to avoid redundant calculations when evaluating atom-pair distances.

The change:

  • Initializes Dcalc once per frame.
  • Calls SetXYZ1() once per outer-loop atom.
  • Uses Dist2() in the inner loop.
  • Covers both single-mask and two-mask calculations.

This builds on the distance-calculation improvements
introduced in #1198.

Validation

  • All four existing PairDist regression comparisons pass.
  • Baseline and optimized versions produce byte-for-byte
    identical benchmark output.
  • Both orthogonal and nonorthogonal imaging were tested.

Performance

Benchmarks were run on an Intel i5-6600, pinned to CPU 2,
using single-threaded execution and five repetitions
with perf stat.

Independent MDAnalysis adenylate kinase trajectory:
47,681 atoms, 4 million atom pairs per frame.

Imaging Frames Elapsed time reduction CPU cycle reduction Instruction reduction
Orthogonal 100 7.4% 8.2% 22.4%
Nonorthogonal 10 23.5% 17.7% 25.8%

The orthogonal benchmark repeats 10 distinct trajectory
frames ten times. Its box angles were changed to 90 degrees
for a controlled orthogonal imaging comparison.

A separate CPPTRAJ truncated-octahedral benchmark showed
a 32.8% reduction in elapsed time.

Maintainer note

Thank you for reviewing and merging our earlier related
optimizations. I particularly appreciate the subsequent
work on distance calculations in #1198, which provided
the basis for this change.

I hope this is a useful extension of that work. If it
overlaps with anything already underway or planned,
please feel entirely free to close the PR. I certainly
don't want to duplicate effort or interfere with your
development plans.

Thanks again for your time and for maintaining CPPTRAJ.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant