diff --git a/.github/workflows/compile-msvc.yml b/.github/workflows/compile-msvc.yml index e71a2950e6..75d531d9af 100644 --- a/.github/workflows/compile-msvc.yml +++ b/.github/workflows/compile-msvc.yml @@ -21,6 +21,7 @@ jobs: shell: bash run: | cmake -C cmake/presets/windows.cmake \ + -D PKG_PYTHON=on \ -S cmake -B build \ -D BUILD_SHARED_LIBS=on \ -D LAMMPS_EXCEPTIONS=on \ diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 7ee4563b6e..56a07dc94b 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -359,11 +359,13 @@ if(BUILD_OMP) ((CMAKE_CXX_COMPILER_ID STREQUAL "Intel") AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0))) # 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) + set(LAMMPS_OMP_COMPAT_LEVEL 4) else() - target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=3) + set(LAMMPS_OMP_COMPAT_LEVEL 3) endif() + target_compile_definitions(lammps PRIVATE -DLAMMPS_OMP_COMPAT=${LAMMPS_OMP_COMPAT_LEVEL}) target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX) + target_link_libraries(lmp PRIVATE OpenMP::OpenMP_CXX) endif() if(PKG_MSCG OR PKG_ATC OR PKG_AWPMD OR PKG_ML-QUIP OR PKG_LATTE) diff --git a/cmake/Modules/Packages/KOKKOS.cmake b/cmake/Modules/Packages/KOKKOS.cmake index ebc5adff5b..bccfdf7243 100644 --- a/cmake/Modules/Packages/KOKKOS.cmake +++ b/cmake/Modules/Packages/KOKKOS.cmake @@ -11,8 +11,14 @@ if(Kokkos_ENABLE_CUDA) endif() # Adding OpenMP compiler flags without the checks done for # BUILD_OMP can result in compile failures. Enforce consistency. -if(Kokkos_ENABLE_OPENMP AND NOT BUILD_OMP) - message(FATAL_ERROR "Must enable BUILD_OMP with Kokkos_ENABLE_OPENMP") +if(Kokkos_ENABLE_OPENMP) + if(NOT BUILD_OMP) + message(FATAL_ERROR "Must enable BUILD_OMP with Kokkos_ENABLE_OPENMP") + else() + if(LAMMPS_OMP_COMPAT_LEVEL LESS 4) + message(FATAL_ERROR "Compiler must support OpenMP 4.0 or later with Kokkos_ENABLE_OPENMP") + endif() + endif() endif() ######################################################################## @@ -27,6 +33,8 @@ if(DOWNLOAD_KOKKOS) endforeach() message(STATUS "KOKKOS download requested - we will build our own") list(APPEND KOKKOS_LIB_BUILD_ARGS "-DCMAKE_INSTALL_PREFIX=") + # build KOKKOS downloaded libraries as static libraries but with PIC, if needed + list(APPEND KOKKOS_LIB_BUILD_ARGS "-DBUILD_SHARED_LIBS=OFF") if(CMAKE_REQUEST_PIC) list(APPEND KOKKOS_LIB_BUILD_ARGS ${CMAKE_REQUEST_PIC}) endif() @@ -47,18 +55,22 @@ if(DOWNLOAD_KOKKOS) URL ${KOKKOS_URL} URL_MD5 ${KOKKOS_MD5} CMAKE_ARGS ${KOKKOS_LIB_BUILD_ARGS} - BUILD_BYPRODUCTS /lib/libkokkoscore.a + BUILD_BYPRODUCTS /lib/libkokkoscore.a /lib/libkokkoscontainers.a ) ExternalProject_get_property(kokkos_build INSTALL_DIR) file(MAKE_DIRECTORY ${INSTALL_DIR}/include) - add_library(LAMMPS::KOKKOS UNKNOWN IMPORTED) - set_target_properties(LAMMPS::KOKKOS PROPERTIES + add_library(LAMMPS::KOKKOSCORE UNKNOWN IMPORTED) + add_library(LAMMPS::KOKKOSCONTAINERS UNKNOWN IMPORTED) + set_target_properties(LAMMPS::KOKKOSCORE PROPERTIES IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscore.a" INTERFACE_INCLUDE_DIRECTORIES "${INSTALL_DIR}/include" INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) - target_link_libraries(lammps PRIVATE LAMMPS::KOKKOS) - target_link_libraries(lmp PRIVATE LAMMPS::KOKKOS) - add_dependencies(LAMMPS::KOKKOS kokkos_build) + set_target_properties(LAMMPS::KOKKOSCONTAINERS PROPERTIES + IMPORTED_LOCATION "${INSTALL_DIR}/lib/libkokkoscontainers.a") + target_link_libraries(lammps PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS) + target_link_libraries(lmp PRIVATE LAMMPS::KOKKOSCORE LAMMPS::KOKKOSCONTAINERS) + add_dependencies(LAMMPS::KOKKOSCORE kokkos_build) + add_dependencies(LAMMPS::KOKKOSCONTAINERS kokkos_build) elseif(EXTERNAL_KOKKOS) find_package(Kokkos 3.5.00 REQUIRED CONFIG) target_link_libraries(lammps PRIVATE Kokkos::kokkos) @@ -66,8 +78,14 @@ elseif(EXTERNAL_KOKKOS) else() set(LAMMPS_LIB_KOKKOS_SRC_DIR ${LAMMPS_LIB_SOURCE_DIR}/kokkos) set(LAMMPS_LIB_KOKKOS_BIN_DIR ${LAMMPS_LIB_BINARY_DIR}/kokkos) + # build KOKKOS internal libraries as static libraries but with PIC, if needed + set(BUILD_SHARED_LIBS OFF) + if(CMAKE_REQUEST_PIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) + endif() add_subdirectory(${LAMMPS_LIB_KOKKOS_SRC_DIR} ${LAMMPS_LIB_KOKKOS_BIN_DIR}) + set(Kokkos_INCLUDE_DIRS ${LAMMPS_LIB_KOKKOS_SRC_DIR}/core/src ${LAMMPS_LIB_KOKKOS_SRC_DIR}/containers/src ${LAMMPS_LIB_KOKKOS_SRC_DIR}/algorithms/src diff --git a/cmake/Modules/Packages/ML-HDNNP.cmake b/cmake/Modules/Packages/ML-HDNNP.cmake index e27b3a1410..5a4c287fa2 100644 --- a/cmake/Modules/Packages/ML-HDNNP.cmake +++ b/cmake/Modules/Packages/ML-HDNNP.cmake @@ -46,12 +46,10 @@ if(DOWNLOAD_N2P2) if((CMAKE_SYSTEM_NAME STREQUAL Windows) AND CMAKE_CROSSCOMPILING) get_target_property(N2P2_MPI_INCLUDE MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES) set(N2P2_PROJECT_OPTIONS "-I${N2P2_MPI_INCLUDE}") - set(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") get_target_property(N2P2_MPI_INCLUDE MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES) set(N2P2_PROJECT_OPTIONS "-I${N2P2_MPI_INCLUDE}") - set(MPI_CXX_COMPILER ${CMAKE_CXX_COMPILER}) endif() endif() @@ -64,8 +62,8 @@ if(DOWNLOAD_N2P2) string(TOUPPER "${CMAKE_BUILD_TYPE}" BTYPE) set(N2P2_BUILD_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${BTYPE}} ${N2P2_CXX_STD}") set(N2P2_BUILD_OPTIONS INTERFACES=LAMMPS COMP=${N2P2_COMP} "PROJECT_OPTIONS=${N2P2_PROJECT_OPTIONS}" "PROJECT_DEBUG=" - "PROJECT_CC=${CMAKE_CXX_COMPILER}" "PROJECT_MPICC=${MPI_CXX_COMPILER}" "PROJECT_CFLAGS=${N2P2_BUILD_FLAGS}" - "PROJECT_AR=${N2P2_AR}") + "PROJECT_CC=${CMAKE_CXX_COMPILER}" "PROJECT_MPICC=${CMAKE_CXX_COMPILER}" "PROJECT_CFLAGS=${N2P2_BUILD_FLAGS}" + "PROJECT_AR=${N2P2_AR}" "APP_CORE=nnp-convert" "APP_TRAIN=nnp-train" "APP=nnp-convert") # echo final flag for debugging message(STATUS "N2P2 BUILD OPTIONS: ${N2P2_BUILD_OPTIONS}") diff --git a/lib/kokkos/core/src/desul/atomics/Generic.hpp b/lib/kokkos/core/src/desul/atomics/Generic.hpp index 9d5e87ece2..19d7a453fa 100644 --- a/lib/kokkos/core/src/desul/atomics/Generic.hpp +++ b/lib/kokkos/core/src/desul/atomics/Generic.hpp @@ -10,8 +10,10 @@ SPDX-License-Identifier: (BSD-3-Clause) #define DESUL_ATOMICS_GENERIC_HPP_ #include +#if defined(__GNUC__) && (!defined(__clang__)) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif #include "desul/atomics/Common.hpp" #include "desul/atomics/Compare_Exchange.hpp" #include "desul/atomics/Lock_Array.hpp" @@ -686,5 +688,7 @@ DESUL_INLINE_FUNCTION bool atomic_compare_exchange_weak(T* const dest, #include #include #include +#if defined(__GNUC__) && (!defined(__clang__)) #pragma GCC diagnostic pop #endif +#endif diff --git a/lib/kokkos/core/src/impl/Kokkos_Core.cpp b/lib/kokkos/core/src/impl/Kokkos_Core.cpp index a1f9d33632..00d6b5850b 100644 --- a/lib/kokkos/core/src/impl/Kokkos_Core.cpp +++ b/lib/kokkos/core/src/impl/Kokkos_Core.cpp @@ -58,7 +58,7 @@ #ifndef _WIN32 #include #else -#include +#include #endif //---------------------------------------------------------------------------- diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index e26513a122..0c730fda65 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -600,7 +600,8 @@ void KokkosLMP::my_signal_handler(int sig) { if (sig == SIGSEGV) { #if defined(_WIN32) - kill(_getpid(),SIGABRT); + // there is no kill() function on Windows + exit(1); #else kill(getpid(),SIGABRT); #endif diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 0988cb4910..d96e9f3f65 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -17,9 +17,7 @@ ------------------------------------------------------------------------- */ #include "pair_exp6_rx_kokkos.h" -#include -#include #include "atom.h" #include "comm.h" #include "force.h" @@ -28,12 +26,14 @@ #include "memory_kokkos.h" #include "error.h" #include "fix.h" -#include #include "atom_masks.h" #include "neigh_request.h" #include "atom_kokkos.h" #include "kokkos.h" +#include +#include +#include #ifdef _OPENMP #include @@ -57,22 +57,6 @@ using namespace MathSpecialKokkos; #define exp6PotentialType (1) #define isExp6PotentialType(_type) ( (_type) == exp6PotentialType ) -namespace /* anonymous */ -{ - -//typedef double TimerType; -//TimerType getTimeStamp(void) { return platform::walltime(); } -//double getElapsedTime( const TimerType &t0, const TimerType &t1) { return t1-t0; } - -typedef struct timespec TimerType; -TimerType getTimeStamp(void) { TimerType tick; clock_gettime( CLOCK_MONOTONIC, &tick); return tick; } -double getElapsedTime( const TimerType &t0, const TimerType &t1) -{ - return (t1.tv_sec - t0.tv_sec) + 1e-9*(t1.tv_nsec - t0.tv_nsec); -} - -} // end namespace - /* ---------------------------------------------------------------------- */ template @@ -142,8 +126,6 @@ void PairExp6rxKokkos::init_style() template void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) { - //TimerType t_start = getTimeStamp(); - copymode = 1; eflag = eflag_in; @@ -187,7 +169,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) // and ghost atoms. Make the parameter data persistent // and exchange like any other atom property later. - //TimerType t_mix_start = getTimeStamp(); { const int np_total = nlocal + atom->nghost; @@ -260,7 +241,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) error->all(FLERR,"Computed fraction less than -10*DBL_EPSILON"); #endif } - //TimerType t_mix_stop = getTimeStamp(); k_error_flag.template modify(); k_error_flag.template sync(); @@ -377,9 +357,6 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) } copymode = 0; - - //TimerType t_stop = getTimeStamp(); - //printf("PairExp6rxKokkos::compute %f %f\n", getElapsedTime(t_start, t_stop), getElapsedTime(t_mix_start, t_mix_stop)); } template diff --git a/src/KOKKOS/pppm_kokkos.cpp b/src/KOKKOS/pppm_kokkos.cpp index da18bba001..a5073129e8 100644 --- a/src/KOKKOS/pppm_kokkos.cpp +++ b/src/KOKKOS/pppm_kokkos.cpp @@ -2711,10 +2711,9 @@ void PPPMKokkos::compute_rho_coeff() { int j,k,l,m; FFT_SCALAR s; - - //FFT_SCALAR **a; - //memory->create2d_offset(a,order,-order,order,"pppm:a"); - FFT_SCALAR a[order][2*order+1]; + FFT_SCALAR **a = new FFT_SCALAR *[order]; + for (int i = 0; i < order; ++i) + a[i] = new FFT_SCALAR[2*order+1]; for (k = 0; k <= 2*order; k++) for (l = 0; l < order; l++) @@ -2744,7 +2743,9 @@ void PPPMKokkos::compute_rho_coeff() h_rho_coeff(l,m-(1-order)/2) = a[l][k+order]; m++; } - //memory->destroy2d_offset(a,-order); + for (int i = 0; i < order; ++i) + delete[] a[i]; + delete[] a; } /* ---------------------------------------------------------------------- diff --git a/unittest/cplusplus/test_lammps_class.cpp b/unittest/cplusplus/test_lammps_class.cpp index 6c733a31e4..4885cffbe2 100644 --- a/unittest/cplusplus/test_lammps_class.cpp +++ b/unittest/cplusplus/test_lammps_class.cpp @@ -261,13 +261,13 @@ protected: int argc = sizeof(args) / sizeof(char *); // only run this test fixture with kk suffix if KOKKOS package is installed - // also need to figure out a way to find which parallelizations are enabled if (LAMMPS::is_installed_pkg("KOKKOS")) { ::testing::internal::CaptureStdout(); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::")); + if (Info::has_accelerator_feature("KOKKOS", "api", "openmp")) + EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::")); } else GTEST_SKIP(); } diff --git a/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml b/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml index 5acd407191..b8d662829b 100644 --- a/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml +++ b/unittest/force-styles/tests/atomic-pair-reaxff_tabulate.yaml @@ -1,6 +1,6 @@ --- lammps_version: 30 Jul 2021 -tags: slow, unstable +tags: slow, unstable, noWindows date_generated: Mon Aug 23 20:32:05 2021 epsilon: 1e-12 skip_tests: