diff --git a/doc/src/Build_basics.rst b/doc/src/Build_basics.rst index 3b20209e5c..d364382591 100644 --- a/doc/src/Build_basics.rst +++ b/doc/src/Build_basics.rst @@ -159,11 +159,11 @@ 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 +because of your compiler requiring strict OpenMP 4.0 semantics, 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. +while configuring with CMake. LAMMPS will autodetect a suitable setting +for most GNU, Clang, and Intel compilers. ---------- diff --git a/src/omp_compat.h b/src/omp_compat.h index d80d6f6f7f..366dd9371c 100644 --- a/src/omp_compat.h +++ b/src/omp_compat.h @@ -25,11 +25,30 @@ // so this is what LAMMPS primarily uses. For those compilers // 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) -#else -# define LMP_SHARED(...) shared(__VA_ARGS__) -# define LMP_DEFAULT_NONE default(none) + +// autodetect OpenMP compatibility if not explicitly set + +#ifndef LAMMPS_OMP_COMPAT +# if defined(__INTEL_COMPILER) +# if __INTEL_COMPILER > 18 +# define LAMMPS_OMP_COMPAT 4 +# endif +# elif defined(__clang__) +# if __clang_major__ >= 10 +# define LAMMPS_OMP_COMPAT 4 +# endif +# elif defined(__GNUC__) +# if __GNUC__ >= 9 +# define LAMMPS_OMP_COMPAT 4 +# endif +# endif +#endif + +#if LAMMPS_OMP_COMPAT == 4 +# define LMP_SHARED(...) +# define LMP_DEFAULT_NONE default(shared) +#else +# define LMP_SHARED(...) shared(__VA_ARGS__) +# define LMP_DEFAULT_NONE default(none) #endif