Unverified Commit 3fa7265f authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

modernize CMake script code and add version tests for Clang and Intel to...

modernize CMake script code and add version tests for Clang and Intel to switch to OpenMP4 semantics
parent 7a16567e
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -248,11 +248,15 @@ if(BUILD_OMP)
    message(FATAL_ERROR "Cannot find the 'omp.h' header file required for full OpenMP support")
  endif()

  if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9))
    # GCC 9.x strictly implements OpenMP 4.0 semantics for consts.
    add_definitions(-DLAMMPS_OMP_COMPAT=4)
  if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9)) OR
      ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.99.9)) OR
      ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18.99.9))
      )
    # GCC 9.x and later plus Clang 10.x and later implement strict OpenMP 4.0 semantics for consts.
    # Intel 18.0 was tested to support both, so we switch to OpenMP 4+ from 19.x onward to be safe.
    target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=4)
  else()
    add_definitions(-DLAMMPS_OMP_COMPAT=3)
    target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=3)
  endif()
  target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX)
endif()
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@
//
// To date, most compilers still accept the OpenMP 3.0 form,
// so this is what LAMMPS primarily uses.  For those compilers
// that strictly implement OpenMP 4.0 (such as GCC 9.0), we
// give up default(none).
// that strictly implement OpenMP 4.0 (such as GCC 9.0 and later
// or Clang 10.0 and later), we give up default(none).
#if LAMMPS_OMP_COMPAT == 4
#    define LMP_SHARED(...)
#    define LMP_DEFAULT_NONE default(shared)