Unverified Commit 8b1c6cb2 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

Merge branch 'omp4-compat' into correct-kokkos-docs

parents 15314e3c 9cf6c72a
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -240,16 +240,7 @@ if(OpenMP_FOUND)
  endif()
endif()

# TODO: this is a temporary workaround until a better solution is found. AK 2019-05-30
# GNU GCC 9.x uses settings incompatible with our use of 'default(none)' in OpenMP pragmas
# where we assume older GCC semantics. For the time being, we disable OpenMP by default
# for GCC 9.x and beyond. People may manually turn it on, but need to run the script
# src/USER-OMP/hack_openmp_for_pgi_gcc9.sh on all sources to make it compatible with gcc 9.
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.99.9))
  option(BUILD_OMP "Build with OpenMP support" OFF)
else()
option(BUILD_OMP "Build with OpenMP support" ${BUILD_OMP_DEFAULT})
endif()

if(BUILD_OMP)
  find_package(OpenMP REQUIRED)
@@ -257,6 +248,17 @@ if(BUILD_OMP)
  if(NOT HAVE_OMP_H_INCLUDE)
    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)) 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()
    target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=3)
  endif()
  target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX)
endif()

+10 −0
Original line number Diff line number Diff line
@@ -264,6 +264,16 @@ cmake -C ../cmake/presets/all_on.cmake -C ../cmake/presets/nolib.cmake -D PKG_GP
  </dl>
  </td>
</tr>
<tr>
  <td><code>LAMMPS_OMP_COMPAT</code></td>
  <td>Workaround for backwards-incompatible changes regarding predetermined sharing modes in OpenMP 4.x.  A value of 3 or 4 should be used, reflecting the version of the OpenMP spec that is implemented by the compiler.</td>
  <td>
  <dl>
    <dt><code>3</code> (default except for known OMP 4.0 compilers)</dt>
    <dt><code>4</code></dt>
  </dl>
  </td>
</tr>
<tr>
  <td><code>LAMMPS_MEMALIGN</code></td>
  <td>controls the alignment of blocks of memory allocated by LAMMPS</td>
+9 −8
Original line number Diff line number Diff line
@@ -142,14 +142,15 @@ please refer to its documentation.
**OpenMP Compiler compatibility info**\ :

Some compilers do not fully support the ``default(none)`` directive
and others (e.g. GCC version 9 and beyond) may implement OpenMP 4.0
semantics, which are incompatible with the OpenMP 3.1 semantics used
in LAMMPS (for maximal compatibility with compiler versions in use).
In those case, all ``default(none)`` directives (which aid in detecting
incorrect and unwanted sharing) can be replaced with ``default(shared)``
while dropping all ``shared()`` directives. The script
'src/USER-OMP/hack_openmp_for_pgi_gcc9.sh' can be used to automate
this conversion.
and others (e.g. GCC version 9 and beyond, Clang version 10 and later)
may implement strict OpenMP 4.0 and later semantics, which are incompatible
with the OpenMP 3.1 semantics used in LAMMPS for maximal compatibility
with compiler versions in use.  If compilation with OpenMP enabled fails
because of your compiler requiring strict OpenMP 4.0 semantic, you can
change the behavior by adding ``-D LAMMPS_OMP_COMPAT=4`` to the ``LMP_INC``
variable in your makefile, or add it to the command line while configuring
with CMake. CMake will detect the suitable setting for the GNU, Clang,
and Intel compilers.

----------

+3 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
   Contributing author: Paul Coffman (IBM)
------------------------------------------------------------------------- */

#include "omp_compat.h"
#include "dump_atom_mpiio.h"
#include <cmath>
#include <cstdlib>
@@ -587,7 +588,7 @@ int DumpAtomMPIIO::convert_image_omp(int n, double *mybuf)
    mpifh_buffer_line_per_thread[i] = (char *) malloc(DUMP_BUF_CHUNK_SIZE * sizeof(char));
    mpifh_buffer_line_per_thread[i][0] = '\0';

#pragma omp parallel default(none) shared(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
    {
      int tid = omp_get_thread_num();
      int m=0;
@@ -677,7 +678,7 @@ int DumpAtomMPIIO::convert_noimage_omp(int n, double *mybuf)
    mpifh_buffer_line_per_thread[i] = (char *) malloc(DUMP_BUF_CHUNK_SIZE * sizeof(char));
    mpifh_buffer_line_per_thread[i][0] = '\0';

#pragma omp parallel default(none) shared(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
    {
      int tid = omp_get_thread_num();
      int m=0;
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
   Contributing author: Paul Coffman (IBM)
------------------------------------------------------------------------- */

#include "omp_compat.h"
#include "dump_cfg_mpiio.h"
#include <cmath>
#include <cstdlib>
@@ -365,7 +366,7 @@ int DumpCFGMPIIO::convert_string_omp(int n, double *mybuf)
    mpifh_buffer_line_per_thread[i] = (char *) malloc(DUMP_BUF_CHUNK_SIZE * sizeof(char));
    mpifh_buffer_line_per_thread[i][0] = '\0';

#pragma omp parallel default(none) shared(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
#pragma omp parallel LMP_DEFAULT_NONE LMP_SHARED(bufOffset, bufRange, bufLength, mpifhStringCountPerThread, mpifh_buffer_line_per_thread, mybuf)
    {
      int tid = omp_get_thread_num();
      int m=0;
Loading