From 4ffbee73a313f4850de8d38e26012b4b203488cf Mon Sep 17 00:00:00 2001 From: Kolen Cheung <10970208+ickc@users.noreply.github.com> Date: Wed, 9 Sep 2026 14:44:07 +0000 Subject: [PATCH 1/2] Link the OpenMP targets when BUILD_OPENMP is enabled 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. --- CMakeLists.txt | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b9588d..bfec365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,23 @@ target_compile_definitions(shum PUBLIC ${SHUM_DEFINES}) +# BUILD_OPENMP goes as far as find_package(OpenMP) in ShumOptions.cmake, but +# the imported targets have to be linked for the option to have any effect. +# Without this, no -fopenmp reaches a compile line, _OPENMP is never defined +# and the OpenMP regions are preprocessed away, so a CMake build produces a +# serial library where the Makefile build (SHUM_OPENMP ?= true) produces a +# threaded one. +# +# PRIVATE is sufficient: _OPENMP is used inside c_shum_byteswap.c, never in an +# installed header, so consumers of shumlib do not need OpenMP flags of their +# own. +if(BUILD_OPENMP) + target_link_libraries(shum + PRIVATE + OpenMP::OpenMP_C + OpenMP::OpenMP_Fortran) +endif() + # Install shumlib and the C header files for the sub-libraries that # have them install(TARGETS shum @@ -95,6 +112,16 @@ if(BUILD_TESTS) PUBLIC ${CMAKE_Fortran_MODULE_DIRECTORY}) target_link_libraries(shumlib-tests PUBLIC fruit shum) + # The thread_utils tests exercise the OpenMP paths directly, and shumlib's + # OpenMP linkage is PRIVATE, so the test executable needs the flags in its + # own right. + if(BUILD_OPENMP) + target_link_libraries(shumlib-tests + PRIVATE + OpenMP::OpenMP_C + OpenMP::OpenMP_Fortran) + endif() + add_subdirectory(fruit) setup_shum_fruit() From ba7b2ec42b8abc2481ec434c24f206e50996b194 Mon Sep 17 00:00:00 2001 From: Kolen Cheung <10970208+ickc@users.noreply.github.com> Date: Wed, 16 Sep 2026 16:53:21 +0000 Subject: [PATCH 2/2] add self --- CONTRIBUTORS.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e4f90b3..4d1f42f 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,8 +1,9 @@ # Contributors -| GitHub user | Real Name | Affiliation | Date | -| --------------- | ---------------- | ----------- | ---------- | -| james-bruten-mo | James Bruten | Met Office | 2025-12-09 | -| t00sa | Sam Clarke-Green | Met Office | 2026-02-10 | -| jennyhickson | Jenny Hickson | Met Office | 2026-03-02 | -| yaswant | Yaswant Pradhan | Met Office | 2026-07-17 | +| GitHub user | Real Name | Affiliation | Date | +| --------------- | ---------------- | ----------- | ---------- | +| james-bruten-mo | James Bruten | Met Office | 2025-12-09 | +| t00sa | Sam Clarke-Green | Met Office | 2026-02-10 | +| jennyhickson | Jenny Hickson | Met Office | 2026-03-02 | +| yaswant | Yaswant Pradhan | Met Office | 2026-07-17 | +| ickc | Kolen Cheung | University of Exeter | 2026-09-16 |