From 0265878bff7ca0734b208333759aab98073217ed Mon Sep 17 00:00:00 2001 From: Patrick Kopper Date: Tue, 24 May 2022 17:40:17 +0200 Subject: [PATCH 1/8] Make CMake compatible with ninja build system --- CMakeLists.txt | 5 ++- CMakeListsMachine.txt | 72 ++++++++++++++++++++++++++++++++----------- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8da252c..b93b619 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,10 @@ ENDIF() # Location of binary and filenames # ========================================================================= # append relative filename-macro for __FILENAME__ in Stamp of abort function (see flexi.h) -SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") +# subst replacement is GNU make specific +IF("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles") + SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'") +ENDIF() # add basedir for location of corresponding userblock-file ADD_DEFINITIONS("-DBASEDIR='\"${CMAKE_CURRENT_BINARY_DIR}/\"'") diff --git a/CMakeListsMachine.txt b/CMakeListsMachine.txt index 627d527..6d27da4 100644 --- a/CMakeListsMachine.txt +++ b/CMakeListsMachine.txt @@ -1,12 +1,25 @@ # ========================================================================= -# Detect machine environements +# Detect machine environments # ========================================================================= - +CMAKE_HOST_SYSTEM_INFORMATION(RESULT CMAKE_FQDN_HOST QUERY FQDN) +MARK_AS_ADVANCED(FORCE CMAKE_FQDN_HOST) MARK_AS_ADVANCED(FORCE CMAKE_HOSTNAME) SITE_NAME(CMAKE_HOSTNAME) # ========================================================================= -# Some clusters require setting the compilers by hand and invoking +# CMake generator settings +# ========================================================================= +IF("${CMAKE_GENERATOR}" MATCHES "Ninja") + # CMake introduced the CMAKE_COLOR_DIAGNOSTICS flag with 3.24.0, https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6990 + IF(NOT(${CMAKE_VERSION} VERSION_LESS "3.24.0")) + SET(CMAKE_COLOR_DIAGNOSTICS ON CACHE INTERNAL "Flag if CMake should attempt to color output") + ELSE() + SET(NINJA_COLOR_DIAGNOSTICS "-fdiagnostics-color=always" CACHE INTERNAL "Flag if Ninja should attempt to color output") + ENDIF() +ENDIF() + +# ========================================================================= +# Some clusters requires setting the compilers by hand and invoking # ENABLE_LANGUAGE afterwards, which is required for # CMAKE_Fortran_COMPILER_ID that is used below # > This block must be called before ENABLE_LANGUAGE @@ -50,8 +63,9 @@ IF ("${CMAKE_HOSTNAME}" MATCHES "login") MARK_AS_ADVANCED(FORCE C_PATH CXX_PATH Fortran_PATH) # HAWK and SuperMUC name their login nodes identically, so use OS distribution to identify - find_program(LSB_RELEASE_EXEC lsb_release) - execute_process(COMMAND ${LSB_RELEASE_EXEC} -is OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + FIND_PROGRAM(LSB_RELEASE_EXEC lsb_release) + EXECUTE_PROCESS(COMMAND ${LSB_RELEASE_EXEC} -is OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE) + MARK_AS_ADVANCED(FORCE LSB_RELEASE_EXEC) # HLRS HAWK IF (LSB_RELEASE_ID_SHORT MATCHES "CentOS") MESSAGE(STATUS "Compiling on Hawk") @@ -80,11 +94,13 @@ IF ("${CMAKE_HOSTNAME}" MATCHES "login") ELSEIF("${CMAKE_HOSTNAME}" MATCHES "^prandtl") MESSAGE(STATUS "Compiling on Prandtl") MARK_AS_ADVANCED(FORCE C_PATH CXX_PATH Fortran_PATH) + SET(HOPR_INSTRUCTION "-march=native") # IAG Grafik01/Grafik02 ELSEIF ("${CMAKE_HOSTNAME}" MATCHES "^grafik0") MESSAGE(STATUS "Compiling on ${CMAKE_HOSTNAME}") MARK_AS_ADVANCED(FORCE C_PATH CXX_PATH Fortran_PATH) + SET(HOPR_INSTRUCTION "-march=native") ELSEIF ("${CMAKE_HOSTNAME}" MATCHES "^ilahead1") MESSAGE(STATUS "Compiling on ILA cluster") @@ -99,6 +115,12 @@ ELSEIF ("${CMAKE_HOSTNAME}" MATCHES "^ilahead1") ELSEIF ("${CMAKE_HOSTNAME}" MATCHES "^xenon") MESSAGE(STATUS "Compiling on ILA student cluster") MARK_AS_ADVANCED(FORCE C_PATH CXX_PATH Fortran_PATH) + SET(HOPR_INSTRUCTION "-march=native") + +ELSEIF ("${CMAKE_FQDN_HOST}" MATCHES "gitlab.ila.uni-stuttgart.de") + MESSAGE(STATUS "Compiling on ILA Gitlab") + ADD_DEFINITIONS(-DVDM_ANALYTICAL) + SET(HOPR_INSTRUCTION "-march=native") ELSE() MESSAGE(STATUS "Compiling on a generic machine") @@ -110,7 +132,7 @@ ELSE() ENDIF() ENDIF() -MESSAGE(STATUS "Compiling using [${HOPR_INSTRUCTION}] instruction") +MESSAGE(STATUS "Compiling with [${CMAKE_Fortran_COMPILER_ID}] (v${CMAKE_Fortran_COMPILER_VERSION}) fortran compiler using [${HOPR_INSTRUCTION}] instruction") # ========================================================================= # COMPILER FLAGS @@ -124,7 +146,6 @@ IF (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") # set Flags (disable lto type warnings due to false positives with MATMUL, which is a known bug) IF (NOT DEFINED C_FLAGS_INITIALIZED ) SET (C_FLAGS_INITIALIZED "yes" CACHE INTERNAL "Flag if compiler flags are already initialized" ) - # initialize all variables as signalling NaNs to force the user to correctly initialize these data types SET (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fdefault-real-8 -fdefault-double-8 -fbackslash -ffree-line-length-0 -finit-real=snan -finit-integer=snan -Wno-lto-type-mismatch -DGNU") ENDIF() SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS} -O3 ${HOPR_INSTRUCTION} -finline-functions -fstack-arrays") @@ -132,7 +153,13 @@ IF (CMAKE_Fortran_COMPILER_ID MATCHES "GNU") SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS} -g -Og -ggdb3 -ffpe-trap=invalid -fbounds-check -finit-real=snan -fbacktrace -Wall") SET (CMAKE_Fortran_FLAGS_SANITIZE "${CMAKE_Fortran_FLAGS} -g -Og -ggdb3 -ffpe-trap=invalid,zero,overflow -fbounds-check -finit-real=snan -fbacktrace -Wall -fsanitize=address,undefined,leak -fno-omit-frame-pointer -Wc-binding-type -Wuninitialized -pedantic") # add flags only for compiling not linking! - SET (HOPR_COMPILE_FLAGS "-xf95-cpp-input -fPIC") + # Compile flags depend on the generator + IF(NOT "${CMAKE_GENERATOR}" MATCHES "Ninja") + # add flags only for compiling not linking! + SET (HOPR_COMPILE_FLAGS "-xf95-cpp-input -fPIC") + ELSE() + SET (HOPR_COMPILE_FLAGS "${NINJA_COLOR_DIAGNOSTICS} -fPIC") + ENDIF() # AMD Optimized LLVM/CLANG ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Flang") @@ -144,8 +171,13 @@ ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Flang") SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS} -O3 ${HOPR_INSTRUCTION} -finline-functions ") SET (CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS} -pg -O3 ${HOPR_INSTRUCTION} -finline-functions ") SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS} -g -O0 -ggdb3 -ffpe-trap=invalid -fbounds-check -finit-real=snan -fbacktrace -Wall") - # add flags only for compiling not linking! - SET (HOPR_COMPILE_FLAGS "-xf95-cpp-input -fPIC") + # Compile flags depend on the generator + IF(NOT "${CMAKE_GENERATOR}" MATCHES "Ninja") + # add flags only for compiling not linking! + SET (HOPR_COMPILE_FLAGS "-xf95-cpp-input -fPIC") + ELSE() + SET (HOPR_COMPILE_FLAGS "${NINJA_COLOR_DIAGNOSTICS} -fPIC") + ENDIF() # Intel Compiler ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Intel") @@ -157,8 +189,13 @@ ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Intel") SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS} -O2 ${HOPR_INSTRUCTION} -qopt-report0 -qopt-report-phase=vec") SET (CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS} -p -O2 ${HOPR_INSTRUCTION} -qopt-report0 -qopt-report-phase=vec") SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS} -g -O0 -fpe0 -traceback -check all,noarg_temp_created,noformat,nooutput_conversion,pointer,uninit -init=snan -init=arrays") - # add flags only for compiling not linking! - SET (HOPR_COMPILE_FLAGS "-fpp -allow nofpp_comments -assume bscc") + # Compile flags depend on the generator + IF(NOT "${CMAKE_GENERATOR}" MATCHES "Ninja") + # add flags only for compiling not linking! + SET (HOPR_COMPILE_FLAGS "-fpp -allow nofpp_comments -assume bscc") + ELSE() + SET (HOPR_COMPILE_FLAGS "${NINJA_COLOR_DIAGNOSTICS} -allow nofpp_comments -assume bscc") + ENDIF() # Cray Compiler ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Cray") @@ -171,8 +208,7 @@ ELSEIF (CMAKE_Fortran_COMPILER_ID MATCHES "Cray") SET (CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS} -O2 -hfp3 -h profile_generate -p . -rm") SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS} -O0 -eD -rm") # add flags only for compiling not linking! - SET (HOPR_COMPILE_FLAGS "-F") - + SET (HOPR_COMPILE_FLAGS "${NINJA_COLOR_DIAGNOSTICS} -F") ELSE() MESSAGE(SEND_ERROR "Unknown compiler") ENDIF() @@ -191,10 +227,10 @@ IF (USE_PGO) ENDIF() # Save the current compiler flags to the cache every time cmake configures the project. -MARK_AS_ADVANCED(CMAKE_Fortran_FLAGS) -MARK_AS_ADVANCED(CMAKE_Fortran_FLAGS_RELEASE) -MARK_AS_ADVANCED(CMAKE_Fortran_FLAGS_PROFILE) -MARK_AS_ADVANCED(CMAKE_Fortran_FLAGS_DEBUG) +MARK_AS_ADVANCED(FORCE CMAKE_Fortran_FLAGS) +MARK_AS_ADVANCED(FORCE CMAKE_Fortran_FLAGS_RELEASE) +MARK_AS_ADVANCED(FORCE CMAKE_Fortran_FLAGS_PROFILE) +MARK_AS_ADVANCED(FORCE CMAKE_Fortran_FLAGS_DEBUG) SET(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}" CACHE STRING "Default compiler flags" FORCE) SET(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE}" CACHE STRING "Release compiler flags" FORCE) SET(CMAKE_Fortran_FLAGS_PROFILE "${CMAKE_Fortran_FLAGS_PROFILE}" CACHE STRING "Profile compiler flags" FORCE) From b469ce55dd882131b47235a8436046e5e05ea3c0 Mon Sep 17 00:00:00 2001 From: Patrick Kopper Date: Mon, 13 Jun 2022 08:42:24 +0200 Subject: [PATCH 2/8] Make external libraries builds compatible with Ninja --- CMakeListsLib.txt | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/CMakeListsLib.txt b/CMakeListsLib.txt index 43d16cc..4b4d9df 100644 --- a/CMakeListsLib.txt +++ b/CMakeListsLib.txt @@ -61,6 +61,7 @@ IF(LIBS_USE_MPI) ENDFOREACH() LIST(APPEND linkedlibs ${MPI_Fortran_LIBRARIES}) ENDIF() + MARK_AS_ADVANCED(FORCE MPI_LIBRARY MPI_EXTRA_LIBRARY) MESSAGE(STATUS "Building HOPR with MPI") MESSAGE(STATUS "MPI Compiler: " ${MPI_Fortran_COMPILER}) @@ -92,6 +93,12 @@ SET(HDF5_ROOT "$ENV{HDF5_ROOT}" CACHE STRING "Expose HDF5_ROOT environment varia # Use system HDF5 IF(NOT LIBS_BUILD_HDF5) + # Unset leftover paths from old CMake runs + UNSET(HDF5_LIBRARIES) + UNSET(HDF5_INCLUDE_DIR_FORTRAN) + UNSET(HDF5_INCLUDE_DIR) + UNSET(HDF5_DIFF_EXECUTABLE) + # Try to find the CMake version SET(LIBS_HDF5_CMAKE TRUE) FIND_PACKAGE(HDF5 NAMES hdf5 COMPONENTS C Fortran ${SEARCH_TYPE} QUIET PATH_SUFFIXES share/cmake) @@ -137,20 +144,16 @@ ELSE() #SET HDF5_TAG depending on MPI Version IF(LIBS_USE_MPI) # HDF5 1.12.0 and greater is compatible with OpenMPI 4.0.0 and greater - EXECUTE_PROCESS(COMMAND mpiexec --version COMMAND grep ^mpiexec COMMAND sed "s/^.* //g" OUTPUT_VARIABLE OPENMPI_VERSION) - IF (DEFINED OPENMPI_VERSION AND NOT "${OPENMPI_VERSION}" STREQUAL "") - IF (${OPENMPI_VERSION} VERSION_GREATER_EQUAL "4.0.0") + IF("${LIBS_MPI_NAME}" MATCHES "OpenMPI" AND ${MPI_C_LIBRARY_VERSION} VERSION_GREATER_EQUAL "4.0.0") SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag") ELSE() SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag") ENDIF() - ELSE() - SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag") - ENDIF() + MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} to be compatible with detected [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})") ELSE() SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag") + MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} as no MPI support was requested") ENDIF() - MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} to be compatible with detected MPI version") MARK_AS_ADVANCED(FORCE HDF5_TAG) # Set HDF5 build dir @@ -169,6 +172,10 @@ ELSE() SET(LIBS_HDF5CC ${CMAKE_C_COMPILER} ) ENDIF() + # Set parallel build with maximum number of threads + INCLUDE(ProcessorCount) + PROCESSORCOUNT(N) + # Optional Features: # --enable-silent-rules less verbose build output (undo: "make V=1") # --enable-build-mode=(debug|production|clean) @@ -192,12 +199,14 @@ ELSE() PREFIX ${LIBS_HDF5_DIR} UPDATE_COMMAND "" CONFIGURE_COMMAND FC=${LIBS_HDF5FC} CC=${LIBS_HDF5CC} ${LIBS_HDF5_DIR}/src/HDF5/configure --prefix=${LIBS_HDF5_DIR} --with-pic --enable-fortran ${LIBS_HDF5PARALLEL} --libdir=${LIBS_HDF5_DIR}/lib --enable-build-mode=production --enable-silent-rules --disable-dependency-tracking - BUILD_COMMAND ${MAKE} + BUILD_BYPRODUCTS ${LIBS_HDF5_DIR}/lib/libhdf5_fortran.a ${LIBS_HDF5_DIR}/lib/libhdf5.a ${LIBS_HDF5_DIR}/bin/h5diff + # Configure explicitly requires GNU make + BUILD_COMMAND make -j${N} ) SET(LIBS_HDF5_CMAKE FALSE) # CMake HDF5 is fast but not yet reliable. The following section can be enabled once HDF5 promotes the CMake option to stable - #ExternalProject_Add(HDF5 + #EXTERNALPROJECT_ADD(HDF5 # GIT_REPOSITORY ${HDF5DOWNLOAD} # GIT_TAG ${HDF5_TAG} # GIT_PROGRESS TRUE @@ -239,7 +248,11 @@ IF(LIBS_HDF5_CMAKE) # HDF5 build with configure ELSE() INCLUDE_DIRECTORIES (${HDF5_INCLUDE_DIR_FORTRAN} ${HDF5_INCLUDE_DIR}) - MESSAGE(STATUS "Found HDF5 Libs: " ${HDF5_LIBRARIES}) + IF(${HDF5_IS_PARALLEL}) + MESSAGE(STATUS "Compiling with [HDF5] (v${HDF5_VERSION}) with parallel support") + ELSE() + MESSAGE(STATUS "Compiling with [HDF5] (v${HDF5_VERSION}) without parallel support") + ENDIF() LIST(APPEND linkedlibs ${HDF5_LIBRARIES} ) ENDIF() @@ -424,7 +437,7 @@ ELSE() SET(LIBS_CGNS_DLDIR ${LIBS_EXTERNAL_LIB_DIR}/CGNS${LIBS_BUILD_CGNS_TAG}) SET(LIBS_CGNS_DIR ${LIBS_CGNS_DLDIR}) - IF (NOT EXISTS "${LIBS_CGNS_DIR}/build/lib/libcgns.a") + IF (NOT EXISTS "${LIBS_CGNS_DIR}/lib/libcgns.a") STRING(COMPARE EQUAL ${LIBS_BUILD_CGNS_INT} "64" LIBS_CGNS_64BIT) # Origin pointing to Github @@ -445,10 +458,11 @@ ELSE() GIT_PROGRESS TRUE ${${GITSHALLOW}} PREFIX ${LIBS_CGNS_DIR} - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBS_CGNS_DIR}/build -DCMAKE_PREFIX_PATH=${LIBS_HDF5_DIR} / + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${LIBS_CGNS_DIR} -DCMAKE_PREFIX_PATH=${LIBS_HDF5_DIR} / -DCGNS_ENABLE_FORTRAN=ON -DCGNS_ENABLE_64BIT=${LIBS_CGNS_64BIT} -DCGNS_BUILD_SHARED=OFF -DCGNS_USE_SHARED=OFF / -DCMAKE_BUILD_TYPE=Release -DCGNS_BUILD_CGNSTOOLS=OFF -DCGNS_ENABLE_HDF5=${LIBS_BUILD_CGNS_ENABLE_HDF5} / - -DCGNS_ENABLE_PARALLEL=OFF -DCGNS_ENABLE_TESTS=OFF -DCMAKE_SKIP_RPATH=ON / + -DCGNS_ENABLE_PARALLEL=OFF -DCGNS_ENABLE_TESTS=OFF -DCMAKE_SKIP_RPATH=ON + BUILD_BYPRODUCTS ${LIBS_CGNS_DIR}/lib/libcgns.a ) # If HDF5 is built in HOPR, it must occur before the CGNS compilation (for the support of HDF5-based CGNS files) IF(LIBS_BUILD_HDF5) @@ -459,8 +473,10 @@ ELSE() LIST(APPEND SELFBUILTEXTERNALS cgns) ENDIF() - LIST(INSERT linkedlibs 0 ${LIBS_CGNS_DIR}/build/lib/libcgns.a) - INCLUDE_DIRECTORIES( ${LIBS_CGNS_DIR}/build/include) + LIST(INSERT linkedlibs 0 ${LIBS_CGNS_DIR}/lib/libcgns.a) + INCLUDE_DIRECTORIES( ${LIBS_CGNS_DIR}/include) + + MESSAGE(STATUS "Compiling with [CGNS] (${LIBS_BUILD_CGNS_TAG})") ENDIF() # set pre-processor flag for CGNS version From a372fc6cd97bc1c5ed69039bdc5b4cced5bf465c Mon Sep 17 00:00:00 2001 From: Patrick Kopper Date: Tue, 10 Aug 2021 12:05:07 +0000 Subject: [PATCH 3/8] Add self-built math libraries (LAPACK/OpenBLAS) --- CMakeListsLib.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeListsLib.txt b/CMakeListsLib.txt index 4b4d9df..c4e256f 100644 --- a/CMakeListsLib.txt +++ b/CMakeListsLib.txt @@ -276,15 +276,17 @@ IF(NOT LIBS_BUILD_MATH_LIB) FIND_PACKAGE(LAPACK QUIET) IF (LAPACK_FOUND) LIST(APPEND linkedlibs ${LAPACK_LIBRARIES}) - MESSAGE(STATUS "Using system BLAS/Lapack library") + MESSAGE(STATUS "Compiling with system [BLAS/Lapack]") ENDIF() - -# Build LAPACK/OpenBLAS in HOPR ELSE() # Offer LAPACK and OpenBLAS SET (LIBS_BUILD_MATH_LIB_VENDOR LAPACK CACHE STRING "Choose the type of math lib vendor, options are: LAPACK, OpenBLAS.") SET_PROPERTY(CACHE LIBS_BUILD_MATH_LIB_VENDOR PROPERTY STRINGS LAPACK OpenBLAS) + # Set parallel build with maximum number of threads + INCLUDE(ProcessorCount) + PROCESSORCOUNT(N) + # Build LAPACK IF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "LAPACK") # Origin pointing to Github @@ -328,6 +330,7 @@ ELSE() PREFIX ${LIBS_MATH_DIR} UPDATE_COMMAND "" CMAKE_ARGS -DCMAKE_INSTALL_LIBDIR=lib -DCMAKE_INSTALL_PREFIX=${LIBS_MATH_DIR} -DBLAS++=OFF -DLAPACK++=OFF -DBUILD_SHARED_LIBS=ON -DCBLAS=OFF -DLAPACKE=OFF -DBUILD_TESTING=OFF + BUILD_BYPRODUCTS ${LIBS_MATH_DIR}/lib/liblapack.so ${LIBS_MATH_DIR}/lib/libblas.so ) LIST(APPEND SELFBUILTEXTERNALS ${LIBS_BUILD_MATH_LIB_VENDOR}) @@ -344,8 +347,11 @@ ELSE() PREFIX ${LIBS_MATH_DIR} UPDATE_COMMAND "" CONFIGURE_COMMAND "" + BUILD_BYPRODUCTS ${LIBS_MATH_DIR}/src/${LIBS_BUILD_MATH_LIB_VENDOR}/libopenblas.so BUILD_IN_SOURCE TRUE INSTALL_COMMAND "" + # Configure explicitly requires GNU make + BUILD_COMMAND make -j${N} ) LIST(APPEND SELFBUILTEXTERNALS ${LIBS_BUILD_MATH_LIB_VENDOR}) @@ -368,7 +374,7 @@ ELSE() # Actually add the math lib paths to the linking paths INCLUDE_DIRECTORIES (${MATH_LIB_LIBRARIES}) LIST(APPEND linkedlibs ${LAPACK_LIBRARY} ${BLAS_LIBRARY}) - MESSAGE(STATUS "Using self-built LAPACK library") + MESSAGE(STATUS "Compiling with self-built [LAPACK]") ELSEIF (LIBS_BUILD_MATH_LIB_VENDOR MATCHES "OpenBLAS") # Set math lib paths SET(MATH_LIB_LIBRARIES ${LIBS_MATH_DIR}/src/${LIBS_BUILD_MATH_LIB_VENDOR}) @@ -382,7 +388,7 @@ ELSE() # Actually add the math lib paths to the linking paths INCLUDE_DIRECTORIES (${MATH_LIB_LIBRARIES}) LIST(APPEND linkedlibs ${LAPACK_LIBRARY} ${BLAS_LIBRARY}) - MESSAGE(STATUS "Using self-built OpenBLAS library") + MESSAGE(STATUS "Compiling with self-built [OpenBLAS]") ENDIF() ENDIF() From 8fde1b90b7d8b9279689ee48e1506899ec0900b5 Mon Sep 17 00:00:00 2001 From: Patrick Kopper Date: Fri, 22 Apr 2022 15:11:44 +0200 Subject: [PATCH 4/8] Reliably detect supported MPI vendors and version in CMake Some of the code is based on https://github.com/NOAA-EMC/NCEPLIBS-external/blob/develop/CMakeLists.txt [GNU Lesser General Public License v3.0] --- CMakeListsLib.txt | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/CMakeListsLib.txt b/CMakeListsLib.txt index c4e256f..46da18f 100644 --- a/CMakeListsLib.txt +++ b/CMakeListsLib.txt @@ -51,7 +51,9 @@ ENDIF() OPTION(LIBS_USE_MPI "Compile SINGLE or MPI version" OFF) MARK_AS_ADVANCED(FORCE LIBS_USE_MPI) IF(LIBS_USE_MPI) + SET(MPI_DETERMINE_LIBRARY_VERSION TRUE) FIND_PACKAGE(MPI REQUIRED) + IF (NOT MPI_Fortran_NO_INTERROGATE) FOREACH(DIR ${MPI_INCLUDE_PATH}) INCLUDE_DIRECTORIES(${DIR}) @@ -63,12 +65,29 @@ IF(LIBS_USE_MPI) ENDIF() MARK_AS_ADVANCED(FORCE MPI_LIBRARY MPI_EXTRA_LIBRARY) - MESSAGE(STATUS "Building HOPR with MPI") - MESSAGE(STATUS "MPI Compiler: " ${MPI_Fortran_COMPILER}) - # Detect HPE MPT implementation since if changes some MPI definitions - IF("${MPI_Fortran_COMPILER}" MATCHES "mpt") + + # Detect MPI implementation and version since it changes some MPI definitions + IF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*CRAY MPICH.*" AND MPI_C_VERSION_MAJOR MATCHES "3") + SET(LIBS_MPI_NAME "Cray MPICH") + STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING}) + ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*MPICH.*" AND MPI_C_VERSION_MAJOR MATCHES "3") + SET(LIBS_MPI_NAME "MPICH") + STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING}) + ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*Open MPI.*" AND MPI_C_VERSION_MAJOR MATCHES "3") + SET(LIBS_MPI_NAME "OpenMPI") + STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING}) + ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*HPE MPT.*" AND MPI_C_VERSION_MAJOR MATCHES "3") + SET(LIBS_MPI_NAME "HPE MPT") + STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING}) ADD_DEFINITIONS(-DLIBS_MPT=1) + ELSEIF(MPI_C_LIBRARY_VERSION_STRING MATCHES ".*Intel.*" AND MPI_C_VERSION_MAJOR MATCHES "3") + SET(LIBS_MPI_NAME "Intel MPI") + STRING(REGEX MATCH "([0-9]+)\\.([0-9]+)" MPI_C_LIBRARY_VERSION ${MPI_C_LIBRARY_VERSION_STRING}) + ELSE() + MESSAGE(FATAL_ERROR "Cannot detect supported MPI type or version. Valid options are Cray MPICH, IntelMPI, MPICH, HPE MPT, and OpenMPI supporting MPI version 3.x") ENDIF() + + MESSAGE(STATUS "Compiling with [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})") ADD_DEFINITIONS(-DUSE_MPI=1) ELSE() ADD_DEFINITIONS(-DUSE_MPI=0) @@ -145,10 +164,10 @@ ELSE() IF(LIBS_USE_MPI) # HDF5 1.12.0 and greater is compatible with OpenMPI 4.0.0 and greater IF("${LIBS_MPI_NAME}" MATCHES "OpenMPI" AND ${MPI_C_LIBRARY_VERSION} VERSION_GREATER_EQUAL "4.0.0") - SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag") - ELSE() - SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag") - ENDIF() + SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag") + ELSE() + SET (HDF5_TAG "hdf5-1_10_6" CACHE STRING "HDF5 version tag") + ENDIF() MESSAGE (STATUS "Setting HDF5 to tag ${HDF5_TAG} to be compatible with detected [${LIBS_MPI_NAME}] (v${MPI_C_LIBRARY_VERSION})") ELSE() SET (HDF5_TAG "hdf5-1_12_0" CACHE STRING "HDF5 version tag") From 3be119ce429ce59255791937ffa13e3d3bc78843 Mon Sep 17 00:00:00 2001 From: Stephen Copplestone Date: Mon, 13 Mar 2023 22:58:07 +0100 Subject: [PATCH 5/8] Test binary creation+7z+upload artefact in github actions --- .github/workflows/AppImage.yml | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/AppImage.yml diff --git a/.github/workflows/AppImage.yml b/.github/workflows/AppImage.yml new file mode 100644 index 0000000..6616a19 --- /dev/null +++ b/.github/workflows/AppImage.yml @@ -0,0 +1,54 @@ +name: AppImage.yml + +on: + push: + pull_request: + + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest + + # Use centos7 + container: + image: centos:7 + + steps: + - uses: actions/checkout@v3 + + - name: Dependencies + run: curl -L -O https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-Linux-x86_64.sh + chmod +x cmake-3.16.4-Linux-x86_64.sh + ./cmake-3.16.4-Linux-x86_64.sh --skip-license --prefix=/usr/local + curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-16.02-20.el7.x86_64.rpm + curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-20.el7.x86_64.rpm + rpm -U --quiet p7zip-16.02-20.el7.x86_64.rpm + rpm -U --quiet p7zip-plugins-16.02-20.el7.x86_64.rpm + yum install -y make libasan gcc-c++ + + - name: Configure CMake + shell: bash + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + #run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DLIBS_USE_MPI=OFF + + - name: Build + shell: bash + # Build your program with the given configuration + #run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: cmake --build ${{github.workspace}}/build + + - name: Create archive + run: mkdir artifact + 7z a artifact/hopr.zip ./build/bin/hopr + + # Upload hopr binary archive as an artifact + - name: Upload artifact + uses: actions/upload-artifact@v1 + with: + name: hopr-binary-archives + path: artifact From e719c9c604cb1d7ccad32e55d13cc4905e5ac2f5 Mon Sep 17 00:00:00 2001 From: Stephen Copplestone Date: Mon, 13 Mar 2023 22:59:21 +0100 Subject: [PATCH 6/8] Show cmake generator info --- CMakeListsMachine.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeListsMachine.txt b/CMakeListsMachine.txt index 6d27da4..a25df63 100644 --- a/CMakeListsMachine.txt +++ b/CMakeListsMachine.txt @@ -9,6 +9,8 @@ SITE_NAME(CMAKE_HOSTNAME) # ========================================================================= # CMake generator settings # ========================================================================= +SET(USED_CMAKE_GENERATOR "${CMAKE_GENERATOR}" CACHE STRING "Expose CMAKE_GENERATOR (cannot be changed here)" FORCE) +MESSAGE(STATUS "Using cmake generator: ${CMAKE_GENERATOR}") IF("${CMAKE_GENERATOR}" MATCHES "Ninja") # CMake introduced the CMAKE_COLOR_DIAGNOSTICS flag with 3.24.0, https://gitlab.kitware.com/cmake/cmake/-/merge_requests/6990 IF(NOT(${CMAKE_VERSION} VERSION_LESS "3.24.0")) From 2da87248c9016f55e7839e8ecd0339b651cf365b Mon Sep 17 00:00:00 2001 From: Stephen Copplestone Date: Tue, 14 Mar 2023 10:17:26 +0100 Subject: [PATCH 7/8] Fix for running multi-line commands in github actions .yml --- .github/workflows/{AppImage.yml => ninja.yml} | 21 ++++++++++++------- CMakeListsLib.txt | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) rename .github/workflows/{AppImage.yml => ninja.yml} (69%) diff --git a/.github/workflows/AppImage.yml b/.github/workflows/ninja.yml similarity index 69% rename from .github/workflows/AppImage.yml rename to .github/workflows/ninja.yml index 6616a19..ecd5ecf 100644 --- a/.github/workflows/AppImage.yml +++ b/.github/workflows/ninja.yml @@ -2,8 +2,7 @@ name: AppImage.yml on: push: - pull_request: - + #pull_request: jobs: build: @@ -20,21 +19,28 @@ jobs: - uses: actions/checkout@v3 - name: Dependencies - run: curl -L -O https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-Linux-x86_64.sh + run: | + curl -L -O https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4-Linux-x86_64.sh chmod +x cmake-3.16.4-Linux-x86_64.sh ./cmake-3.16.4-Linux-x86_64.sh --skip-license --prefix=/usr/local curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-16.02-20.el7.x86_64.rpm curl -L -O https://www.mirrorservice.org/sites/dl.fedoraproject.org/pub/epel/7/x86_64/Packages/p/p7zip-plugins-16.02-20.el7.x86_64.rpm rpm -U --quiet p7zip-16.02-20.el7.x86_64.rpm rpm -U --quiet p7zip-plugins-16.02-20.el7.x86_64.rpm - yum install -y make libasan gcc-c++ + yum install -y epel-release + yum install -y make libasan gcc-gfortran gcc-c++ unzip git openblas-devel lapack-devel zlib-devel + curl -L -O https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-linux.zip + unzip ninja-linux.zip + mv ./ninja /usr/bin - name: Configure CMake shell: bash # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type #run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DLIBS_USE_MPI=OFF + # hdf5-openmpi-devel on centos7 probably broken + #run: cmake -G Ninja -B ${{github.workspace}}/build -DLIBS_BUILD_HDF5=OFF -DCMAKE_BUILD_TYPE=Release -DLIBS_USE_MPI=OFF + run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DLIBS_USE_MPI=OFF - name: Build shell: bash @@ -43,8 +49,9 @@ jobs: run: cmake --build ${{github.workspace}}/build - name: Create archive - run: mkdir artifact - 7z a artifact/hopr.zip ./build/bin/hopr + run: | + mkdir artifact + 7z a artifact/hopr.zip ${{github.workspace}}/build/bin/hopr # Upload hopr binary archive as an artifact - name: Upload artifact diff --git a/CMakeListsLib.txt b/CMakeListsLib.txt index 46da18f..5323e30 100644 --- a/CMakeListsLib.txt +++ b/CMakeListsLib.txt @@ -255,7 +255,7 @@ ELSE() LIST(APPEND HDF5_INCLUDE_DIR ${HDF5_C_INCLUDE_DIR}) MARK_AS_ADVANCED(FORCE HDF5_z_LIBRARY_RELEASE) # Add ZLIB to include paths for HDF5 data compression - FIND_LIBRARY(HDF5_z_LIBRARY_RELEASE z) + FIND_LIBRARY(HDF5_z_LIBRARY_RELEASE z REQUIRED) LIST(APPEND HDF5_LIBRARIES ${HDF5_hdf5_fortran_LIBRARY_RELEASE} ${HDF5_hdf5_LIBRARY_RELEASE} ${HDF5_z_LIBRARY_RELEASE} -ldl) ENDIF() From b1a24a1fc1c520c471dfb9b76606f31da8a7ced9 Mon Sep 17 00:00:00 2001 From: Stephen Copplestone Date: Tue, 14 Mar 2023 10:26:47 +0100 Subject: [PATCH 8/8] Renamed github actions .yml files --- .github/workflows/{cmake.yml => cmake-make.yml} | 2 +- .github/workflows/{ninja.yml => cmake-ninja.yml} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{cmake.yml => cmake-make.yml} (99%) rename .github/workflows/{ninja.yml => cmake-ninja.yml} (99%) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake-make.yml similarity index 99% rename from .github/workflows/cmake.yml rename to .github/workflows/cmake-make.yml index e25c76c..370c64a 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake-make.yml @@ -1,4 +1,4 @@ -name: CMake +name: cmake-make on: push: diff --git a/.github/workflows/ninja.yml b/.github/workflows/cmake-ninja.yml similarity index 99% rename from .github/workflows/ninja.yml rename to .github/workflows/cmake-ninja.yml index ecd5ecf..0e896d8 100644 --- a/.github/workflows/ninja.yml +++ b/.github/workflows/cmake-ninja.yml @@ -1,4 +1,4 @@ -name: AppImage.yml +name: cmake-ninja on: push: