Skip to content

Shared secondary bank performance optimizations#3995

Open
paulromano wants to merge 8 commits into
openmc-dev:developfrom
paulromano:shared-sec-perf-opt
Open

Shared secondary bank performance optimizations#3995
paulromano wants to merge 8 commits into
openmc-dev:developfrom
paulromano:shared-sec-perf-opt

Conversation

@paulromano

Copy link
Copy Markdown
Contributor

Description

When doing profiling on a coupled neutron-photon transport simulation with weight windows enabled (which turns on the new shared secondary bank by default), I was noticing a lot of time spent in areas I wasn't expecting. This PR is the first round of some performance optimizations to address the issues:

  1. First, I was noticing that a lot of time was spent allocating memory for the neutron/photon cross section caches (neutron_xs_ and photon_xs_ in the ParticleData class). At first, I made some attempts to only allocate the cache if it was needed for a given particle. Later on though, I realized the core issue was that in the main loop over the shared secondary "read" bank, we allocate a Particle on the stack. Thus, the cost of the memory allocations can be completely eliminated by simply allocating the Particle once per thread and re-using it in the loop (just requires clearing the local secondary bank at the end of each iteration on the inner loop).
  2. I was also noticing a lot of time being spent in event_death. There are some atomics in there for global tallies that we can avoid in a lot of situations, so I've simply added conditionals to avoid triggering the atomics unless they are really needed.
  3. The logic for RNG seed skip-ahead was being repeated for every RNG stream even though it's the same in each case. I've factored it out into a future_seed_coefficients function so that when we call init_particle_seeds, we only pay the cost once rather than 4 times.

I have another round of optimizations having to do with the shared secondary bank data structures directly that builds on top of these, so once this PR is completed, I'll submit a follow-on one.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@paulromano paulromano requested a review from jtramm July 3, 2026 21:20
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