From 7aec563b868e0ec03385ee68ea67101b47d568ce Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2023 17:02:48 -0400 Subject: [PATCH 01/17] building lammps-shell requires pkg-config --- cmake/Modules/Tools.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/Modules/Tools.cmake b/cmake/Modules/Tools.cmake index 285c5f2405..148fb6440e 100644 --- a/cmake/Modules/Tools.cmake +++ b/cmake/Modules/Tools.cmake @@ -37,7 +37,11 @@ if(BUILD_TOOLS) add_subdirectory(${LAMMPS_TOOLS_DIR}/phonon ${CMAKE_BINARY_DIR}/phana_build) endif() +find_package(PkgConfig QUIET) if(BUILD_LAMMPS_SHELL) + if(NOT PkgConfig_FOUND) + message(FATAL_ERROR "Must have pkg-config installed for building LAMMPS shell") + endif() find_package(PkgConfig REQUIRED) pkg_check_modules(READLINE IMPORTED_TARGET REQUIRED readline) if(NOT LAMMPS_EXCEPTIONS) From 66403c93ad51c7fa3778ddd4bef70ba966b3f706 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 18 Jul 2023 18:55:27 -0400 Subject: [PATCH 02/17] add preset and support for building serial multi-arch macOS executables --- cmake/presets/macos-multiarch.cmake | 14 ++++++++++++++ tools/phonon/CMakeLists.txt | 3 +++ 2 files changed, 17 insertions(+) create mode 100644 cmake/presets/macos-multiarch.cmake diff --git a/cmake/presets/macos-multiarch.cmake b/cmake/presets/macos-multiarch.cmake new file mode 100644 index 0000000000..09006e9958 --- /dev/null +++ b/cmake/presets/macos-multiarch.cmake @@ -0,0 +1,14 @@ +# preset that will build portable multi-arch binaries on macOS without MPI and OpenMP + +set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE) +set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0 CACHE STRING "" FORCE) +set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE) + +set(CMAKE_CXX_COMPILER "clang++" CACHE STRING "" FORCE) +set(CMAKE_C_COMPILER "clang" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) +set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE) + +set(BUILD_MPI FALSE CACHE BOOL "" FORCE) +set(BUILD_OMP FALSE CACHE BOOL "" FORCE) +set(BUILD_SHARED_LIBS FALSE CACHE BOOL "" FORCE) diff --git a/tools/phonon/CMakeLists.txt b/tools/phonon/CMakeLists.txt index 60da1cc79f..f3c3b8386c 100644 --- a/tools/phonon/CMakeLists.txt +++ b/tools/phonon/CMakeLists.txt @@ -85,6 +85,7 @@ if(USE_SPGLIB) include(LAMMPSUtils) GetFallbackURL(SPGLIB_URL SPGLIB_FALLBACK) + string(REPLACE ";" "$" CMAKE_OSX_ARCHITECTURES_ "${CMAKE_OSX_ARCHITECTURES}") include(ExternalProject) ExternalProject_Add(spglib_build URL ${SPGLIB_URL} ${SPGLIB_FALLBACK} @@ -96,6 +97,8 @@ if(USE_SPGLIB) -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} UPDATE_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.spglib ${CMAKE_CURRENT_BINARY_DIR}/spglib_build_ext/src/spglib_build/CMakeLists.txt INSTALL_COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/spglib_build_ext/src/spglib_build-build --target install BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/spglib_build_ext/lib/${CMAKE_STATIC_LIBRARY_PREFIX}symspg${CMAKE_STATIC_LIBRARY_SUFFIX}" From f26064d9a5da46b48a6c6cb55fbe6fdc475e5d25 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 Jul 2023 17:46:21 -0400 Subject: [PATCH 03/17] also install the bench folder into ${datadir} --- cmake/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 88b7ec422e..f5b04e2165 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -795,9 +795,11 @@ include(Tools) include(Documentation) ############################################################################### -# Install potential and force field files in data directory +# Install bench, potential and force field files in data directory ############################################################################### set(LAMMPS_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}/lammps) + +install(DIRECTORY ${LAMMPS_DIR}/bench DESTINATION ${LAMMPS_INSTALL_DATADIR}) install(DIRECTORY ${LAMMPS_POTENTIALS_DIR} DESTINATION ${LAMMPS_INSTALL_DATADIR}) if(BUILD_TOOLS) install(DIRECTORY ${LAMMPS_TOOLS_DIR}/msi2lmp/frc_files DESTINATION ${LAMMPS_INSTALL_DATADIR}) From c42ec8a647838eceebe09e4c8b73fe33e8b51918 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 19 Jul 2023 18:14:03 -0400 Subject: [PATCH 04/17] create toplevel README file when building for static Linux or macOS multiarch --- cmake/CMakeLists.txt | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index f5b04e2165..a4f8c58132 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -808,10 +808,25 @@ endif() configure_file(etc/profile.d/lammps.sh.in ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.sh @ONLY) configure_file(etc/profile.d/lammps.csh.in ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.csh @ONLY) install( - FILES ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.sh - ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.csh - DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/profile.d -) + FILES ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.sh ${CMAKE_BINARY_DIR}/etc/profile.d/lammps.csh + DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/profile.d) + +if(CMAKE_SYSTEM_NAME STREQUAL "LinuxMUSL") + file(WRITE ${CMAKE_BINARY_DIR}/README.txt + "Statically linked, portable, serial LAMMPS binary archive for x86_64 Linux\n\n") +endif() +if(APPLE AND CMAKE_OSX_ARCHITECTURES) + file(WRITE ${CMAKE_BINARY_DIR}/README.txt + "Multi-arch, serial LAMMPS binary archive for macOS 11 (Big Sur) and later\n\n") +endif() +if((CMAKE_SYSTEM_NAME STREQUAL "LinuxMUSL") OR (APPLE AND CMAKE_OSX_ARCHITECTURES)) + file(APPEND ${CMAKE_BINARY_DIR}/README.txt + "Executables are in 'bin', potential files in 'share/lammps/potentials',\n") + file(APPEND ${CMAKE_BINARY_DIR}/README.txt + "benchmark and simple input examples are in 'share/lammps/bench'.\n") + install(FILES ${CMAKE_BINARY_DIR}/README.txt + DESTINATION ${CMAKE_INSTALL_PREFIX}) +endif() ############################################################################### # Install LAMMPS lib and python module into site-packages folder with From e299fa9aab4877f1e6b301b96edc9feec53df552 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 20 Jul 2023 14:00:21 -0400 Subject: [PATCH 05/17] add option to skip building for multiple GPU archs --- cmake/Modules/Packages/GPU.cmake | 104 ++++++++++++++++--------------- doc/src/Build_extras.rst | 68 +++++++++++--------- 2 files changed, 93 insertions(+), 79 deletions(-) diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index 4a70eb7a1e..99321fce9f 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -64,6 +64,8 @@ if(GPU_API STREQUAL "CUDA") endif() set(GPU_CUDA_MPS_FLAGS "-DCUDA_MPS_SUPPORT") endif() + option(CUDA_BUILD_MULTIARCH "Enable building CUDA kernels for all supported GPU architectures" ON) + mark_as_advanced(GPU_BUILD_MULTIARCH) set(GPU_ARCH "sm_50" CACHE STRING "LAMMPS GPU CUDA SM primary architecture (e.g. sm_60)") @@ -93,56 +95,58 @@ if(GPU_API STREQUAL "CUDA") # --arch translates directly instead of JIT, so this should be for the preferred or most common architecture set(GPU_CUDA_GENCODE "-arch=${GPU_ARCH}") - # apply the following to build "fat" CUDA binaries only for known CUDA toolkits since version 8.0 - # only the Kepler achitecture and beyond is supported - # comparison chart according to: https://en.wikipedia.org/wiki/CUDA#GPUs_supported - if(CUDA_VERSION VERSION_LESS 8.0) - message(FATAL_ERROR "CUDA Toolkit version 8.0 or later is required") - elseif(CUDA_VERSION VERSION_GREATER_EQUAL "13.0") - message(WARNING "Untested CUDA Toolkit version ${CUDA_VERSION}. Use at your own risk") - set(GPU_CUDA_GENCODE "-arch=all") - elseif(CUDA_VERSION VERSION_GREATER_EQUAL "12.0") - set(GPU_CUDA_GENCODE "-arch=all") - else() - # Kepler (GPU Arch 3.0) is supported by CUDA 5 to CUDA 10.2 - if((CUDA_VERSION VERSION_GREATER_EQUAL "5.0") AND (CUDA_VERSION VERSION_LESS "11.0")) - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_30,code=[sm_30,compute_30] ") - endif() - # Kepler (GPU Arch 3.5) is supported by CUDA 5 to CUDA 11 - if((CUDA_VERSION VERSION_GREATER_EQUAL "5.0") AND (CUDA_VERSION VERSION_LESS "12.0")) - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_35,code=[sm_35,compute_35]") - endif() - # Maxwell (GPU Arch 5.x) is supported by CUDA 6 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "6.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_50,code=[sm_50,compute_50] -gencode arch=compute_52,code=[sm_52,compute_52]") - endif() - # Pascal (GPU Arch 6.x) is supported by CUDA 8 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "8.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_60,code=[sm_60,compute_60] -gencode arch=compute_61,code=[sm_61,compute_61]") - endif() - # Volta (GPU Arch 7.0) is supported by CUDA 9 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_70,code=[sm_70,compute_70]") - endif() - # Turing (GPU Arch 7.5) is supported by CUDA 10 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_75,code=[sm_75,compute_75]") - endif() - # Ampere (GPU Arch 8.0) is supported by CUDA 11 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_80,code=[sm_80,compute_80]") - endif() - # Ampere (GPU Arch 8.6) is supported by CUDA 11.1 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_86,code=[sm_86,compute_86]") - endif() - # Lovelace (GPU Arch 8.9) is supported by CUDA 11.8 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.8") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_90,code=[sm_90,compute_90]") - endif() - # Hopper (GPU Arch 9.0) is supported by CUDA 12.0 and later - if(CUDA_VERSION VERSION_GREATER_EQUAL "12.0") - string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_90,code=[sm_90,compute_90]") + if(CUDA_BUILD_MULTIARCH) + # apply the following to build "fat" CUDA binaries only for known CUDA toolkits since version 8.0 + # only the Kepler achitecture and beyond is supported + # comparison chart according to: https://en.wikipedia.org/wiki/CUDA#GPUs_supported + if(CUDA_VERSION VERSION_LESS 8.0) + message(FATAL_ERROR "CUDA Toolkit version 8.0 or later is required") + elseif(CUDA_VERSION VERSION_GREATER_EQUAL "13.0") + message(WARNING "Untested CUDA Toolkit version ${CUDA_VERSION}. Use at your own risk") + set(GPU_CUDA_GENCODE "-arch=all") + elseif(CUDA_VERSION VERSION_GREATER_EQUAL "12.0") + set(GPU_CUDA_GENCODE "-arch=all") + else() + # Kepler (GPU Arch 3.0) is supported by CUDA 5 to CUDA 10.2 + if((CUDA_VERSION VERSION_GREATER_EQUAL "5.0") AND (CUDA_VERSION VERSION_LESS "11.0")) + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_30,code=[sm_30,compute_30] ") + endif() + # Kepler (GPU Arch 3.5) is supported by CUDA 5 to CUDA 11 + if((CUDA_VERSION VERSION_GREATER_EQUAL "5.0") AND (CUDA_VERSION VERSION_LESS "12.0")) + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_35,code=[sm_35,compute_35]") + endif() + # Maxwell (GPU Arch 5.x) is supported by CUDA 6 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "6.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_50,code=[sm_50,compute_50] -gencode arch=compute_52,code=[sm_52,compute_52]") + endif() + # Pascal (GPU Arch 6.x) is supported by CUDA 8 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "8.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_60,code=[sm_60,compute_60] -gencode arch=compute_61,code=[sm_61,compute_61]") + endif() + # Volta (GPU Arch 7.0) is supported by CUDA 9 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "9.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_70,code=[sm_70,compute_70]") + endif() + # Turing (GPU Arch 7.5) is supported by CUDA 10 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_75,code=[sm_75,compute_75]") + endif() + # Ampere (GPU Arch 8.0) is supported by CUDA 11 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_80,code=[sm_80,compute_80]") + endif() + # Ampere (GPU Arch 8.6) is supported by CUDA 11.1 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_86,code=[sm_86,compute_86]") + endif() + # Lovelace (GPU Arch 8.9) is supported by CUDA 11.8 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "11.8") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_90,code=[sm_90,compute_90]") + endif() + # Hopper (GPU Arch 9.0) is supported by CUDA 12.0 and later + if(CUDA_VERSION VERSION_GREATER_EQUAL "12.0") + string(APPEND GPU_CUDA_GENCODE " -gencode arch=compute_90,code=[sm_90,compute_90]") + endif() endif() endif() diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 0ecf54f744..692ab52e1d 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -140,6 +140,8 @@ CMake build # value = yes or no (default) -D CUDA_MPS_SUPPORT=value # enables some tweaks required to run with active nvidia-cuda-mps daemon # value = yes or no (default) + -D CUDA_BUILD_MULTIARCH=value # enables building CUDA kernels for all supported GPU architectures + # value = yes (default) or no -D USE_STATIC_OPENCL_LOADER=value # downloads/includes OpenCL ICD loader library, no local OpenCL headers/libs needed # value = yes (default) or no @@ -158,41 +160,49 @@ CMake build A more detailed list can be found, for example, at `Wikipedia's CUDA article `_ -CMake can detect which version of the CUDA toolkit is used and thus will try -to include support for **all** major GPU architectures supported by this toolkit. -Thus the GPU_ARCH setting is merely an optimization, to have code for -the preferred GPU architecture directly included rather than having to wait -for the JIT compiler of the CUDA driver to translate it. +CMake can detect which version of the CUDA toolkit is used and thus will +try to include support for **all** major GPU architectures supported by +this toolkit. Thus the GPU_ARCH setting is merely an optimization, to +have code for the preferred GPU architecture directly included rather +than having to wait for the JIT compiler of the CUDA driver to translate +it. This behavior can be turned off (e.g. to speed up compilation) by +setting code:`CUDA_ENABLE_MULTIARCH` to code:`no`. -When compiling for CUDA or HIP with CUDA, version 8.0 or later of the CUDA toolkit -is required and a GPU architecture of Kepler or later, which must *also* be -supported by the CUDA toolkit in use **and** the CUDA driver in use. -When compiling for OpenCL, OpenCL version 1.2 or later is required and the -GPU must be supported by the GPU driver and OpenCL runtime bundled with the driver. +When compiling for CUDA or HIP with CUDA, version 8.0 or later of the +CUDA toolkit is required and a GPU architecture of Kepler or later, +which must *also* be supported by the CUDA toolkit in use **and** the +CUDA driver in use. When compiling for OpenCL, OpenCL version 1.2 or +later is required and the GPU must be supported by the GPU driver and +OpenCL runtime bundled with the driver. -When building with CMake, you **must NOT** build the GPU library in ``lib/gpu`` -using the traditional build procedure. CMake will detect files generated by that -process and will terminate with an error and a suggestion for how to remove them. +When building with CMake, you **must NOT** build the GPU library in +``lib/gpu`` using the traditional build procedure. CMake will detect +files generated by that process and will terminate with an error and a +suggestion for how to remove them. -If you are compiling for OpenCL, the default setting is to download, build, and -link with a static OpenCL ICD loader library and standard OpenCL headers. This -way no local OpenCL development headers or library needs to be present and only -OpenCL compatible drivers need to be installed to use OpenCL. If this is not -desired, you can set :code:`USE_STATIC_OPENCL_LOADER` to :code:`no`. +If you are compiling for OpenCL, the default setting is to download, +build, and link with a static OpenCL ICD loader library and standard +OpenCL headers. This way no local OpenCL development headers or library +needs to be present and only OpenCL compatible drivers need to be +installed to use OpenCL. If this is not desired, you can set +:code:`USE_STATIC_OPENCL_LOADER` to :code:`no`. -The GPU library has some multi-thread support using OpenMP. If LAMMPS is built -with ``-D BUILD_OMP=on`` this will also be enabled. +The GPU library has some multi-thread support using OpenMP. If LAMMPS +is built with ``-D BUILD_OMP=on`` this will also be enabled. -If you are compiling with HIP, note that before running CMake you will have to -set appropriate environment variables. Some variables such as -:code:`HCC_AMDGPU_TARGET` (for ROCm <= 4.0) or :code:`CUDA_PATH` are necessary for :code:`hipcc` -and the linker to work correctly. +If you are compiling with HIP, note that before running CMake you will +have to set appropriate environment variables. Some variables such as +:code:`HCC_AMDGPU_TARGET` (for ROCm <= 4.0) or :code:`CUDA_PATH` are +necessary for :code:`hipcc` and the linker to work correctly. -Using CHIP-SPV implementation of HIP is now supported. It allows one to run HIP -code on Intel GPUs via the OpenCL or Level Zero backends. To use CHIP-SPV, you must -set :code:`-DHIP_USE_DEVICE_SORT=OFF` in your CMake command line as CHIP-SPV does not -yet support hipCUB. The use of HIP for Intel GPUs is still experimental so you -should only use this option in preparations to run on Aurora system at ANL. +.. versionadded:: 3Aug2022 + +Using the CHIP-SPV implementation of HIP is supported. It allows one to +run HIP code on Intel GPUs via the OpenCL or Level Zero backends. To use +CHIP-SPV, you must set :code:`-DHIP_USE_DEVICE_SORT=OFF` in your CMake +command line as CHIP-SPV does not yet support hipCUB. As of Summer 2022, +the use of HIP for Intel GPUs is experimental. You should only use this +option in preparations to run on Aurora system at Argonne. .. code:: bash From c441a999f1ea4867a9f7f0e65586cbb6d099dc15 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 20 Jul 2023 17:59:40 -0400 Subject: [PATCH 06/17] fix typos --- doc/src/Build_extras.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 692ab52e1d..c1ab6ecb87 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -166,7 +166,7 @@ this toolkit. Thus the GPU_ARCH setting is merely an optimization, to have code for the preferred GPU architecture directly included rather than having to wait for the JIT compiler of the CUDA driver to translate it. This behavior can be turned off (e.g. to speed up compilation) by -setting code:`CUDA_ENABLE_MULTIARCH` to code:`no`. +setting :code:`CUDA_ENABLE_MULTIARCH` to :code:`no`. When compiling for CUDA or HIP with CUDA, version 8.0 or later of the CUDA toolkit is required and a GPU architecture of Kepler or later, From cccc362b3fc6aff2ab630c1cac0cac55389178d4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 21 Jul 2023 11:28:09 -0400 Subject: [PATCH 07/17] improve error messages --- src/thermo.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/thermo.cpp b/src/thermo.cpp index 6122edec83..f121c95000 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -1228,13 +1228,13 @@ int Thermo::evaluate_keyword(const std::string &word, double *answer) } else if (word == "elapsed") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword elapsed cannot be used between runs"); compute_elapsed(); dvalue = bivalue; } else if (word == "elaplong") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword elaplong cannot be used between runs"); compute_elapsed_long(); dvalue = bivalue; @@ -1246,22 +1246,22 @@ int Thermo::evaluate_keyword(const std::string &word, double *answer) } else if (word == "cpu") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cpu cannot be used between runs"); compute_cpu(); } else if (word == "tpcpu") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword tpcpu cannot be used between runs"); compute_tpcpu(); } else if (word == "spcpu") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword spcpu cannot be used between runs"); compute_spcpu(); } else if (word == "cpuremain") { if (update->whichflag == 0) - error->all(FLERR, "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cpuremain cannot be used between runs"); compute_cpuremain(); } else if (word == "part") { @@ -1350,7 +1350,7 @@ int Thermo::evaluate_keyword(const std::string &word, double *answer) } else if (word == "etail") { if (update->eflag_global != update->ntimestep) - error->all(FLERR, "Energy was not tallied on needed timestep"); + error->all(FLERR, "Energy was not tallied on needed timestep for thermo keyword etail"); compute_etail(); } else if (word == "enthalpy") { From 21d4be321ae59506dc02652068393e098f2cb3dc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 21 Jul 2023 12:12:53 -0400 Subject: [PATCH 08/17] must lower test epsilon with single precision FFTs and pppm used --- unittest/force-styles/CMakeLists.txt | 3 +++ unittest/force-styles/test_fix_timestep.cpp | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index dfffdfea0c..ac5cd7dfd7 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -199,6 +199,9 @@ add_executable(test_fix_timestep test_fix_timestep.cpp) if(NOT BUILD_SHARED_LIBS) target_compile_definitions(test_fix_timestep PRIVATE USING_STATIC_LIBS=1) endif() +if(FFT_SINGLE) + target_compile_definitions(test_fix_timestep PRIVATE -DFFT_SINGLE) +endif() target_link_libraries(test_fix_timestep PRIVATE lammps style_tests) # tests for timestep related fixes (time integration, thermostat, force manipulation, constraints/restraints) diff --git a/unittest/force-styles/test_fix_timestep.cpp b/unittest/force-styles/test_fix_timestep.cpp index d2e35b463f..b65eab2049 100644 --- a/unittest/force-styles/test_fix_timestep.cpp +++ b/unittest/force-styles/test_fix_timestep.cpp @@ -279,6 +279,10 @@ TEST(FixTimestep, plain) ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; + // relax test precision when using pppm and single precision FFTs +#if defined(FFT_SINGLE) + if (lmp->force->kspace && utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; +#endif ErrorStats stats; @@ -411,7 +415,6 @@ TEST(FixTimestep, plain) ifix = lmp->modify->find_fix("test"); if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") && !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) { - if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -579,6 +582,10 @@ TEST(FixTimestep, omp) ASSERT_EQ(lmp->atom->natoms, nlocal); double epsilon = test_config.epsilon; + // relax test precision when using pppm and single precision FFTs +#if defined(FFT_SINGLE) + if (lmp->force->kspace && utils::strmatch(lmp->force->kspace_style, "^pppm")) epsilon *= 2.0e8; +#endif ErrorStats stats; From 732566c8a9ba47475f8e6c8fdc83324d82193139 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 21 Jul 2023 19:32:47 -0400 Subject: [PATCH 09/17] mention that class members should be initialized in the constructor, not the header. --- doc/src/Modify_style.rst | 42 ++++++++++++++------- doc/utils/sphinx-config/false_positives.txt | 1 + 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/doc/src/Modify_style.rst b/doc/src/Modify_style.rst index c5aef71597..e02c2ce59f 100644 --- a/doc/src/Modify_style.rst +++ b/doc/src/Modify_style.rst @@ -28,20 +28,34 @@ Include files (varied) packages and hard-to-find bugs have regularly manifested in the past. -- Header files, especially those defining a "style", should only use - the absolute minimum number of include files and **must not** - contain any ``using`` statements. Typically, that would only be the - header for the base class. Instead, any include statements should - be put in the corresponding implementation files and forward - declarations be used. For implementation files, the "include what - you use" principle should be employed. However, there is the - notable exception that when the ``pointers.h`` header is included - (or one of the base classes derived from it) certain headers will - always be included and thus do not need to be explicitly specified. - These are: `mpi.h`, `cstddef`, `cstdio`, `cstdlib`, `string`, - `utils.h`, `vector`, `fmt/format.h`, `climits`, `cinttypes`. This - also means any such file can assume that `FILE`, `NULL`, and - `INT_MAX` are defined. +- Header files, especially those defining a "style", should only use the + absolute minimum number of include files and **must not** contain any + ``using`` statements. Typically, that would only be the header for the + base class. Instead, any include statements should be put in the + corresponding implementation files and forward declarations be used. + For implementation files, the "include what you use" principle should + be employed. However, there is the notable exception that when the + ``pointers.h`` header is included (or the header of one of the classes + derived from it), certain headers will *always* be included and thus + do not need to be explicitly specified. These are: `mpi.h`, + `cstddef`, `cstdio`, `cstdlib`, `string`, `utils.h`, `vector`, + `fmt/format.h`, `climits`, `cinttypes`. This also means any such file + can assume that `FILE`, `NULL`, and `INT_MAX` are defined. + +- Class members variables should not be initialized in the header file, + but instead should be initialized either in the initializer list of + the constructor or explicitly assigned in the body of the constructor. + If the member variable is relevant to the functionality of a class + (for example when it stores a value from a command line argument), the + member variable declaration is followed by a brief comment explaining + its purpose and what its values can be. Class members that are + pointers should always be initialized to ``nullptr`` in the + initializer list of the constructor. This reduces clutter in the + header and avoids accessing uninitialized pointers, which leads to + hard to debug issues, class members are often implicitly initialized + to ``NULL`` on the first use (but *not* after a :doc:`clear command + `). Please see the files ``reset_atoms_mol.h`` and + ``reset_atoms_mol.cpp`` as an example. - System headers or headers from installed libraries are included with angular brackets (example: ``#include ``), while local diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index a68cd2714f..8e03f283f1 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1528,6 +1528,7 @@ inhomogeneous init initialdelay initialisms +initializer initializations InitiatorIDs initio From 6422565048106045443f022b26bd144d23505533 Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Sun, 23 Jul 2023 12:22:02 +0300 Subject: [PATCH 10/17] Update CONTRIBUTING.md Fixing a small typo --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 44a5ced761..c7abfebf3a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing to LAMMPS via GitHub -Thank your for considering to contribute to the LAMMPS software project. +Thank you for considering to contribute to the LAMMPS software project. The following is a set of guidelines as well as explanations of policies and work flows for contributing to the LAMMPS molecular dynamics software project. These guidelines focus on submitting issues or pull requests on the LAMMPS GitHub project. From 497659a4c73da271d80642c0d8df9e347a921280 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 24 Jul 2023 10:46:31 -0400 Subject: [PATCH 11/17] consolidate use of cstdint and cinttypes, with the latter being a superset of the former --- src/INTEL/intel_intrinsics_airebo.h | 2 +- src/lmptype.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/INTEL/intel_intrinsics_airebo.h b/src/INTEL/intel_intrinsics_airebo.h index 5a7959c683..04cc78f3d2 100644 --- a/src/INTEL/intel_intrinsics_airebo.h +++ b/src/INTEL/intel_intrinsics_airebo.h @@ -749,7 +749,7 @@ struct intr_types { #include #include -#include // requires C++-11 +#include #define VEC_INLINE __attribute__((always_inline)) diff --git a/src/lmptype.h b/src/lmptype.h index 2089350f48..4e62a1a7eb 100644 --- a/src/lmptype.h +++ b/src/lmptype.h @@ -44,7 +44,6 @@ #include // IWYU pragma: export #include // IWYU pragma: export -#include // IWYU pragma: export #include // IWYU pragma: export // grrr - IBM Power6 does not provide this def in their system header files From f7881f4de598d1e9e28342f906a756280544576e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 25 Jul 2023 13:05:27 -0400 Subject: [PATCH 12/17] add global error message buffer for exceptions creating a LAMMPS instance --- src/library.cpp | 62 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 8cec7c4505..d0cad391cb 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -61,6 +61,9 @@ #include #endif +/// string buffer for error messages of global errors +static std::string lammps_last_global_errormessage; + using namespace LAMMPS_NS; // for printing the non-null pointer argument warning only once @@ -179,10 +182,13 @@ void *lammps_open(int argc, char **argv, MPI_Comm comm, void **ptr) #ifdef LAMMPS_EXCEPTIONS try { + lammps_last_global_errormessage.clear(); lmp = new LAMMPS(argc, argv, comm); if (ptr) *ptr = (void *) lmp; } catch(LAMMPSException &e) { + lammps_last_global_errormessage = e.message; + fmt::print(stderr, "LAMMPS Exception: {}", e.message); if (ptr) *ptr = nullptr; } @@ -6488,6 +6494,14 @@ void lammps_force_timeout(void *handle) This function can be used to query if an error inside of LAMMPS has thrown a :ref:`C++ exception `. +.. note:: + + The *handle* pointer may be ``NULL`` for this function, as would be + the case when a call to create a LAMMPS instance has failed. Then + this function will not check the error status inside the LAMMPS + instance, but instead would check the global error buffer of the + library interface. + .. note:: This function will always report "no error" when the LAMMPS library @@ -6497,14 +6511,18 @@ has thrown a :ref:`C++ exception `. the case. \endverbatim * - * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL * \return 0 on no error, 1 on error. */ int lammps_has_error(void *handle) { #ifdef LAMMPS_EXCEPTIONS - LAMMPS *lmp = (LAMMPS *) handle; - Error *error = lmp->error; - return (error->get_last_error().empty()) ? 0 : 1; + if (handle) { + LAMMPS *lmp = (LAMMPS *) handle; + Error *error = lmp->error; + return (error->get_last_error().empty()) ? 0 : 1; + } else { + return lammps_last_global_errormessage.empty() ? 0 : 1; + } #else return 0; #endif @@ -6526,6 +6544,14 @@ a "2" indicates an abort that would happen only in a single MPI rank and thus may not be recoverable, as other MPI ranks may be waiting on the failing MPI ranks to send messages. +.. note:: + + The *handle* pointer may be ``NULL`` for this function, as would be + the case when a call to create a LAMMPS instance has failed. Then + this function will not check the error buffer inside the LAMMPS + instance, but instead would check the global error buffer of the + library interface. + .. note:: This function will do nothing when the LAMMPS library has been @@ -6534,22 +6560,32 @@ the failing MPI ranks to send messages. :cpp:func:`lammps_config_has_exceptions` to check whether this is the case. \endverbatim * - * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. + * \param handle pointer to a previously created LAMMPS instance cast to ``void *`` or NULL. * \param buffer string buffer to copy the error message to * \param buf_size size of the provided string buffer * \return 1 when all ranks had the error, 2 on a single rank error. */ int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) { #ifdef LAMMPS_EXCEPTIONS - LAMMPS *lmp = (LAMMPS *) handle; - Error *error = lmp->error; - buffer[0] = buffer[buf_size-1] = '\0'; + if (handle) { + LAMMPS *lmp = (LAMMPS *) handle; + Error *error = lmp->error; + buffer[0] = buffer[buf_size-1] = '\0'; - if (!error->get_last_error().empty()) { - int error_type = error->get_last_error_type(); - strncpy(buffer, error->get_last_error().c_str(), buf_size-1); - error->set_last_error("", ERROR_NONE); - return error_type; + if (!error->get_last_error().empty()) { + int error_type = error->get_last_error_type(); + strncpy(buffer, error->get_last_error().c_str(), buf_size-1); + error->set_last_error("", ERROR_NONE); + return error_type; + } + } else { + buffer[0] = buffer[buf_size-1] = '\0'; + + if (!lammps_last_global_errormessage.empty()) { + strncpy(buffer, lammps_last_global_errormessage.c_str(), buf_size-1); + lammps_last_global_errormessage.clear(); + return 1; + } } #endif return 0; From 368be8ac39df5c444af0772414812140d0273e01 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 25 Jul 2023 21:40:54 -0400 Subject: [PATCH 13/17] update list of keywords for VIM syntax highlighting --- tools/vim/lammps.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/vim/lammps.vim b/tools/vim/lammps.vim index 9565d0a86e..25c18f4a9c 100644 --- a/tools/vim/lammps.vim +++ b/tools/vim/lammps.vim @@ -17,19 +17,19 @@ syn keyword lammpsLattice delete_atoms displace_atoms change_box dimension syn keyword lammpsParticle pair_coeff pair_style pair_modify pair_write mass velocity angle_coeff angle_style angle_write syn keyword lammpsParticle atom_modify atom_style bond_coeff bond_style bond_write create_bonds delete_bonds kspace_style syn keyword lammpsParticle kspace_modify dihedral_style dihedral_coeff dihedral_write improper_style improper_coeff labelmap -syn keyword lammpsSetup min_style min_modify fix_modify run_style timestep neighbor neigh_modify fix unfix suffix special_bonds +syn keyword lammpsSetup min_style min_modify fix_modify run_style timestep neighbor neigh_modify fix unfix suffix special_bonds dump_modify syn keyword lammpsSetup balance box clear comm_modify comm_style newton package processors reset_atoms reset_ids reset_timestep syn keyword lammpsRun minimize minimize/kk run rerun tad neb neb/spin prd quit server temper/npt temper/grem temper syn keyword lammpsRun message hyper dynamical_matrix dynamical_matrix/kk third_order third_order/kk fitpod syn keyword lammpsDefine variable group compute python set uncompute kim_query kim group2ndx ndx2group mdi -syn keyword lammpsRepeat jump next loop +syn keyword lammpsRepeat jump next loop label syn keyword lammpsOperator equal add sub mult div syn keyword lammpsConditional if then elif else -syn keyword lammpsSpecial EDGE NULL & +syn keyword lammpsSpecial EDGE NULL INF & syn region lammpsString start=+'+ end=+'+ oneline syn region lammpsString start=+"+ end=+"+ oneline From 32091d9f32b232c75d50a2a6efbebbbfa7ee0909 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jul 2023 08:20:02 -0400 Subject: [PATCH 14/17] fix typo in plugin interface API --- examples/COUPLE/plugin/liblammpsplugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/COUPLE/plugin/liblammpsplugin.h b/examples/COUPLE/plugin/liblammpsplugin.h index 1520ef638d..271f6b9b20 100644 --- a/examples/COUPLE/plugin/liblammpsplugin.h +++ b/examples/COUPLE/plugin/liblammpsplugin.h @@ -239,7 +239,7 @@ struct _liblammpsplugin { void (*free)(void *); - void (*is_running)(void *); + int (*is_running)(void *); void (*force_timeout)(void *); int (*has_error)(void *); From a8de49769bd7b34c072e067903b59fd4be0c5551 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jul 2023 10:43:20 -0400 Subject: [PATCH 15/17] add missing entry --- src/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/.gitignore b/src/.gitignore index 2cb2fd315b..6e2a8b92c9 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -60,6 +60,8 @@ /pair_lepton.h /pair_lepton_coul.cpp /pair_lepton_coul.h +/pair_lepton_sphere.cpp +/pair_lepton_sphere.h /bond_lepton.cpp /bond_lepton.h /angle_lepton.cpp From 739bffa5e66fcd7e8d3015d2de1013ba1760193f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 27 Jul 2023 19:20:35 -0400 Subject: [PATCH 16/17] accept sphinx 7.1 --- doc/utils/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/utils/requirements.txt b/doc/utils/requirements.txt index 9c8522948b..5b298c2975 100644 --- a/doc/utils/requirements.txt +++ b/doc/utils/requirements.txt @@ -1,4 +1,4 @@ -Sphinx >= 5.3.0, <7.1.0 +Sphinx >= 5.3.0, <7.2.0 sphinxcontrib-spelling sphinxcontrib-jquery git+https://github.com/akohlmey/sphinx-fortran@parallel-read From b75407684f779d67c1266bf5b90c384966dde584 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 29 Jul 2023 13:49:21 -0400 Subject: [PATCH 17/17] more accurate pattern matching --- src/ELECTRODE/fix_electrode_conp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ELECTRODE/fix_electrode_conp.cpp b/src/ELECTRODE/fix_electrode_conp.cpp index 85f59127f1..1b6c0a37d4 100644 --- a/src/ELECTRODE/fix_electrode_conp.cpp +++ b/src/ELECTRODE/fix_electrode_conp.cpp @@ -417,7 +417,7 @@ void FixElectrodeConp::post_constructor() input->variable->set(fmt::format("{} equal f_{}[{}]", var_vtop, fixname, 1 + top_group)); input->variable->set(fmt::format("{} equal (v_{}-v_{})/lz", var_efield, var_vbot, var_vtop)); // check for other efields and warn if found - if (modify->get_fix_by_style("efield").size() > 0 && comm->me == 0) + if (modify->get_fix_by_style("^efield").size() > 0 && comm->me == 0) error->warning(FLERR, "Other efield fixes found -- please make sure this is intended!"); // call fix command: // fix [varstem]_efield all efield 0.0 0.0 [var_vdiff]/lz