Skip to content

Improve nijbo access locality in density calculation - #329

Open
whahnsr wants to merge 1 commit into
openmopac:mainfrom
whahnsr:optimize-density-nijbo-access
Open

whahnsr wants to merge 1 commit into
openmopac:mainfrom
whahnsr:optimize-density-nijbo-access

Conversation

@whahnsr

@whahnsr whahnsr commented Oct 15, 2026

Copy link
Copy Markdown

Summary

Improve memory locality in density_for_MOZYME by accessing the symmetric
nijbo entry with the inner-loop atom index as the first array index.

Because Fortran arrays are column-major, changing

nijbo(j, k)

to the equivalent symmetric entry

nijbo(k, j)

makes the inner-loop access contiguous without changing the calculated value.

Performance

Tested with tests/Crambin_1SCF.mop using a RelWithDebInfo build with:

-O3 -g -fno-omit-frame-pointer -march=native

Baseline user time was approximately 28.9 s.

Optimized user times:

  • 27.84 s
  • 28.00 s
  • 28.37 s

Mean optimized user time: approximately 28.07 s.

This is about a 3% whole-program improvement.

perf also showed the source-line cost at density_for_MOZYME.F90:82
drop from 5.98% to 2.81% of total sampled cycles.

Validation

  • 125/125 tests passed with ctest
  • Crambin_1SCF.out showed no numerical differences from baseline
  • output differences were limited to timestamps and timing values

Generative AI usage

OpenAI Codex was used to assist with performance analysis, profiling
interpretation, and preparation of this change.

Access the symmetric nijbo entry with the inner-loop atom index as the first array index. This preserves the calculated value while improving contiguous memory access in Fortran column-major storage.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Signed-off-by: Werner Hahn <whahnsr@users.noreply.github.com>
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