diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 1f29689f46..bdd1d45187 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -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() diff --git a/src/omp_compat.h b/src/omp_compat.h index add429eea8..d80d6f6f7f 100644 --- a/src/omp_compat.h +++ b/src/omp_compat.h @@ -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)