Skip to content

Comments

fix[cartesian]: MacOS & OpenMP: skip the multithreading#2491

Draft
FlorianDeconinck wants to merge 3 commits intoGridTools:mainfrom
FlorianDeconinck:fix/macos_apple_clang_openmp_deactivate
Draft

fix[cartesian]: MacOS & OpenMP: skip the multithreading#2491
FlorianDeconinck wants to merge 3 commits intoGridTools:mainfrom
FlorianDeconinck:fix/macos_apple_clang_openmp_deactivate

Conversation

@FlorianDeconinck
Copy link
Contributor

Description

This PR deactivate OpenMP when detecting MacOS (Darwin) as the OS.

The reason are simple apple-clang don't ship with openmp by default and the way to acquire it is requires brew or other workaround we won't expect out of our users.

In detail the PR:

  • strips includes and omp_get_max_threads from codegen on the glue code of stencil DaCe backends when all the computes are sequential (non MacOS related),
  • put an option in the StencilBuilder to centralize deactivation of OpenMP and turn it off when detecting Darwin (+ warning),
  • makes all maps sequential as part of the OIR -> TreeIR process based on the above option,
  • strips openmp flags from the command line based on the above option.

Requirements

  • All fixes and/or new features come with corresponding tests.

@havogt
Copy link
Contributor

havogt commented Feb 23, 2026

Adding @tehrengruber as reviewer to check with PMAP people if they are running with openmp on mac for development.

Copy link
Contributor

@romanc romanc left a comment

Choose a reason for hiding this comment

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

I'd also suggest to add minimal tests (e.g. we run daily CI on MacOS hardware) to catch obvious errors like deactivating OpenMP on the wrong platform.

Also, we might wanna allow OpenMP on MacOS systems if used in combination with GCC (like we do - without issues - on the daily CI).

# would require brew, we cancel it altogether. A slightly narrower configuration
# would run a test on the compiler for OpenMP directives support
self.options.uses_openmp = True
if platform.system() != "Darwin":
Copy link
Contributor

Choose a reason for hiding this comment

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

This condition is "the wrong way around" and deactivates OpenMP support except on MacOS devices.

# Dev NOTE: MacOS is not issue, apple-clang is. But because a proper OpenMP
# would require brew, we cancel it altogether. A slightly narrower configuration
# would run a test on the compiler for OpenMP directives support
self.options.uses_openmp = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to set the default? Isn't this covered by changes in src/gt4py/cartesian/definitions.py?

Comment on lines +79 to +84
warnings.warn(
"Multithreading is deactivated under MacOS due to apple-clang "
"not handling OpenMP by default.",
category=UserWarning,
stacklevel=2,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning here is very verbose because it will warn for every stencil built, e.g. in the current test log we see a bunch of these warning messages (because the condition is wrong - see above).

I suggest to test this once (I'd probably put in in src/gt4py/cartesian/config.py) and only warn once there. It also seems to be more consistent with build_settings setup there rather than make this a (per-stencil configurable) BuildOption because this won't change per-stencil.

@FlorianDeconinck
Copy link
Contributor Author

My bad - this was supposed to be a draft. Thanks for the review, I'll be back on it today

@FlorianDeconinck FlorianDeconinck marked this pull request as draft February 23, 2026 14:14
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.

3 participants