Skip to content

CMake - OpenMP Check fail with NVHPC #5412

@antoine-morvan

Description

@antoine-morvan

Hello,

I was trying to build OpenBLAS 0.3.30 with NVHPC (25.5 and 25.7). However, cmake fails early with this message :

Multiple OpenMP runtime libraries detected. Mixed OpenMP runtime linkage is dangerous. You may pass -DOpenMP_LANG_LIB_NAMES and -DOpenMP_omp_LIBRARY to manually choose the OpenMP library

This comes from these lines in system.cmake , that were introduced between 0.3.29 and 0.3.30 :

OpenBLAS/cmake/system.cmake

Lines 415 to 427 in d23680b

if (USE_OPENMP)
find_package(OpenMP COMPONENTS C REQUIRED)
set(CCOMMON_OPT "${CCOMMON_OPT} -DUSE_OPENMP")
if (NOT NOFORTRAN)
find_package(OpenMP COMPONENTS Fortran REQUIRED)
# Avoid mixed OpenMP linkage
get_target_property(OMP_C_LIB OpenMP::OpenMP_C INTERFACE_LINK_LIBRARIES)
get_target_property(OMP_Fortran_LIB OpenMP::OpenMP_Fortran INTERFACE_LINK_LIBRARIES)
if (NOT OMP_C_LIB STREQUAL OMP_Fortran_LIB)
message(FATAL_ERROR "Multiple OpenMP runtime libraries detected. Mixed OpenMP runtime linkage is dangerous. You may pass -DOpenMP_LANG_LIB_NAMES and -DOpenMP_omp_LIBRARY to manually choose the OpenMP library.")
endif()
endif ()
endif ()

I dag a bit more and dumped some variables :

        message("OpenMP_C_FOUND       = ${OpenMP_C_FOUND}")
        message("OpenMP_Fortran_FOUND = ${OpenMP_Fortran_FOUND}")
        message("OpenMP_VERSION       = ${OpenMP_VERSION}")
        message("OpenMP_C_LIB_NAMES   = ${OpenMP_C_LIB_NAMES}")
        message("OpenMP_Fortran_LIB_NAMES = ${OpenMP_Fortran_LIB_NAMES}")
        message("OMP_C_LIB            = ${OMP_C_LIB}")
        message("OMP_Fortran_LIB      = ${OMP_Fortran_LIB}")

With GCC, I get

OpenMP_C_FOUND       = TRUE
OpenMP_Fortran_FOUND = TRUE
OpenMP_VERSION       =
OpenMP_C_LIB_NAMES   = gomp;pthread
OpenMP_Fortran_LIB_NAMES = gomp;pthread
OMP_C_LIB            = /home/morvana/compilers/gcc/15.1.0/prefix/lib64/libgomp.so;/lib/x86_64-linux-gnu/libpthread.a
OMP_Fortran_LIB      = /home/morvana/compilers/gcc/15.1.0/prefix/lib64/libgomp.so;/lib/x86_64-linux-gnu/libpthread.a

But for NVHPC, I get this :

OpenMP_C_FOUND       = TRUE
OpenMP_Fortran_FOUND = TRUE
OpenMP_VERSION       =
OpenMP_C_LIB_NAMES   =
OpenMP_Fortran_LIB_NAMES =
OMP_C_LIB            = OMP_C_LIB-NOTFOUND
OMP_Fortran_LIB      = OMP_Fortran_LIB-NOTFOUND

So I have the feeling the FindOpenMP from CMake (https://github.com/Kitware/CMake/blob/master/Modules/FindOpenMP.cmake) is not working properly with NVidia OpenMP. Do you share my opinion, before I open an issue over there ?

I add these flags to the cmake line as workaround at the moment :

            OPENBLAS_CMAKE_EXTRA_FLAGS="-DOpenMP_C_LIB_NAMES=nvomp -DOpenMP_Fortran_LIB_NAMES=nvomp"
            OPENBLAS_CMAKE_EXTRA_FLAGS+=" -DOpenMP_nvomp_LIBRARY=${NVHPC_ROOT}/compilers/lib/libnvomp.a"

Do you have a better one to propose ?

Best.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions