Link the OpenMP targets when BUILD_OPENMP is enabled - #39
Open
Kolen Cheung (ickc) wants to merge 2 commits into
Open
Kolen Cheung (ickc) wants to merge 2 commits into
Kolen Cheung (ickc) wants to merge 2 commits into
Conversation
BUILD_OPENMP defaults to ON and ShumOptions.cmake runs find_package(OpenMP 3.0 REQUIRED), but nothing ever links the resulting imported targets. No -fopenmp therefore reaches a compile line, _OPENMP is left undefined, and the OpenMP regions in shum_wgdos_packing, shum_horizontal_field_interp, shum_latlon_eq_grids, shum_thread_utils and shum_byteswap are preprocessed away. A CMake build produces a serial library where the Makefile build, which defaults SHUM_OPENMP to true, produces a threaded one, and the option gives no indication that it had no effect. Link OpenMP::OpenMP_C and OpenMP::OpenMP_Fortran to shum. PRIVATE is sufficient because _OPENMP is used inside c_shum_byteswap.c and never in an installed header, so consumers do not need OpenMP flags of their own. The thread_utils unit tests exercise the OpenMP paths directly, so shumlib-tests is given the same linkage in its own right rather than inheriting it. Verified with GCC that -fopenmp now reaches the C and Fortran compile lines of both targets, that libshum links libgomp, and that the fruit test suite still passes; BUILD_OPENMP=OFF continues to configure and build with no OpenMP flags.
Kolen Cheung (ickc)
marked this pull request as ready for review
September 16, 2026 16:57
Collaborator
|
Thanks for fixing this. I've confirmed that the change works and the OpenMP option are now correctly applied. However, I've discovered that the shumlib regression tests now hangs on my platform - I'm using GCC 12.2.0 and CMake 3.26.5 on RHEL 9.7 - e.g. in |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
Link the OpenMP imported targets so that
BUILD_OPENMPactually enables OpenMP.Code Reviewer: Sam Clarke-Green (@t00sa)
BUILD_OPENMPdefaults toONandcmake/ShumOptions.cmakerunsfind_package(OpenMP 3.0 REQUIRED), but nothing links the resultingOpenMP::OpenMP_C/OpenMP::OpenMP_Fortrantargets.-fopenmptherefore never reaches a compile line,_OPENMPis never defined, and the OpenMP regions inshum_wgdos_packing,shum_horizontal_field_interp,shum_latlon_eq_grids,shum_thread_utilsandshum_byteswapare preprocessed away. The Makefile build defaultsSHUM_OPENMPto true and does apply the flags, so the two build systems currently disagree and the CMake one gives no sign that the option did nothing.This links the targets inside the existing
BUILD_OPENMPguard:shumgets themPRIVATE. That is sufficient because_OPENMPis used insidec_shum_byteswap.cand never in an installed header, so consumers do not need OpenMP flags of their own.shumlib-testsgets the same linkage in its own right, since theshum_thread_utilstests exercise the OpenMP paths directly and would not otherwise be compiled with them.closes CMake build does not link the OpenMP targets, so BUILD_OPENMP has no effect #37
Code Quality Checklist
(Some checks are automatically carried out via the CI pipeline)
Testing
I am an external contributor and have no access to the rose-stem suite, so that box is unticked. What I did verify locally with GCC:
-fopenmpnow reaches the C and Fortran compile lines of both targets:libshum.sonow links the runtime:libgomp.so.1 => /usr/lib64/libgomp.so.1.The fruit suite still passes:
1/1 Test #1: shumlib-tests ... Passed,100% tests passed, 0 tests failed out of 1.-DBUILD_OPENMP=OFFstill configures and builds, with no OpenMP flags on either target.No new tests are added here: this restores the behaviour the existing
shum_thread_utilstests were written against, rather than adding functionality.trac.log
Not applicable — I have no rose-stem access, so there is no trac.log to attach.
Security Considerations
Performance Impact
This is a performance change by nature: the parallel regions in the affected sub-libraries go from being compiled out to being compiled in, so a CMake-built shumlib becomes threaded where it previously was not. That matches what the Makefile build has always produced by default. I have not run comparative benchmarks, and results on Met Office platforms would be more meaningful than mine — worth a look during review if you want numbers.
AI Assistance and Attribution
Documentation
No documentation change:
BUILD_OPENMPis already documented as building with OpenMP parallelisation, which is what it now does.