Skip to content

Fix for Issue Loading MGXS Data Files with LLVM 20 or Newer #3368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2025

Conversation

jtramm
Copy link
Contributor

@jtramm jtramm commented Apr 8, 2025

Description

Currently, OpenMC crashes with errors like:

libc++abi: terminating due to uncaught exception of type std::bad_array_new_length: bad_array_new_length

when reading in mgxs.h5 multigroup data files when using LLVM clang version 20 or newer. More info is in Issue #3367.

The Cause

The debugger reveals the crash is coming from this xtensor operation in mgxs.cpp:

      auto i_closest = xt::argmin(xt::abs(temps_available - T))[0];

Specifically, the xt::argmin part of the operation. This seems like a valid operation and works fine in gcc and LLVM 19 and older, but appears to break in LLVM 20 and newer. My best guess is that this is related to the relaxed template arguments issue in xtensor. It's possible this issue is fixed in xtensor 0.26.0, but that is unfortunately also the version of xtensor where they refactored the API seemingly for no reason (which I expect might get rolled back?). So, updating the xtensor version is not a good option.

The Fix

Instead of using xt::argmin we just find the closest element manually with a for loop. Not as elegant but gets the job done! Note there are other areas in the code that use xt:argmin but perhaps they don't break as they are being used on different types where the relaxed template issue doesn't get tripped.

Fixes #3367

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)

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Thanks @jtramm!

@paulromano paulromano enabled auto-merge (squash) April 10, 2025 15:27
@paulromano paulromano merged commit cdc254c into openmc-dev:develop Apr 10, 2025
14 checks passed
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.

LLVM 20 Fails at Loading MGXS Data Files
2 participants