Trilinos icon indicating copy to clipboard operation
Trilinos copied to clipboard

STK: Mac compilation error in FPExceptions.cpp on Trilinos 16.1 branch

Open hkthorn opened this issue 7 months ago • 10 comments

Bug Report

@trilinos/stk

Description

As of Trilinos 16.1.0, the parallel build of Trilinos on my Mac is encountering an error in STK. I double checked that this error was not present in 16.0.0:

In file included from /Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.cpp:1:
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:26:16: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
   26 | constexpr bool have_errexcept()
      |                ^
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:29:10: note: non-constexpr function '__math_errhandling' cannot be used in a constant expression
   29 |   return math_errhandling & MATH_ERREXCEPT;
      |          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:111:27: note: expanded from macro 'math_errhandling'
  111 | #define math_errhandling (__math_errhandling())
      |                           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:112:12: note: declared here
  112 | extern int __math_errhandling(void);
      |            ^
In file included from /Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.cpp:1:
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:41:17: error: constexpr if condition is not a constant expression
   41 |   if constexpr (have_errexcept())
      |                 ^~~~~~~~~~~~~~~~
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:29:10: note: non-constexpr function '__math_errhandling' cannot be used in a constant expression
   29 |   return math_errhandling & MATH_ERREXCEPT;
      |          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:111:27: note: expanded from macro 'math_errhandling'
  111 | #define math_errhandling (__math_errhandling())
      |                           ^
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:41:17: note: in call to 'have_errexcept()'
   41 |   if constexpr (have_errexcept())
      |                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:112:12: note: declared here
  112 | extern int __math_errhandling(void);
      |            ^
In file included from /Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.cpp:1:
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:57:17: error: constexpr if condition is not a constant expression
   57 |   if constexpr (have_errexcept())
      |                 ^~~~~~~~~~~~~~~~
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:29:10: note: non-constexpr function '__math_errhandling' cannot be used in a constant expression
   29 |   return math_errhandling & MATH_ERREXCEPT;
      |          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:111:27: note: expanded from macro 'math_errhandling'
  111 | #define math_errhandling (__math_errhandling())
      |                           ^
/Users/hkthorn/Trilinos/Trilinos/packages/stk/stk_util/stk_util/util/FPExceptions.hpp:57:17: note: in call to 'have_errexcept()'
   57 |   if constexpr (have_errexcept())
      |                 ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk/usr/include/math.h:112:12: note: declared here
  112 | extern int __math_errhandling(void);
      |            ^
3 errors generated.

Steps to Reproduce

Use Clang 16.0.0, OpenMPI 5.0.2, and Trilinos 16.1 branch

hkthorn avatar Sep 22 '25 15:09 hkthorn

Tagging @cgcgcg @csiefer2

hkthorn avatar Sep 22 '25 15:09 hkthorn

@hkthorn So the 16.1 release was created roughly in early March, and this stk issue was fixed later in March in develop/master... Perhaps the others know, should I/we add a commit to the 16.1 release branch? Is that allowed? @sebrowne ?

Alternatively, if you're building with spack, you can patch trilinos... If that's desirable, I could provide the patch for you to use.

alanw0 avatar Sep 22 '25 15:09 alanw0

@alanw0 Thanks for letting me know! I think it would be nice if that commit could be cherry picked onto the 16.1 branch, if possible. The spack patch is not an option at this time. @sebrowne ?

hkthorn avatar Sep 22 '25 17:09 hkthorn

@hkthorn Sam indicates that updating the 16.1 branch would essentially constitute a 16.1.1 release. Which is possible, but not common. Also, the 16.2/17.0 release is a month away or less. Please let me know how urgent this is. Sam recommended also tagging Curt @ccober6 for his perspective on a point-release.

alanw0 avatar Sep 24 '25 17:09 alanw0

Also, one other work-around might be to use -DSTK_ENABLE_STKExprEval:bool=OFF which should then avoid the FP-Exceptions error. (Obviously this assumes you don't actually need stk-expreval (string-function parsing).)

alanw0 avatar Sep 24 '25 17:09 alanw0

Also, one other work-around might be to use -DSTK_ENABLE_STKExprEval:bool=OFF which should then avoid the FP-Exceptions error. (Obviously this assumes you don't actually need stk-expreval (string-function parsing).)

On further thought, this might not help after all. The error is occurring in the build of FPExceptions.cpp, which will happen regardless of whether anyone includes the header... sorry about that.

alanw0 avatar Sep 24 '25 17:09 alanw0

So @sebrowne and I talked about this. If @hkthorn you need a release before the 17.0 release, I would lean towards creating a 16.2 release for you. This would make the Epetra removal a 16.3/17.0 release transition.

ccober6 avatar Sep 25 '25 14:09 ccober6

@ccober6 STK is not a requirement for Xyce, this was an issue I encountered while trying to help out SCEPTRE in #14389

hkthorn avatar Sep 25 '25 15:09 hkthorn

@alanw0 Do you know when this issue was introduced after the 16.0 release? Which STK snapshot?

hkthorn avatar Sep 25 '25 16:09 hkthorn

@alanw0 Do you know when this issue was introduced after the 16.0 release? Which STK snapshot?

@hkthorn It's hard to be sure but looking at sierra git history it looks like this issue was introduced in Nov 2024. In the file packages/stk/CHANGELOG.md it would be the snapshot labeled 5.23.2 (STK_VERSION 5230200) 12/11/2024, although unfortunately the text blurb for that snapshot doesn't mention the fp-exception stuff...

But you can see (on the master branch) that the fix for this MAC issue was included in the snapshot labeled 5.23.8-01 (STK_VERSION 5230801) 3/27/2025.

Sorry our macos support is not great! I hate it when issues show up only on that platform.

alanw0 avatar Sep 25 '25 16:09 alanw0