Unverified Commit f893f4f8 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

set host specific optimizations in CMAKE_TUNE_FLAGS, so they can be conveniently overridden

parent 5779731d
Loading
Loading
Loading
Loading
+14 −18
Original line number Diff line number Diff line
@@ -53,11 +53,18 @@ include(CheckIncludeFileCXX)

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel")
  set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
  if (NOT CMAKE_TUNE_FLAGS)
    if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
      set(CMAKE_TUNE_FLAGS "-xCOMMON-AVX512")
    else()
      set(CMAKE_TUNE_FLAGS "-xHost")
    endif()
  endif()
endif()

if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  if(NOT ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug"))
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math -ftree-vectorize -fexpensive-optimizations")
  if(NOT CMAKE_TUNE_FLAGS)
    set (CMAKE_TUNE_FLAGS "-ffast-math -march=native")
  endif()
endif()

@@ -70,22 +77,7 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  option(ENABLE_COVERAGE "Enable code coverage" OFF)
  mark_as_advanced(ENABLE_COVERAGE)
  if(ENABLE_COVERAGE)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
  endif()
  option(ENABLE_SANITIZE_ADDRESS "Enable address sanitizer" OFF)
  mark_as_advanced(ENABLE_SANITIZE_ADDRESS)
  if(ENABLE_SANITIZE_ADDRESS)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  endif()
  option(ENABLE_SANITIZE_UNDEFINED "Enable undefined behavior sanitizer" OFF)
  mark_as_advanced(ENABLE_SANITIZE_UNDEFINED)
  if(ENABLE_SANITIZE_UNDEFINED)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
  endif()
  option(ENABLE_SANITIZE_THREAD "Enable thread sanitizer" OFF)
  mark_as_advanced(ENABLE_SANITIZE_THREAD)
  if(ENABLE_SANITIZE_THREAD)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
    set (CMAKE_TUNE_FLAGS "--coverage")
  endif()
endif()

@@ -347,6 +339,10 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
  list(APPEND LAMMPS_LINK_LIBS -lwsock32 -lpsapi)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_TUNE_FLAGS}")
if(CMAKE_Fortran_FLAGS)
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_TUNE_FLAGS}")
endif()
########################################################################
# Basic system tests (standard libraries, headers, functions, types)   #
########################################################################
+0 −5
Original line number Diff line number Diff line
@@ -74,11 +74,6 @@ if(PKG_USER-INTEL)
    add_definitions(-DLMP_INTEL_OFFLOAD)
  else()
    if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
      if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xCOMMON-AVX512")
      else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost")
      endif()
      include(CheckCXXCompilerFlag)
      foreach(_FLAG -O2 -fp-model fast=2 -no-prec-div -qoverride-limits -qopt-zmm-usage=high -qno-offload -fno-alias -ansi-alias -restrict)
        check_cxx_compiler_flag("${__FLAG}" COMPILER_SUPPORTS${_FLAG})
+7 −0
Original line number Diff line number Diff line
@@ -213,6 +213,13 @@ A few example command lines are:
For compiling with the Clang/LLVM compilers a special CMake preset is
included that can be loaded with `-C ../cmake/presets/clang.cmake`.

In addition you can set ``CMAKE_TUNE_FLAGS`` to specifically add compiler
flags to tune for optimal performance on given hosts. By default these are
initialized to some compiler specific flags, where known, to optimize the
LAMMPS executable with optimizations and instructions available on the host
where LAMMPS is compiled. For example, for Intel compilers this would be
``-xHost`` and for GNU compilers this would be ``-march=native``.

.. note::

   When the cmake command completes, it prints a summary to the screen