- Notifications
You must be signed in to change notification settings - Fork 1.6k
CMake: Pass OpenMP compiler and linker flags through CMake targets#5180
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
a6e2183 to b0746c7Comparebf2f49f to 18ccac9Compareywwry66 commented Mar 13, 2025
Ok, this is ready. If appropriate, I can also remove all OpenMP related code in |
dimpase commented Mar 17, 2025
see #5169 for the needed setup |
dimpase commented Mar 18, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
A successful test on Linux x86_64, where libomp is installed system-wide in /usr/. I ran the following: and the linkage is correct: |
dimpase commented Mar 19, 2025
Also works on M1 up to date system, with openblas.pc looks correct too. |
Using `OpenMP::OpenMP_LANG` targets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by setting `OpenMP_LANG_FLAGS`, `OpenMP_LANG_LIB_NAMES`, and `OpenMP_omp_LIBRARY`.
Uh oh!
There was an error while loading. Please reload this page.
ywwry66 commented Apr 2, 2025
Hi @martin-frbg, could you initiate those pending checks for the GitHub workflow? Thanks for the help. |
ywwry66 commented Apr 8, 2025
The loongarch64 test does not use cmake, so the frozen test was not related to this PR. |
martin-frbg commented Apr 8, 2025
yes, that was probably some network error in the cloud |
70865a8 into OpenMathLib:developUh oh!
There was an error while loading. Please reload this page.
dimpase commented Apr 9, 2025
Thank you! |
| if (USE_OPENMP AND (NOT NOFORTRAN)) | ||
| # Disable OpenMP for LAPACK Fortran codes on Windows. | ||
| if(NOT${CMAKE_SYSTEM_NAME}STREQUAL"Windows") | ||
| target_link_libraries(LAPACK_OVERRIDES OpenMP::OpenMP_Fortran) | ||
| endif() | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason Why?
You know there is GNU Fortran and Flang (MinGW) for Windows that could build lapack+OpenMP on Windows.
@ywwry66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is simply because the code was there before, added in 0beea3a, and I didn't investigate the feasibility of enabling OpenMP for OpenBLAS on Windows while working on this PR. But you are probably right, as your PR has passed the CI tests. @MehdiChinoune
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flang/OpenMP on Windows is still a bit dubious (it compiles but led to errors last time I checked, and I need to check again with a current version). but the restriction you complain about is only in the CMake configuration, and indeed mostly historical from when CMake usually implied someone using Visual Studio.
derekchiang commented Jul 15, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Has this fix been released to the See this issue: ocaml/opam-repository#27483 |
dimpase commented Jul 15, 2025
No, homebrew folks closed the corresponding issue as won't fix. With the rationale that it works with the "real" gcc, i.e. GNU gcc, not the clang renamed by Apple to gcc. |
ywwry66 commented Jul 16, 2025
martin-frbg commented Jul 31, 2025
Ahem, do I get this right that the entire motivation for this PR is that the homebrew package is set up to be built with OpenMP enabled, while the native AppleClang does not support OpenMP at all ? |
dimpase commented Jul 31, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
No, the native Apple clang does support OpenMP, but it requires a non-standard option to do so. And, as all clangs, it cannot use GNU OpenMP, aka libgomp, it needs llvm's OpenMP, aka libomp. So you can build and use OpenMP-enabled openblas with gfortran+clang, but with llvm's OpenMP; in addition, Apple's clang does not grok |
martin-frbg commented Jul 31, 2025
According to https://mac.r-project.org/openmp/ that would be |
dimpase commented Jul 31, 2025
I don't know what you mean by "another compiler". gcc (the real thing, not a renamed Apple clang) cannot handle macOS headers, as they use blocks. Do you mean to use several C compilers to build a project ? Building a project with several C compilers isn't standard, and would require custom scripts... |
dimpase commented Jul 31, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Well, such a library is available in Homebrew. But the current OpenBLAS won't easily allow to create a homebrew formula to use it instead of incompatible with clang libgomp. (R Project overcomplicates things here IMHO)
I don't follow here. Do you mean to say that there is a way to use libgomp with clang? |
ywwry66 commented Aug 1, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
While one of the applications of the PR is to allow building OpenBLAS on macOS with GCC+Apple Clang with OpenMP support, the main motivation is to let CMake handle OpenMP related Fortran flags automatically, and at the same time offers better customizability. In this regard, the changes are very generic and an overall improvement to the old cmake code that handles flags manually, and I don't see how they are invasive. Admittedly, the test I added that caused the NVHPC issue was a little sloppy. My suggestion here is to either demote the error to warning or remove it altogether instead of reverting the entire PR. |
ywwry66 commented Aug 2, 2025
dimpase commented Aug 2, 2025
Not allowing a seamless treatment of OpenBLAS on macOS would basically push users to Apple's Accelerate framework, which, after years of lagging behind OpenBLAS in following BLAS/LAPACK standards, has caught up. E.g., numpy/scipy, one of the most popular BLAS/LAPACK-using Python libraries, switched to using Accelerate in their binary wheels. |
Using
OpenMP::OpenMP_LANGtargets for CMake is less error-prone than passing the compiler and linker flags manually. Furthermore, it allows the user to customize those flags by settingOpenMP_LANG_FLAGS,OpenMP_LANG_LIB_NAMES, andOpenMP_omp_LIBRARY.