Skip to content

Parallelization of Weight Window Update - #3467

Merged
jtramm merged 8 commits into
openmc-dev:developfrom
jtramm:parallel_ww_gen
Jun 25, 2025
Merged

jtramm merged 8 commits into
openmc-dev:developfrom
jtramm:parallel_ww_gen

Conversation

@jtramm

@jtramm jtramm commented Jun 24, 2025

Copy link
Copy Markdown
Contributor

Description

Currently, updates to weight window values are computed serially in OpenMC. This is not a problem on smaller models and/or if using a very coarse mesh, but for larger models at finer mesh resolutions (where you can easily have 100 million or more bins), the weight window update times can become pretty significant in serial.

This PR parallelizes the weight window update function across threads. As the original function made heavy usage of xtensor views and vector operations, this parallelization required a few additional lines so as to convert the vector calls to iterative for loops that could be parallelized with OpenMP.

Note that this PR should not be changing any results -- it is only intended to speed things up via parallelization.

Impact

I did some performance analysis on the JET model with this PR along with the last several optimizations on WW generation with FW-CADIS. Runtimes are given for total runtime (of the adjoint solve) on a single CPU node (for 5 inactive + 5 active batches, with extremely low ray density, and a 10cm resolution weight window mesh). Below is the summary:

Runtime [s] Speedup
Unoptimized 374.7 1.0
Tally Mapping Optimization (PR #3465) 320.9 1.2
All of the above + WW Generation Last Batch Only (PR #3464) 51.6 7.3
All of the above + WW Generation Parallelization (This PR) 25.9 14.5

As can be seen above, the new parallelization scheme gives an additional 2x overall performance boost.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) 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)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR parallelizes the weight window update function in OpenMC to improve performance for large models by replacing xtensor vector operations with iterative OpenMP-parallelized loops.

  • Replaces serial xtensor calls with parallelized for loops for initializing, computing, and normalizing weight window arrays
  • Implements separate parallel loops for both MAGIC and FW-CADIS processing methods
  • Adjusts computation of mean and relative error, as well as normalization across energy groups

Comment thread src/weight_windows.cpp

@pshriwise pshriwise left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization @jtramm! The logic in the for loops is more clear as if-statements than the current xtensor calls too. Thanks!!

@jtramm
jtramm merged commit 15dfe7e into openmc-dev:develop Jun 25, 2025
ahnaf-tahmid-chowdhury pushed a commit to ahnaf-tahmid-chowdhury/OpenMC that referenced this pull request Jul 7, 2025
apingegno pushed a commit to apingegno/openmc that referenced this pull request May 7, 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.

3 participants