From 7a80a90022ef6cebcbb2b697b7a1bb7ef52bfbe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 22 Nov 2022 09:40:20 +0100 Subject: [PATCH] CMake: Use modern CMake Simplify conditionals and generator expressions. Rewrite FindMpiexecBackend as a regular function. Make found package messages more homogeneous. --- CMakeLists.txt | 31 ++++++++------- cmake/FindCUDACompilerClang.cmake | 12 +++--- cmake/FindCUDACompilerNVCC.cmake | 14 +++---- cmake/FindMpiexecBackend.cmake | 48 ----------------------- cmake/espresso_get_mpiexec_vendor.cmake | 51 +++++++++++++++++++++++++ src/CMakeLists.txt | 3 -- 6 files changed, 81 insertions(+), 78 deletions(-) delete mode 100644 cmake/FindMpiexecBackend.cmake create mode 100644 cmake/espresso_get_mpiexec_vendor.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ceede6dec2..ef28eebc5f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,14 +123,12 @@ set(TEST_TIMEOUT "300" CACHE STRING "Timeout in seconds for each testsuite test") if(WITH_CCACHE) - find_program(CCACHE ccache) - if(CCACHE) - message(STATUS "Found ccache ${CCACHE}") - set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} CACHE STRING "ccache executable") - else() - message(FATAL_ERROR "ccache not found.") - endif(CCACHE) -endif(WITH_CCACHE) + find_program(CCACHE_PROGRAM ccache REQUIRED) + if(CCACHE_PROGRAM) + message(STATUS "Found ccache: ${CCACHE_PROGRAM}") + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM}) + endif() +endif() # Write compile commands to file, for various tools... set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -321,7 +319,12 @@ endif(WITH_VALGRIND_INSTRUMENTATION) # find_package(MPI 3.0 REQUIRED) -find_package(MpiexecBackend) +include(espresso_get_mpiexec_vendor) +espresso_get_mpiexec_vendor() +message( + STATUS + "Found ${ESPRESSO_MPIEXEC_VENDOR}: ${MPIEXEC} (version \"${ESPRESSO_MPIEXEC_VERSION}\")" +) # OpenMPI checks the number of processes against the number of CPUs set(MPIEXEC_OVERSUBSCRIBE "") @@ -329,12 +332,12 @@ set(MPIEXEC_OVERSUBSCRIBE "") set(ESPRESSO_MPIEXEC_GUARD_SINGLETON_NUMA OFF) set(ESPRESSO_CPU_MODEL_NAME_OMPI_SINGLETON_NUMA_PATTERN "AMD (EPYC|Ryzen)") -if("${MPIEXEC_BACKEND_NAME}" STREQUAL "OpenMPI") - if("${MPIEXEC_BACKEND_VERSION}" VERSION_GREATER_EQUAL 2.0.0) +if("${ESPRESSO_MPIEXEC_VENDOR}" STREQUAL "OpenMPI") + if(${ESPRESSO_MPIEXEC_VERSION} VERSION_GREATER_EQUAL 2.0.0) set(MPIEXEC_OVERSUBSCRIBE "-oversubscribe") endif() - if("${MPIEXEC_BACKEND_VERSION}" VERSION_GREATER_EQUAL 4.0 - AND "${MPIEXEC_BACKEND_VERSION}" VERSION_LESS 5.0) + if(${ESPRESSO_MPIEXEC_VERSION} VERSION_GREATER_EQUAL 4.0 + AND ${ESPRESSO_MPIEXEC_VERSION} VERSION_LESS 5.0) if(NOT DEFINED ESPRESSO_CPU_MODEL_NAME) if(CMAKE_SYSTEM_NAME STREQUAL Linux) if(EXISTS /proc/cpuinfo) @@ -363,7 +366,7 @@ endif() # base folder is deleted upon completion of a job, other jobs will fail when # attempting to create subdirectories in the base folder. # https://github.com/open-mpi/ompi/issues/8510 -if("${MPIEXEC_BACKEND_NAME}" STREQUAL "OpenMPI" AND INSIDE_DOCKER) +if("${ESPRESSO_MPIEXEC_VENDOR}" STREQUAL "OpenMPI" AND INSIDE_DOCKER) cmake_host_system_information(RESULT hostname QUERY HOSTNAME) function(set_mpiexec_tmpdir) set(MPIEXEC_TMPDIR --mca orte_tmpdir_base diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 46d26e2931f..0bc348c9c85 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -87,12 +87,12 @@ set(CUDA 1) target_compile_options( espresso_cuda_flags INTERFACE - $<$:-g> - $<$:-O3 -DNDEBUG> - $<$:-O2 -DNDEBUG> - $<$:-O2 -g -DNDEBUG> - $<$:-O3 -g> - $<$:-O3 -g> + $<$:-g> + $<$:-O3 -DNDEBUG> + $<$:-O2 -DNDEBUG> + $<$:-O2 -g -DNDEBUG> + $<$:-O3 -g> + $<$:-O3 -g> # GTX-900 series (Maxwell) $<$:--cuda-gpu-arch=sm_52> # GTX-1000 series (Pascal) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index 0b9bda3e343..1c3fd0ce07a 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -53,12 +53,12 @@ add_library(espresso::cuda_flags ALIAS espresso_cuda_flags) target_compile_options( espresso_cuda_flags INTERFACE - $<$:> - $<$:-Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG> - $<$:-Xptxas=-O2 -Xcompiler=-Os -DNDEBUG> - $<$:-Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG> - $<$:-Xptxas=-O3 -Xcompiler=-Og,-g> - $<$:-Xptxas=-O3 -Xcompiler=-O3,-g> + $<$:> + $<$:-Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG> + $<$:-Xptxas=-O2 -Xcompiler=-Os -DNDEBUG> + $<$:-Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG> + $<$:-Xptxas=-O3 -Xcompiler=-Og,-g> + $<$:-Xptxas=-O3 -Xcompiler=-O3,-g> "--compiler-bindir=${CMAKE_CXX_COMPILER}" $<$:-Xcompiler=-Werror;-Xptxas=-Werror> $<$:-Xcompiler=-isysroot;-Xcompiler=${CMAKE_OSX_SYSROOT}> @@ -67,7 +67,7 @@ target_compile_options( function(add_gpu_library) add_library(${ARGV}) set(GPU_TARGET_NAME ${ARGV0}) - set_property(TARGET ${GPU_TARGET_NAME} PROPERTY CUDA_SEPARABLE_COMPILATION ON) + set_target_properties(${GPU_TARGET_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON) target_link_libraries(${GPU_TARGET_NAME} PRIVATE espresso::cuda_flags) list(APPEND cuda_archs 75) # RTX-2000 series (Turing) list(APPEND cuda_archs 61) # GTX-1000 series (Pascal) diff --git a/cmake/FindMpiexecBackend.cmake b/cmake/FindMpiexecBackend.cmake deleted file mode 100644 index 3ec12502150..00000000000 --- a/cmake/FindMpiexecBackend.cmake +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (C) 2022 The ESPResSo project -# -# This file is part of ESPResSo. -# -# ESPResSo is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# ESPResSo is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# - -# Find the MPI backend. -# -# This code sets the following variables: -# -# MPIEXEC_BACKEND_NAME MPIEXEC_BACKEND_VERSION - -set(MPIEXEC_BACKEND_NAME "unknown") -set(MPIEXEC_BACKEND_VERSION 0.0.0) - -execute_process( - COMMAND ${MPIEXEC} --version RESULT_VARIABLE mpi_version_result - OUTPUT_VARIABLE mpi_version_output ERROR_VARIABLE mpi_version_output) -if(mpi_version_result EQUAL 0) - if(mpi_version_output MATCHES "Intel\\(R\\) MPI Library") - set(MPIEXEC_BACKEND_NAME "Intel") - string(REGEX REPLACE ".*Build ([0-9]+).*" "\\1" MPIEXEC_BACKEND_VERSION ${mpi_version_output}) - endif() - if(mpi_version_output MATCHES "HYDRA") - set(MPIEXEC_BACKEND_NAME "MPICH") - string(REGEX REPLACE ".*Version: +([0-9\\.]+).*" "\\1" MPIEXEC_BACKEND_VERSION ${mpi_version_output}) - endif() - if(mpi_version_output MATCHES "\\(Open(RTE| MPI)\\)") - set(MPIEXEC_BACKEND_NAME "OpenMPI") - string(REGEX REPLACE ".*\\(Open(RTE| MPI)\\) ([0-9\\.]+).*" "\\2" MPIEXEC_BACKEND_VERSION ${mpi_version_output}) - endif() -endif() - -include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(MpiexecBackend REQUIRED_VARS MPIEXEC) diff --git a/cmake/espresso_get_mpiexec_vendor.cmake b/cmake/espresso_get_mpiexec_vendor.cmake new file mode 100644 index 00000000000..b1d27dd7a94 --- /dev/null +++ b/cmake/espresso_get_mpiexec_vendor.cmake @@ -0,0 +1,51 @@ +# +# Copyright (C) 2022 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Find the MPI backend. +# +# This code sets the following variables: +# +# ESPRESSO_MPIEXEC_VENDOR ESPRESSO_MPIEXEC_VERSION + +function(espresso_get_mpiexec_vendor) + set(MPIEXEC_BACKEND_NAME "unknown") + set(MPIEXEC_BACKEND_VERSION 0.0.0) + execute_process( + COMMAND ${MPIEXEC} --version RESULT_VARIABLE MPI_VERSION_RESULT + OUTPUT_VARIABLE MPI_VERSION_OUTPUT ERROR_VARIABLE MPI_VERSION_OUTPUT) + if(MPI_VERSION_RESULT EQUAL 0) + if(MPI_VERSION_OUTPUT MATCHES "Intel\\(R\\) MPI Library") + set(MPIEXEC_BACKEND_NAME "Intel") + string(REGEX REPLACE ".*Build ([0-9]+).*" "\\1" MPIEXEC_BACKEND_VERSION + ${MPI_VERSION_OUTPUT}) + endif() + if(MPI_VERSION_OUTPUT MATCHES "HYDRA") + set(MPIEXEC_BACKEND_NAME "MPICH") + string(REGEX REPLACE ".*Version: +([0-9\\.]+).*" "\\1" + MPIEXEC_BACKEND_VERSION ${MPI_VERSION_OUTPUT}) + endif() + if(MPI_VERSION_OUTPUT MATCHES "\\(Open(RTE| MPI)\\)") + set(MPIEXEC_BACKEND_NAME "OpenMPI") + string(REGEX REPLACE ".*\\(Open(RTE| MPI)\\) ([0-9\\.]+).*" "\\2" + MPIEXEC_BACKEND_VERSION ${MPI_VERSION_OUTPUT}) + endif() + endif() + set(ESPRESSO_MPIEXEC_VENDOR ${MPIEXEC_BACKEND_NAME} PARENT_SCOPE) + set(ESPRESSO_MPIEXEC_VERSION ${MPIEXEC_BACKEND_VERSION} PARENT_SCOPE) +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c996d06f17d..176c276a5a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -42,9 +42,6 @@ endif(SCAFACOS) if(WITH_PYTHON) add_subdirectory(script_interface) -endif() - -if(WITH_PYTHON) add_subdirectory(python) endif()