From cfb3efb50fbc6c5aeab3f0c40d983cf7979f1eec Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 16 May 2021 16:10:33 -0400 Subject: [PATCH 01/13] add cmake config option to enable clang-tidy with preferred options --- cmake/CMakeLists.txt | 6 +++++ doc/src/Build_development.rst | 22 ++++++++++++++++++ src/arg_info.cpp | 43 +++++++++++++++++++---------------- src/utils.cpp | 2 +- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b1cbf33c41..81f67fa674 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -104,6 +104,12 @@ endif() option(BUILD_TOOLS "Build and install LAMMPS tools (msi2lmp, binary2txt, chain)" OFF) option(BUILD_LAMMPS_SHELL "Build and install the LAMMPS shell" OFF) +# allow enabling clang-tidy for C++ files +set(ENABLE_CLANG_TIDY OFF CACHE BOOL "Include clang-tidy processing when compiling") +if(ENABLE_CLANG_TIDY) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*-header-filter=.*" CACHE LIST "") +endif() + include(GNUInstallDirs) file(GLOB ALL_SOURCES ${LAMMPS_SOURCE_DIR}/[^.]*.cpp) file(GLOB MAIN_SOURCES ${LAMMPS_SOURCE_DIR}/main.cpp) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 9c5f5ea61e..cc47a617ff 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -28,6 +28,28 @@ variable VERBOSE set to 1: ---------- +.. _clang-tidy + +Enable static code analysis with clang-tidy +------------------------------------------- + +The `clang-tidy tool `_ is a +static code analysis tool to diagnose (and potentially fix) typical +programming errors or coding style violations. It has a modular framework +of tests that can be adjusted to help identifying problems before they +become bugs and also assist in modernizing large code bases (like LAMMPS). +It can be enabled for all C++ code with the following CMake flag + +.. code-block:: bash + + -D ENABLE_CLANG_TIDY=value # value = no (default) or yes + +With this flag enabled all source files will be processed twice, first to +be compiled and then to be analyzed. Please note that the analysis can be +significantly more time consuming than the compilation itself. + +---------- + .. _iwyu_processing: Report missing and unneeded '#include' statements diff --git a/src/arg_info.cpp b/src/arg_info.cpp index ac5e661c0e..682bb592ef 100644 --- a/src/arg_info.cpp +++ b/src/arg_info.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://lammps.sandia.gov/, Sandia National Laboratories @@ -14,8 +13,8 @@ #include "arg_info.h" -#include #include +#include using namespace LAMMPS_NS; @@ -29,46 +28,51 @@ using namespace LAMMPS_NS; * \param arg string with possible reference * \param allowed integer with bitmap of allowed types of references */ -ArgInfo::ArgInfo(const std::string &arg, int allowed) - : type(NONE), dim(0), index1(-1), index2(-1) +ArgInfo::ArgInfo(const std::string &arg, int allowed) : type(NONE), dim(0), index1(-1), index2(-1) { if ((arg.size() > 2) && (arg[1] == '_')) { - if ((arg[0] == 'c') && (allowed & COMPUTE)) type = COMPUTE; - else if ((arg[0] == 'f') && (allowed & FIX)) type = FIX; - else if ((arg[0] == 'v') && (allowed & VARIABLE)) type = VARIABLE; - else if ((arg[0] == 'd') && (allowed & DNAME)) type = DNAME; - else if ((arg[0] == 'i') && (allowed & INAME)) type = INAME; + if ((arg[0] == 'c') && (allowed & COMPUTE)) + type = COMPUTE; + else if ((arg[0] == 'f') && (allowed & FIX)) + type = FIX; + else if ((arg[0] == 'v') && (allowed & VARIABLE)) + type = VARIABLE; + else if ((arg[0] == 'd') && (allowed & DNAME)) + type = DNAME; + else if ((arg[0] == 'i') && (allowed & INAME)) + type = INAME; else { index1 = 0; name = arg; return; } - std::size_t has_idx1 = arg.find('[',2); + std::size_t has_idx1 = arg.find('[', 2); if (has_idx1 != std::string::npos) { - name = arg.substr(2,has_idx1-2); + name = arg.substr(2, has_idx1 - 2); dim = 1; - std::size_t has_idx2 = arg.find('[',has_idx1+1); + std::size_t has_idx2 = arg.find('[', has_idx1 + 1); if (has_idx2 != std::string::npos) { dim = 2; - if (arg[arg.size()-1] != ']') { + if (arg[arg.size() - 1] != ']') { type = UNKNOWN; } else { try { - index2 = std::stoi(arg.substr(has_idx2+1,arg.size()-(has_idx2+2))); + index2 = std::stoi(arg.substr(has_idx2 + 1, arg.size() - (has_idx2 + 2))); } catch (std::invalid_argument &) { type = UNKNOWN; } } - } else has_idx2 = arg.size(); + } else + has_idx2 = arg.size(); - if (arg[has_idx2-1] != ']') { + if (arg[has_idx2 - 1] != ']') { type = UNKNOWN; } else { try { - index1 = std::stoi(arg.substr(has_idx1+1,arg.size()-(has_idx2+2))); + index1 = std::stoi(arg.substr(has_idx1 + 1, arg.size() - (has_idx2 + 2))); } catch (std::invalid_argument &) { type = UNKNOWN; } @@ -97,8 +101,7 @@ ArgInfo::ArgInfo(const std::string &arg, int allowed) char *ArgInfo::copy_name() { - char *dest = new char[name.size()+1]; - strcpy(dest,name.c_str()); + char *dest = new char[name.size() + 1]; + strcpy(dest, name.c_str()); // NOLINT return dest; } - diff --git a/src/utils.cpp b/src/utils.cpp index 992f5cec56..a765ebfc68 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -638,7 +638,7 @@ int utils::expand_args(const char *file, int line, int narg, char **arg, int mod char *utils::strdup(const std::string &text) { char *tmp = new char[text.size() + 1]; - strcpy(tmp, text.c_str()); + strcpy(tmp, text.c_str()); // NOLINT return tmp; } From e584a3b958b1a4385370300810d03896a9ddb627 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 May 2021 16:57:15 -0400 Subject: [PATCH 02/13] Must use explicit scope on virtual functions when called from constructor --- src/SPIN/compute_spin.cpp | 2 +- src/USER-MISC/compute_gyration_shape.cpp | 2 +- src/USER-MISC/compute_gyration_shape_chunk.cpp | 2 +- src/compute_angmom_chunk.cpp | 2 +- src/compute_com_chunk.cpp | 2 +- src/compute_dipole_chunk.cpp | 2 +- src/compute_gyration_chunk.cpp | 2 +- src/compute_inertia_chunk.cpp | 2 +- src/compute_msd_chunk.cpp | 2 +- src/compute_omega_chunk.cpp | 2 +- src/compute_property_chunk.cpp | 2 +- src/compute_temp_chunk.cpp | 2 +- src/compute_torque_chunk.cpp | 2 +- src/compute_vcm_chunk.cpp | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/SPIN/compute_spin.cpp b/src/SPIN/compute_spin.cpp index 6a408b9db1..e1a0211371 100644 --- a/src/SPIN/compute_spin.cpp +++ b/src/SPIN/compute_spin.cpp @@ -58,7 +58,7 @@ ComputeSpin::ComputeSpin(LAMMPS *lmp, int narg, char **arg) : long_spin_flag = 0; precession_spin_flag = 0; - init(); + ComputeSpin::init(); allocate(); diff --git a/src/USER-MISC/compute_gyration_shape.cpp b/src/USER-MISC/compute_gyration_shape.cpp index aa8c038867..c2cc060048 100644 --- a/src/USER-MISC/compute_gyration_shape.cpp +++ b/src/USER-MISC/compute_gyration_shape.cpp @@ -44,7 +44,7 @@ ComputeGyrationShape::ComputeGyrationShape(LAMMPS *lmp, int narg, char **arg) : // ID of compute gyration id_gyration = utils::strdup(arg[3]); - init(); + ComputeGyrationShape::init(); vector = new double[6]; } diff --git a/src/USER-MISC/compute_gyration_shape_chunk.cpp b/src/USER-MISC/compute_gyration_shape_chunk.cpp index 0147ab6590..91c27bf218 100644 --- a/src/USER-MISC/compute_gyration_shape_chunk.cpp +++ b/src/USER-MISC/compute_gyration_shape_chunk.cpp @@ -40,7 +40,7 @@ ComputeGyrationShapeChunk::ComputeGyrationShapeChunk(LAMMPS *lmp, int narg, char // ID of compute gyration id_gyration_chunk = utils::strdup(arg[3]); - init(); + ComputeGyrationShapeChunk::init(); array_flag = 1; size_array_cols = 6; diff --git a/src/compute_angmom_chunk.cpp b/src/compute_angmom_chunk.cpp index 2616e5eec2..a24138f2e1 100644 --- a/src/compute_angmom_chunk.cpp +++ b/src/compute_angmom_chunk.cpp @@ -44,7 +44,7 @@ ComputeAngmomChunk::ComputeAngmomChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeAngmomChunk::init(); // chunk-based data diff --git a/src/compute_com_chunk.cpp b/src/compute_com_chunk.cpp index 4778854f7a..93590b307b 100644 --- a/src/compute_com_chunk.cpp +++ b/src/compute_com_chunk.cpp @@ -46,7 +46,7 @@ ComputeCOMChunk::ComputeCOMChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeCOMChunk::init(); // chunk-based data diff --git a/src/compute_dipole_chunk.cpp b/src/compute_dipole_chunk.cpp index cb0bb8d914..82d0686734 100644 --- a/src/compute_dipole_chunk.cpp +++ b/src/compute_dipole_chunk.cpp @@ -60,7 +60,7 @@ ComputeDipoleChunk::ComputeDipoleChunk(LAMMPS *lmp, int narg, char **arg) : else error->all(FLERR,"Illegal compute dipole/chunk command"); } - init(); + ComputeDipoleChunk::init(); // chunk-based data diff --git a/src/compute_gyration_chunk.cpp b/src/compute_gyration_chunk.cpp index 63ad555080..a0611356af 100644 --- a/src/compute_gyration_chunk.cpp +++ b/src/compute_gyration_chunk.cpp @@ -39,7 +39,7 @@ ComputeGyrationChunk::ComputeGyrationChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeGyrationChunk::init(); // optional args diff --git a/src/compute_inertia_chunk.cpp b/src/compute_inertia_chunk.cpp index 936121ab11..c6d9b487fb 100644 --- a/src/compute_inertia_chunk.cpp +++ b/src/compute_inertia_chunk.cpp @@ -44,7 +44,7 @@ ComputeInertiaChunk::ComputeInertiaChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeInertiaChunk::init(); // chunk-based data diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index f7eb70711c..099f8f6735 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -48,7 +48,7 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); firstflag = 1; - init(); + ComputeMSDChunk::init(); // create a new fix STORE style for reference positions // id = compute-ID + COMPUTE_STORE, fix group = compute group diff --git a/src/compute_omega_chunk.cpp b/src/compute_omega_chunk.cpp index 515d2290c2..8226263eaa 100644 --- a/src/compute_omega_chunk.cpp +++ b/src/compute_omega_chunk.cpp @@ -48,7 +48,7 @@ ComputeOmegaChunk::ComputeOmegaChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeOmegaChunk::init(); // chunk-based data diff --git a/src/compute_property_chunk.cpp b/src/compute_property_chunk.cpp index 352cdb82fc..555af5e119 100644 --- a/src/compute_property_chunk.cpp +++ b/src/compute_property_chunk.cpp @@ -36,7 +36,7 @@ ComputePropertyChunk::ComputePropertyChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputePropertyChunk::init(); // parse values diff --git a/src/compute_temp_chunk.cpp b/src/compute_temp_chunk.cpp index fb4a95e7a4..9d165e54e8 100644 --- a/src/compute_temp_chunk.cpp +++ b/src/compute_temp_chunk.cpp @@ -48,7 +48,7 @@ ComputeTempChunk::ComputeTempChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); biasflag = 0; - init(); + ComputeTempChunk::init(); // optional per-chunk values diff --git a/src/compute_torque_chunk.cpp b/src/compute_torque_chunk.cpp index cebef7eeff..1397afdb9e 100644 --- a/src/compute_torque_chunk.cpp +++ b/src/compute_torque_chunk.cpp @@ -43,7 +43,7 @@ ComputeTorqueChunk::ComputeTorqueChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeTorqueChunk::init(); // chunk-based data diff --git a/src/compute_vcm_chunk.cpp b/src/compute_vcm_chunk.cpp index 0d6ce38b05..b1b584ffe0 100644 --- a/src/compute_vcm_chunk.cpp +++ b/src/compute_vcm_chunk.cpp @@ -44,7 +44,7 @@ ComputeVCMChunk::ComputeVCMChunk(LAMMPS *lmp, int narg, char **arg) : idchunk = utils::strdup(arg[3]); - init(); + ComputeVCMChunk::init(); // chunk-based data From 0b8c82e90643587e24d1e6cde221cca1730c078d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 May 2021 17:56:26 -0400 Subject: [PATCH 03/13] use correct type for clang-tidy command options --- cmake/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 81f67fa674..35fbecf8f3 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -107,7 +107,7 @@ option(BUILD_LAMMPS_SHELL "Build and install the LAMMPS shell" OFF) # allow enabling clang-tidy for C++ files set(ENABLE_CLANG_TIDY OFF CACHE BOOL "Include clang-tidy processing when compiling") if(ENABLE_CLANG_TIDY) - set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*-header-filter=.*" CACHE LIST "") + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*-header-filter=.*" CACHE STRING "") endif() include(GNUInstallDirs) From 0737e014f3fa43958e326b310f698d078cc85177 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 13:51:55 -0400 Subject: [PATCH 04/13] update code owners file --- .github/CODEOWNERS | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8457af3af9..afdac828f8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -13,29 +13,37 @@ lib/kim/* @ellio167 lib/mesont/* @iafoss # whole packages -src/COMPRESS/* @akohlmey +src/COMPRESS/* @rbberger src/GPU/* @ndtrung81 src/KOKKOS/* @stanmoore1 src/KIM/* @ellio167 src/LATTE/* @cnegre src/MESSAGE/* @sjplimp +src/MLIAP/* @athomps +src/SNAP/* @athomps src/SPIN/* @julient31 +src/USER-BROWNIAN/* @samueljmcameron src/USER-CGDNA/* @ohenrich src/USER-CGSDK/* @akohlmey src/USER-COLVARS/* @giacomofiorin +src/USER-FEP/* @agiliopadua +src/USER-HDNNP/* @singraber src/USER-INTEL/* @wmbrownintel src/USER-MANIFOLD/* @Pakketeretet2 +src/USER-MDI/* @taylor-a-barnes src/USER-MEAMC/* @martok src/USER-MESONT/* @iafoss src/USER-MOFFF/* @hheenen src/USER-MOLFILE/* @akohlmey src/USER-NETCDF/* @pastewka +src/USER-PACE/* @yury-lysogorskiy src/USER-PLUMED/* @gtribello src/USER-PHONON/* @lingtikong src/USER-PTM/* @pmla src/USER-OMP/* @akohlmey src/USER-QMMM/* @akohlmey src/USER-REAXC/* @hasanmetin +src/USER-REACTION/* @jrgissing src/USER-SCAFACOS/* @rhalver src/USER-TALLY/* @akohlmey src/USER-UEF/* @danicholson @@ -47,7 +55,6 @@ src/GPU/pair_vashishta_gpu.* @andeplane src/KOKKOS/pair_vashishta_kokkos.* @andeplane src/MANYBODY/pair_vashishta_table.* @andeplane src/MANYBODY/pair_atm.* @sergeylishchuk -src/USER-REACTION/fix_bond_react.* @jrgissing src/USER-MISC/*_grem.* @dstelter92 src/USER-MISC/compute_stress_mop*.* @RomainVermorel @@ -122,6 +129,8 @@ tools/emacs/* @HaoZeke tools/singularity/* @akohlmey @rbberger tools/code_standard/* @rbberger tools/valgrind/* @akohlmey +tools/swig/* @akohlmey +tools/offline/* @rbberger # tests unittest/* @akohlmey @rbberger @@ -130,7 +139,7 @@ unittest/* @akohlmey @rbberger cmake/* @junghans @rbberger cmake/Modules/Packages/USER-COLVARS.cmake @junghans @rbberger @giacomofiorin cmake/Modules/Packages/KIM.cmake @junghans @rbberger @ellio167 -cmake/presets/*.cmake @junghans @rbberger @akohlmey +cmake/presets/*.cmake @akohlmey # python python/* @rbberger @@ -142,6 +151,7 @@ fortran/* @akohlmey doc/utils/*/* @rbberger doc/Makefile @rbberger doc/README @rbberger +examples/plugin/* @akohlmey # for releases src/version.h @sjplimp From 7ba0d553e401bca779c892a0e9930c8df31b9a44 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 18:34:33 -0400 Subject: [PATCH 05/13] correct C++ standard dependency of Kokkos in Package details summary --- doc/src/Packages_details.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/Packages_details.rst b/doc/src/Packages_details.rst index e70c20a60d..6ee9a56513 100644 --- a/doc/src/Packages_details.rst +++ b/doc/src/Packages_details.rst @@ -447,7 +447,7 @@ time via the "-sf kk" or "-suffix kk" :doc:`command-line switches ` :ref:`USER-INTEL `, and :ref:`USER-OMP ` packages, which have styles optimized for CPUs, KNLs, and GPUs. -You must have a C++11 compatible compiler to use this package. +You must have a C++14 compatible compiler to use this package. KOKKOS makes extensive use of advanced C++ features, which can expose compiler bugs, especially when compiling for maximum performance at high optimization levels. Please see the file From c0d13d064c65606410b09ae1aca51bb68cc2ce36 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 18:35:15 -0400 Subject: [PATCH 06/13] since the new Intel compiler is LLVM based the _noalias macro needs to be defined like for GNU and Clang --- src/lmptype.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmptype.h b/src/lmptype.h index 90ba486559..7ebba0ba12 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -252,9 +252,9 @@ union ubuf { // declaration to lift aliasing restrictions -#if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) #define _noalias restrict -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__INTEL_LLVM_COMPILER) #define _noalias __restrict #else #define _noalias From d2fe5e6ec8cb8191c4b18241fe488a8581e257ed Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 18:35:56 -0400 Subject: [PATCH 07/13] include compiler optimization with certain build types when using presets --- cmake/presets/clang.cmake | 10 +++++++++- cmake/presets/intel.cmake | 12 +++++++++++- cmake/presets/oneapi.cmake | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmake/presets/clang.cmake b/cmake/presets/clang.cmake index 47df6dcc6f..9ea077b14c 100644 --- a/cmake/presets/clang.cmake +++ b/cmake/presets/clang.cmake @@ -4,10 +4,18 @@ set(CMAKE_CXX_COMPILER "clang++" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "clang" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) + set(MPI_CXX "clang++" CACHE STRING "" FORCE) set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) -unset(HAVE_OMP_H_INCLUDE CACHE) +unset(HAVE_OMP_H_INCLUDE CACHE) set(OpenMP_C "clang" CACHE STRING "" FORCE) set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "" FORCE) set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE) diff --git a/cmake/presets/intel.cmake b/cmake/presets/intel.cmake index d101a0f699..9baf873608 100644 --- a/cmake/presets/intel.cmake +++ b/cmake/presets/intel.cmake @@ -3,10 +3,20 @@ set(CMAKE_CXX_COMPILER "icpc" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "icc" CACHE STRING "" FORCE) set(CMAKE_Fortran_COMPILER "ifort" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) + set(MPI_CXX "icpc" CACHE STRING "" FORCE) set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) -unset(HAVE_OMP_H_INCLUDE CACHE) +unset(HAVE_OMP_H_INCLUDE CACHE) set(OpenMP_C "icc" CACHE STRING "" FORCE) set(OpenMP_C_FLAGS "-qopenmp" CACHE STRING "" FORCE) set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE) diff --git a/cmake/presets/oneapi.cmake b/cmake/presets/oneapi.cmake index ef04167305..403494c409 100644 --- a/cmake/presets/oneapi.cmake +++ b/cmake/presets/oneapi.cmake @@ -1,12 +1,22 @@ -# preset that will enable the LLVM based Intel compilers with support for MPI and OpenMP (on Linux boxes) +# preset that will enable the LLVM based Intel compilers with support for MPI and OpenMP and Fortran (on Linux boxes) set(CMAKE_CXX_COMPILER "icpx" CACHE STRING "" FORCE) set(CMAKE_C_COMPILER "icx" CACHE STRING "" FORCE) set(CMAKE_Fortran_COMPILER "ifx" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_Fortran_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -g" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Wall -Wextra -g -O2 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) + set(MPI_CXX "icpx" CACHE STRING "" FORCE) set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE) -unset(HAVE_OMP_H_INCLUDE CACHE) +unset(HAVE_OMP_H_INCLUDE CACHE) set(OpenMP_C "icx" CACHE STRING "" FORCE) set(OpenMP_C_FLAGS "-qopenmp" CACHE STRING "" FORCE) set(OpenMP_C_LIB_NAMES "omp" CACHE STRING "" FORCE) From 5c9966989790715fa882aab56d37f771bcf46127 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 11:53:35 -0400 Subject: [PATCH 08/13] silence PGI compiler warnings --- src/RIGID/fix_rigid_nh.cpp | 2 +- src/USER-BROWNIAN/fix_brownian_asphere.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/RIGID/fix_rigid_nh.cpp b/src/RIGID/fix_rigid_nh.cpp index aaaabdddf0..40e3c2d1c3 100644 --- a/src/RIGID/fix_rigid_nh.cpp +++ b/src/RIGID/fix_rigid_nh.cpp @@ -823,7 +823,7 @@ void FixRigidNH::nhc_press_integrate() double tb_mass = kt / (p_freq_max * p_freq_max); q_b[0] = dimension * dimension * tb_mass; - for (int i = 1; i < p_chain; i++) { + for (i = 1; i < p_chain; i++) { q_b[i] = tb_mass; f_eta_b[i] = q_b[i-1] * eta_dot_b[i-1] * eta_dot_b[i-1] - kt; f_eta_b[i] /= q_b[i]; diff --git a/src/USER-BROWNIAN/fix_brownian_asphere.cpp b/src/USER-BROWNIAN/fix_brownian_asphere.cpp index 7f5a09f4a5..7805179f9a 100644 --- a/src/USER-BROWNIAN/fix_brownian_asphere.cpp +++ b/src/USER-BROWNIAN/fix_brownian_asphere.cpp @@ -73,7 +73,6 @@ void FixBrownianAsphere::init() double f_rot[3]; double *quat; - int *ellipsoid = atom->ellipsoid; AtomVecEllipsoid::Bonus *bonus = avec->bonus; double Q[3][3]; From d9bcbe0e421a8dd0b92e19aba1c0c0c8957fbc2a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 19:16:36 -0400 Subject: [PATCH 09/13] fix null pointer dereferences due to typos --- src/force.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/force.cpp b/src/force.cpp index 0f93f2eab1..0a53c462c1 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -449,7 +449,7 @@ Angle *Force::new_angle(const std::string &style, int trysuffix, int &sflag) if (lmp->suffix2) { sflag = 2; - std::string estyle = style + "/" + lmp->suffix; + std::string estyle = style + "/" + lmp->suffix2; if (angle_map->find(estyle) != angle_map->end()) { AngleCreator &angle_creator = (*angle_map)[estyle]; return angle_creator(lmp); @@ -679,7 +679,7 @@ KSpace *Force::new_kspace(const std::string &style, int trysuffix, int &sflag) } if (lmp->suffix2) { - sflag = 1; + sflag = 2; std::string estyle = style + "/" + lmp->suffix2; if (kspace_map->find(estyle) != kspace_map->end()) { KSpaceCreator &kspace_creator = (*kspace_map)[estyle]; From bf2d1db49da1426607692d7eb4c2e29e622b8911 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 22 May 2021 21:28:39 -0400 Subject: [PATCH 10/13] PGI compiler can handle restrict and aligned attributes --- src/lmptype.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lmptype.h b/src/lmptype.h index 7ebba0ba12..9e25a00f18 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -244,7 +244,7 @@ union ubuf { #if defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER) #define _alignvar(expr, val) __declspec(align(val)) expr -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__PGI) #define _alignvar(expr, val) expr __attribute((aligned(val))) #else #define _alignvar(expr, val) expr @@ -252,7 +252,7 @@ union ubuf { // declaration to lift aliasing restrictions -#if defined(__INTEL_COMPILER) +#if defined(__INTEL_COMPILER) || defined(__PGI) #define _noalias restrict #elif defined(__GNUC__) || defined(__INTEL_LLVM_COMPILER) #define _noalias __restrict From d5f62a22b803acd05370df3d9abbddd1c9491574 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 23 May 2021 00:53:40 -0400 Subject: [PATCH 11/13] 64-bit integers are "long long" on windows, not "long" (which is 32-bit) --- src/PYTHON/python_compat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PYTHON/python_compat.h b/src/PYTHON/python_compat.h index 9263cd3e95..661a6aa23c 100644 --- a/src/PYTHON/python_compat.h +++ b/src/PYTHON/python_compat.h @@ -18,15 +18,31 @@ // Wrap API changes between Python 2 and 3 using macros #if PY_MAJOR_VERSION == 2 +#if defined(_MSC_VER) || defined(__MINGW32__) +#define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) +#else #define PY_INT_FROM_LONG(X) PyInt_FromLong(X) +#endif +#if defined(_MSC_VER) || defined(__MINGW32__) +#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X) +#else #define PY_INT_AS_LONG(X) PyInt_AsLong(X) +#endif #define PY_STRING_FROM_STRING(X) PyString_FromString(X) #define PY_VOID_POINTER(X) PyCObject_FromVoidPtr((void *) X, nullptr) #define PY_STRING_AS_STRING(X) PyString_AsString(X) #elif PY_MAJOR_VERSION == 3 +#if defined(_MSC_VER) || defined(__MINGW32__) +#define PY_INT_FROM_LONG(X) PyLong_FromLongLong(X) +#else #define PY_INT_FROM_LONG(X) PyLong_FromLong(X) +#endif +#if defined(_MSC_VER) || defined(__MINGW32__) +#define PY_INT_AS_LONG(X) PyLong_AsLongLong(X) +#else #define PY_INT_AS_LONG(X) PyLong_AsLong(X) +#endif #define PY_STRING_FROM_STRING(X) PyUnicode_FromString(X) #define PY_VOID_POINTER(X) PyCapsule_New((void *) X, nullptr, nullptr) #define PY_STRING_AS_STRING(X) PyUnicode_AsUTF8(X) From ba854ec7c3980890a9b4a601dbb212a60dcd9866 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 23 May 2021 01:46:14 -0400 Subject: [PATCH 12/13] changes required to cross-compile unit tests for windows --- cmake/Modules/YAML.cmake | 18 +++++++++++++++--- unittest/cplusplus/test_lammps_class.cpp | 4 ++++ unittest/force-styles/CMakeLists.txt | 2 +- unittest/fortran/CMakeLists.txt | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/YAML.cmake b/cmake/Modules/YAML.cmake index c50773568c..77ee804111 100644 --- a/cmake/Modules/YAML.cmake +++ b/cmake/Modules/YAML.cmake @@ -6,15 +6,27 @@ set(YAML_MD5 "bb15429d8fb787e7d3f1c83ae129a999" CACHE STRING "MD5 checksum of li mark_as_advanced(YAML_URL) mark_as_advanced(YAML_MD5) +# support cross-compilation to windows +if(CMAKE_CROSSCOMPILING AND (CMAKE_SYSTEM_NAME STREQUAL "Windows")) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86") + set(YAML_CROSS_HOST --host=i686-mingw64) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(YAML_CROSS_HOST --host=x86_64-mingw64) + else() + message(FATAL_ERROR "Unsupported cross-compilation " + " for ${CMAKE_SYSTEM_NAME}/${CMAKE_SYSTEM_PROCESSOR}" + " on ${CMAKE_HOST_SYSTEM}/${CMAKE_HOST_SYSTEM_PROCESSOR}") + endif() +endif() + ExternalProject_Add(libyaml URL ${YAML_URL} URL_MD5 ${YAML_MD5} SOURCE_DIR "${CMAKE_BINARY_DIR}/yaml-src" BINARY_DIR "${CMAKE_BINARY_DIR}/yaml-build" CONFIGURE_COMMAND /configure ${CONFIGURE_REQUEST_PIC} - CXX=${CMAKE_CXX_COMPILER} - CC=${CMAKE_C_COMPILER} - --prefix= --disable-shared + CXX=${CMAKE_CXX_COMPILER} CC=${CMAKE_C_COMPILER} + --prefix= --disable-shared ${YAML_CROSS_HOST} BUILD_BYPRODUCTS /lib/libyaml${CMAKE_STATIC_LIBRARY_SUFFIX} TEST_COMMAND "") diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 04ad403db6..5288cfc2b6 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -362,7 +362,11 @@ TEST(LAMMPS_init, NoOpenMP) FILE *fp = fopen("in.lammps_class_noomp", "w"); fputs("\n", fp); fclose(fp); +#if defined(__WIN32) + _putenv("OMP_NUM_THREADS"); +#else unsetenv("OMP_NUM_THREADS"); +#endif const char *args[] = {"LAMMPS_init", "-in", "in.lammps_class_noomp", "-log", "none", "-nocite"}; char **argv = (char **)args; diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 2c0977397a..86b0f4fdaf 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -26,7 +26,7 @@ set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) add_library(style_tests STATIC yaml_writer.cpp error_stats.cpp test_config_reader.cpp test_main.cpp) target_compile_definitions(style_tests PRIVATE -DTEST_INPUT_FOLDER=${TEST_INPUT_FOLDER}) target_include_directories(style_tests PRIVATE ${LAMMPS_SOURCE_DIR}) -target_link_libraries(style_tests PUBLIC GTest::GTest GTest::GMock Yaml::Yaml) +target_link_libraries(style_tests PUBLIC GTest::GTest GTest::GMock Yaml::Yaml lammps) if(BUILD_MPI) target_link_libraries(style_tests PUBLIC MPI::MPI_CXX) else() diff --git a/unittest/fortran/CMakeLists.txt b/unittest/fortran/CMakeLists.txt index fe63802e8b..9bd6c8f419 100644 --- a/unittest/fortran/CMakeLists.txt +++ b/unittest/fortran/CMakeLists.txt @@ -7,6 +7,7 @@ endif() include(CheckLanguage) check_language(Fortran) if(CMAKE_Fortran_COMPILER) + enable_language(C) enable_language(Fortran) get_filename_component(LAMMPS_FORTRAN_MODULE ${LAMMPS_SOURCE_DIR}/../fortran/lammps.f90 ABSOLUTE) if(BUILD_MPI) From 53164321c901289a2f7f3d9157c97904f779f669 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 23 May 2021 03:37:58 -0400 Subject: [PATCH 13/13] silence CMake warnings with CMake 3.19 and later when cross compiling --- cmake/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b1cbf33c41..ecc5a84352 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -7,6 +7,11 @@ cmake_minimum_required(VERSION 3.10) if(POLICY CMP0074) cmake_policy(SET CMP0074 NEW) endif() +# set policy to silence warnings about missing executable permissions in +# pythonx.y-config when cross-compiling. review occasionally if it may be set to NEW +if (POLICY CMP0109) + cmake_policy(SET CMP0109 OLD) +endif() ######################################## project(lammps CXX)