Unverified Commit 82b767f6 authored by Michael Lamparski's avatar Michael Lamparski Committed by GitHub
Browse files

Merge pull request #1 from akohlmey/omp4-compat

Update OpenMP 4+ compatibility pull request for LAMMPS
parents 0fa6472c 2edc6939
Loading
Loading
Loading
Loading
+8 −4
Original line number Original line 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")
    message(FATAL_ERROR "Cannot find the 'omp.h' header file required for full OpenMP support")
  endif()
  endif()


  if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9))
  if (((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9)) OR
    # GCC 9.x strictly implements OpenMP 4.0 semantics for consts.
      ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.99.9)) OR
    add_definitions(-DLAMMPS_OMP_COMPAT=4)
      ((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()
  else()
    add_definitions(-DLAMMPS_OMP_COMPAT=3)
    target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=3)
  endif()
  endif()
  target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX)
  target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX)
endif()
endif()
+9 −7
Original line number Original line Diff line number Diff line
@@ -142,13 +142,15 @@ please refer to its documentation.
**OpenMP Compiler compatibility info**\ :
**OpenMP Compiler compatibility info**\ :


Some compilers do not fully support the ``default(none)`` directive
Some compilers do not fully support the ``default(none)`` directive
and others (e.g. GCC version 9 and beyond) may implement OpenMP 4.0
and others (e.g. GCC version 9 and beyond, Clang version 10 and later)
semantics, which are incompatible with the OpenMP 3.1 semantics used
may implement strict OpenMP 4.0 and later semantics, which are incompatible
in LAMMPS (for maximal compatibility with compiler versions in use).
with the OpenMP 3.1 semantics used in LAMMPS for maximal compatibility
LAMMPS will try to detect compilers that use OpenMP 4.0 semantics and
with compiler versions in use.  If compilation with OpenMP enabled fails
change the directives accordingly, but if your compiler is not
because of your compiler requiring strict OpenMP 4.0 semantic, you can
detected, you may set the define ``-D LAMMPS_OMP_COMPAT=4`` in ``LMP_INC``
change the behvior by adding ``-D LAMMPS_OMP_COMPAT=4`` to the ``LMP_INC``
or the CMake build command.
variable in your makefile, or add it to the command line while configuring
with CMake. CMake will autodetect the suitable setting for the GNU, Clang,
and Intel compilers.


----------
----------


+2 −1
Original line number Original line Diff line number Diff line
@@ -1203,7 +1203,8 @@ char *Info::get_compiler_info()
#if __clang__
#if __clang__
  snprintf(buf,_INFOBUF_SIZE,"Clang C++ %s", __VERSION__);
  snprintf(buf,_INFOBUF_SIZE,"Clang C++ %s", __VERSION__);
#elif __INTEL_COMPILER
#elif __INTEL_COMPILER
  snprintf(buf,_INFOBUF_SIZE,"Intel C++ %s", __VERSION__);
  double version = static_cast<double>(__INTEL_COMPILER)*0.01;
  snprintf(buf,_INFOBUF_SIZE,"Intel C++ %5.2f.%d / %s", version, __INTEL_COMPILER_UPDATE, __VERSION__);
#elif __GNUC__
#elif __GNUC__
  snprintf(buf,_INFOBUF_SIZE,"GNU C++ %s",   __VERSION__);
  snprintf(buf,_INFOBUF_SIZE,"GNU C++ %s",   __VERSION__);
#else
#else
+2 −2
Original line number Original line Diff line number Diff line
@@ -23,8 +23,8 @@
//
//
// To date, most compilers still accept the OpenMP 3.0 form,
// To date, most compilers still accept the OpenMP 3.0 form,
// so this is what LAMMPS primarily uses.  For those compilers
// so this is what LAMMPS primarily uses.  For those compilers
// that strictly implement OpenMP 4.0 (such as GCC 9.0), we
// that strictly implement OpenMP 4.0 (such as GCC 9.0 and later
// give up default(none).
// or Clang 10.0 and later), we give up default(none).
#if LAMMPS_OMP_COMPAT == 4
#if LAMMPS_OMP_COMPAT == 4
#    define LMP_SHARED(...)
#    define LMP_SHARED(...)
#    define LMP_DEFAULT_NONE default(shared)
#    define LMP_DEFAULT_NONE default(shared)