Merge remote-tracking branch 'github/develop' into collected-small-fixes
This commit is contained in:
@ -105,46 +105,33 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qrestrict")
|
||||
endif()
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
|
||||
set(CMAKE_TUNE_DEFAULT "/QxCOMMON-AVX512")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QxCOMMON-AVX512")
|
||||
else()
|
||||
set(CMAKE_TUNE_DEFAULT "/QxHost")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /QxHost")
|
||||
endif()
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -restrict")
|
||||
if(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.3 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 17.4)
|
||||
set(CMAKE_TUNE_DEFAULT "-xCOMMON-AVX512")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xCOMMON-AVX512")
|
||||
else()
|
||||
set(CMAKE_TUNE_DEFAULT "-xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -xHost -fp-model fast=2 -no-prec-div -qoverride-limits -diag-disable=10441 -diag-disable=11074 -diag-disable=11076 -diag-disable=2196")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# silence excessive warnings for new Intel Compilers
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
|
||||
set(CMAKE_TUNE_DEFAULT "-fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model precise -Wno-tautological-constant-compare -Wno-unused-command-line-argument")
|
||||
endif()
|
||||
|
||||
# silence excessive warnings for PGI/NVHPC compilers
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_CXX_COMPILER_ID STREQUAL "PGI"))
|
||||
set(CMAKE_TUNE_DEFAULT "-Minform=severe")
|
||||
endif()
|
||||
|
||||
# this hack is required to compile fmt lib with CrayClang version 15.0.2
|
||||
# CrayClang is only directly recognized by version 3.28 and later
|
||||
if(CMAKE_VERSION VERSION_LESS 3.28)
|
||||
get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
|
||||
set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
|
||||
endif()
|
||||
else()
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
|
||||
set(CMAKE_TUNE_DEFAULT "-DFMT_STATIC_THOUSANDS_SEPARATOR")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Minform=severe")
|
||||
endif()
|
||||
|
||||
# silence nvcc warnings
|
||||
if((PKG_KOKKOS) AND (Kokkos_ENABLE_CUDA) AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
|
||||
set(CMAKE_TUNE_DEFAULT "${CMAKE_TUNE_DEFAULT}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-Xcudafe --diag_suppress=unrecognized_pragma,--diag_suppress=128")
|
||||
endif()
|
||||
|
||||
# we *require* C++11 without extensions but prefer C++17.
|
||||
@ -450,6 +437,19 @@ if(NOT ${LAMMPS_MEMALIGN} STREQUAL "0")
|
||||
target_compile_definitions(lammps PRIVATE -DLAMMPS_MEMALIGN=${LAMMPS_MEMALIGN})
|
||||
endif()
|
||||
|
||||
# this hack is required to compile fmt lib with CrayClang version 15.0.2
|
||||
# CrayClang is only directly recognized by CMake version 3.28 and later
|
||||
if(CMAKE_VERSION VERSION_LESS 3.28)
|
||||
get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
|
||||
target_compile_definitions(lammps PRIVATE -DFMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
endif()
|
||||
else()
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
|
||||
target_compile_definitions(lammps PRIVATE -DFMT_STATIC_THOUSANDS_SEPARATOR)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# "hard" dependencies between packages resulting
|
||||
# in an error instead of skipping over files
|
||||
pkg_depends(ML-IAP ML-SNAP)
|
||||
@ -507,13 +507,13 @@ if(BUILD_OMP)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.28)
|
||||
get_filename_component(_exe "${CMAKE_CXX_COMPILER}" NAME)
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND (_exe STREQUAL "crayCC"))
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp")
|
||||
set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
|
||||
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fopenmp")
|
||||
endif()
|
||||
else()
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "CrayClang")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_${BTYPE} "${CMAKE_SHARED_LINKER_FLAGS_${BTYPE}} -fopenmp")
|
||||
set(CMAKE_STATIC_LINKER_FLAGS_${BTYPE} "${CMAKE_STATIC_LINKER_FLAGS_${BTYPE}} -fopenmp")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fopenmp")
|
||||
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fopenmp")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
@ -628,10 +628,6 @@ if(WITH_SWIG)
|
||||
add_subdirectory(${LAMMPS_SWIG_DIR} swig)
|
||||
endif()
|
||||
|
||||
set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler and machine specific optimization flags (compilation only)")
|
||||
separate_arguments(CMAKE_TUNE_FLAGS)
|
||||
target_compile_options(lammps PRIVATE ${CMAKE_TUNE_FLAGS})
|
||||
target_compile_options(lmp PRIVATE ${CMAKE_TUNE_FLAGS})
|
||||
########################################################################
|
||||
# Basic system tests (standard libraries, headers, functions, types) #
|
||||
########################################################################
|
||||
|
||||
@ -14,10 +14,6 @@ endif()
|
||||
|
||||
add_library(colvars STATIC ${COLVARS_SOURCES})
|
||||
target_compile_definitions(colvars PRIVATE -DCOLVARS_LAMMPS)
|
||||
separate_arguments(CMAKE_TUNE_FLAGS)
|
||||
foreach(_FLAG ${CMAKE_TUNE_FLAGS})
|
||||
target_compile_options(colvars PRIVATE ${_FLAG})
|
||||
endforeach()
|
||||
set_target_properties(colvars PROPERTIES OUTPUT_NAME lammps_colvars${LAMMPS_MACHINE})
|
||||
target_include_directories(colvars PUBLIC ${LAMMPS_LIB_SOURCE_DIR}/colvars)
|
||||
# The line below is needed to locate math_eigen_impl.h
|
||||
|
||||
@ -9,8 +9,7 @@ set(Kokkos_ARCH_VEGA90A on CACHE BOOL "" FORCE)
|
||||
set(Kokkos_ENABLE_HIP_MULTIPLE_KERNEL_INSTANTIATIONS ON CACHE BOOL "" FORCE)
|
||||
set(BUILD_OMP ON CACHE BOOL "" FORCE)
|
||||
|
||||
set(CMAKE_CXX_COMPILER hipcc CACHE STRING "" FORCE)
|
||||
set(CMAKE_TUNE_FLAGS "-munsafe-fp-atomics" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -munsafe-fp-atomics" CACHE STRING "" FORCE)
|
||||
|
||||
# If KSPACE is also enabled, use CUFFT for FFTs
|
||||
set(FFT_KOKKOS "HIPFFT" CACHE STRING "" FORCE)
|
||||
|
||||
@ -21,9 +21,10 @@ set(CMAKE_C_COMPILER icx CACHE STRING "" FORCE)
|
||||
set(CMAKE_Fortran_COMPILER "" CACHE STRING "" FORCE)
|
||||
set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE)
|
||||
# Silence everything
|
||||
set(CMAKE_CXX_FLAGS "-w" CACHE STRING "" FORCE)
|
||||
|
||||
# set(_intel_sycl_flags " -w -fsycl -flink-huge-device-code -fsycl-targets=spir64_gen "
|
||||
set(_intel_sycl_flags " -w -fsycl -fsycl-device-code-split=per_kernel -fsycl-targets=spir64_gen "
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_intel_sycl_flags}" CACHE STRING "" FORCE)
|
||||
|
||||
#set(CMAKE_EXE_LINKER_FLAGS "-fsycl -flink-huge-device-code -fsycl-targets=spir64_gen " CACHE STRING "" FORCE)
|
||||
#set(CMAKE_TUNE_FLAGS "-O3 -fsycl -fsycl-device-code-split=per_kernel -fsycl-targets=spir64_gen" CACHE STRING "" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-fsycl -flink-huge-device-code " CACHE STRING "" FORCE)
|
||||
set(CMAKE_TUNE_FLAGS "-O3 -fsycl -fsycl-device-code-split=per_kernel " CACHE STRING "" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsycl -flink-huge-device-code " CACHE STRING "" FORCE)
|
||||
|
||||
@ -14,5 +14,7 @@ set(Kokkos_ENABLE_DEPRECATION_WARNINGS OFF CACHE BOOL "" FORCE)
|
||||
set(CMAKE_CXX_COMPILER clang++ CACHE STRING "" FORCE)
|
||||
set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_STANDARD 17 CACHE STRING "" FORCE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "-Xsycl-target-frontend -O3" CACHE STRING "" FORCE)
|
||||
set(CMAKE_TUNE_FLAGS "-fgpu-inline-threshold=100000 -Xsycl-target-frontend -O3 -Xsycl-target-frontend -ffp-contract=on -Wno-unknown-cuda-version" CACHE STRING "" FORCE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Xsycl-target-frontend -O3 " CACHE STRING "" FORCE)
|
||||
|
||||
set(_intel_sycl_flags "-fgpu-inline-threshold=100000 -Xsycl-target-frontend -O3 -Xsycl-target-frontend -ffp-contract=on -Wno-unknown-cuda-version")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_intel_sycl_flags}" CACHE STRING "" FORCE)
|
||||
|
||||
@ -91,7 +91,7 @@ endif()
|
||||
set(DOWNLOAD_VORO ON CACHE BOOL "" FORCE)
|
||||
set(DOWNLOAD_EIGEN3 ON CACHE BOOL "" FORCE)
|
||||
set(LAMMPS_MEMALIGN "0" CACHE STRING "" FORCE)
|
||||
set(CMAKE_TUNE_FLAGS "-Wno-missing-include-dirs" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-include-dirs" CACHE STRING "" FORCE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--enable-stdcall-fixup,--as-needed,-lssp" CACHE STRING "" FORCE)
|
||||
set(BUILD_TOOLS ON CACHE BOOL "" FORCE)
|
||||
|
||||
@ -5,4 +5,4 @@ set(CMAKE_C_COMPILER "icx" CACHE STRING "" FORCE)
|
||||
set(CMAKE_Fortran_COMPILER "ifx" CACHE STRING "" FORCE)
|
||||
set(INTEL_LRT_MODE "C++11" CACHE STRING "" FORCE)
|
||||
unset(HAVE_OMP_H_INCLUDE CACHE)
|
||||
set(CMAKE_TUNE_FLAGS -Wno-unused-command-line-argument)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument" CACHE STRING "" FORCE)
|
||||
|
||||
@ -212,11 +212,7 @@ LAMMPS.
|
||||
You can tell CMake to look for a specific compiler with setting
|
||||
CMake variables (listed below) during configuration. For a few
|
||||
common choices, there are also presets in the ``cmake/presets``
|
||||
folder. For convenience, there is a ``CMAKE_TUNE_FLAGS`` variable
|
||||
that can be set to apply global compiler options (applied to
|
||||
compilation only), to be used for adding compiler or host specific
|
||||
optimization flags in addition to the "flags" variables listed
|
||||
below. You may also specify the corresponding ``CMAKE_*_FLAGS``
|
||||
folder. You may also specify the corresponding ``CMAKE_*_FLAGS``
|
||||
variables individually, if you want to experiment with alternate
|
||||
optimization flags. You should specify all 3 compilers, so that
|
||||
the (few) LAMMPS source files written in C or Fortran are built
|
||||
@ -266,10 +262,6 @@ LAMMPS.
|
||||
``-C ../cmake/presets/pgi.cmake`` will switch the compiler to the PGI compilers,
|
||||
and ``-C ../cmake/presets/nvhpc.cmake`` will switch to the NVHPC compilers.
|
||||
|
||||
Furthermore, you can set ``CMAKE_TUNE_FLAGS`` to specifically add
|
||||
compiler flags to tune for optimal performance on given hosts.
|
||||
This variable is empty by default.
|
||||
|
||||
.. note::
|
||||
|
||||
When the cmake command completes, it prints a summary to the
|
||||
|
||||
@ -18,7 +18,6 @@ explains how to do this for building both with CMake and make.
|
||||
* `Memory allocation alignment`_
|
||||
* `Workaround for long long integers`_
|
||||
* `Exception handling when using LAMMPS as a library`_ to capture errors
|
||||
* `Trigger selected floating-point exceptions`_
|
||||
|
||||
----------
|
||||
|
||||
@ -659,40 +658,3 @@ code has to be set up to *catch* exceptions thrown from within LAMMPS.
|
||||
throw an exception and thus other MPI ranks may get stuck waiting for
|
||||
messages from the ones with errors.
|
||||
|
||||
----------
|
||||
|
||||
.. _trap_fpe:
|
||||
|
||||
Trigger selected floating-point exceptions
|
||||
------------------------------------------
|
||||
|
||||
Many kinds of CPUs have the capability to detect when a calculation
|
||||
results in an invalid math operation, like a division by zero or calling
|
||||
the square root with a negative argument. The default behavior on
|
||||
most operating systems is to continue and have values for ``NaN`` (= not
|
||||
a number) or ``Inf`` (= infinity). This allows software to detect and
|
||||
recover from such conditions. This behavior can be changed, however,
|
||||
often through use of compiler flags. On Linux systems (or more general
|
||||
on systems using the GNU C library), these so-called floating-point traps
|
||||
can also be selectively enabled through library calls. LAMMPS supports
|
||||
that by setting the ``-DLAMMPS_TRAP_FPE`` pre-processor define. As it is
|
||||
done in the ``main()`` function, this applies only to the standalone
|
||||
executable, not the library.
|
||||
|
||||
.. tabs::
|
||||
|
||||
.. tab:: CMake build
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
-D CMAKE_TUNE_FLAGS=-DLAMMPS_TRAP_FPE
|
||||
|
||||
.. tab:: Traditional make
|
||||
|
||||
.. code-block:: make
|
||||
|
||||
LMP_INC = -DLAMMPS_TRAP_FPE <other LMP_INC settings>
|
||||
|
||||
After compilation with this flag set, the LAMMPS executable will stop
|
||||
and produce a core dump when a division by zero, overflow, illegal math
|
||||
function argument or other invalid floating point operation is encountered.
|
||||
|
||||
@ -285,7 +285,7 @@ when used before the CMake directory, there may be a space between the
|
||||
can have boolean values (on/off, yes/no, or 1/0 are all valid) or are
|
||||
strings representing a choice, or a path, or are free format. If the
|
||||
string would contain whitespace, it must be put in quotes, for example
|
||||
``-D CMAKE_TUNE_FLAGS="-ftree-vectorize -ffast-math"``.
|
||||
``-D CMAKE_CXX_FLAGS="-O3 -Wall -ftree-vectorize -ffast-math"``.
|
||||
|
||||
CMake variables fall into two categories: 1) common CMake variables that
|
||||
are used by default for any CMake configuration setup and 2) project
|
||||
@ -341,8 +341,6 @@ Some common LAMMPS specific variables
|
||||
- compile some additional executables from the ``tools`` folder (default: ``off``)
|
||||
* - ``BUILD_DOC``
|
||||
- include building the HTML format documentation for packaging/installing (default: ``off``)
|
||||
* - ``CMAKE_TUNE_FLAGS``
|
||||
- common compiler flags, for optimization or instrumentation (default:)
|
||||
* - ``LAMMPS_MACHINE``
|
||||
- when set to ``name`` the LAMMPS executable and library will be called ``lmp_name`` and ``liblammps_name.a``
|
||||
* - ``FFT``
|
||||
|
||||
12
src/info.cpp
12
src/info.cpp
@ -34,6 +34,7 @@
|
||||
#include "group.h"
|
||||
#include "improper.h"
|
||||
#include "input.h"
|
||||
#include "json.h"
|
||||
#include "lmpfftsettings.h"
|
||||
#include "modify.h"
|
||||
#include "neighbor.h"
|
||||
@ -291,6 +292,7 @@ void Info::command(int narg, char **arg)
|
||||
utils::print(out,"\nCompiler: {} with {}\nC++ standard: {}\n",
|
||||
platform::compiler_info(),platform::openmp_standard(),platform::cxx_standard());
|
||||
fputs(get_fmt_info().c_str(), out);
|
||||
fputs(get_json_info().c_str(), out);
|
||||
|
||||
fputs("\nActive compile time flags:\n\n",out);
|
||||
if (has_gzip_support()) fputs("-DLAMMPS_GZIP\n",out);
|
||||
@ -1320,6 +1322,16 @@ std::string Info::get_fmt_info()
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
std::string Info::get_json_info()
|
||||
{
|
||||
return fmt::format("Embedded JSON class version: {}.{}.{}\n",
|
||||
NLOHMANN_JSON_VERSION_MAJOR,
|
||||
NLOHMANN_JSON_VERSION_MINOR,
|
||||
NLOHMANN_JSON_VERSION_PATCH);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void Info::get_memory_info(double *meminfo)
|
||||
{
|
||||
double bytes = 0;
|
||||
|
||||
@ -50,6 +50,7 @@ class Info : public Command {
|
||||
const std::string &);
|
||||
static std::string get_fft_info();
|
||||
static std::string get_fmt_info();
|
||||
static std::string get_json_info();
|
||||
static bool has_gpu_device();
|
||||
static std::string get_gpu_device_info();
|
||||
static std::string get_accelerator_info(const std::string &pkg = "");
|
||||
|
||||
25
src/json.h
Normal file
25
src/json.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_JSON_H
|
||||
#define LMP_JSON_H
|
||||
|
||||
// wrapper around including the JSON parsing and writing class
|
||||
// Do NOT include in any header file
|
||||
|
||||
#include "../third_party/nlohmann/json.hpp"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using json = ::nlohmann_lmp::json;
|
||||
}
|
||||
#endif
|
||||
@ -1456,6 +1456,7 @@ void LAMMPS::print_config(FILE *fp)
|
||||
platform::compiler_info(),platform::openmp_standard(),
|
||||
platform::cxx_standard());
|
||||
fputs(Info::get_fmt_info().c_str(),fp);
|
||||
fputs(Info::get_json_info().c_str(),fp);
|
||||
|
||||
int major,minor;
|
||||
std::string infobuf = platform::mpi_info(major,minor);
|
||||
|
||||
22
src/main.cpp
22
src/main.cpp
@ -17,14 +17,12 @@
|
||||
#include "input.h"
|
||||
#include "library.h"
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <mpi.h>
|
||||
#include <new>
|
||||
|
||||
#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
|
||||
#include <fenv.h>
|
||||
#endif
|
||||
|
||||
// import MolSSI Driver Interface library
|
||||
#if defined(LMP_MDI)
|
||||
#include <mdi.h>
|
||||
@ -62,17 +60,6 @@ int main(int argc, char **argv)
|
||||
if (MDI_MPI_get_world_comm(&lammps_comm)) MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
#endif
|
||||
|
||||
#if defined(LAMMPS_TRAP_FPE) && defined(_GNU_SOURCE)
|
||||
// enable trapping selected floating point exceptions.
|
||||
// this uses GNU extensions and is only tested on Linux
|
||||
// therefore we make it depend on -D_GNU_SOURCE, too.
|
||||
fesetenv(FE_NOMASK_ENV);
|
||||
fedisableexcept(FE_ALL_EXCEPT);
|
||||
feenableexcept(FE_DIVBYZERO);
|
||||
feenableexcept(FE_INVALID);
|
||||
feenableexcept(FE_OVERFLOW);
|
||||
#endif
|
||||
|
||||
try {
|
||||
auto lammps = new LAMMPS(argc, argv, lammps_comm);
|
||||
lammps->input->file();
|
||||
@ -90,6 +77,11 @@ int main(int argc, char **argv)
|
||||
finalize();
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
exit(1);
|
||||
} catch (json::exception &je) {
|
||||
fprintf(stderr, "\nJSON library error %d: %s\n", je.id, je.what());
|
||||
finalize();
|
||||
MPI_Abort(MPI_COMM_WORLD, 1);
|
||||
exit(1);
|
||||
} catch (std::bad_alloc &ae) {
|
||||
fprintf(stderr, "C++ memory allocation failed: %s\n", ae.what());
|
||||
finalize();
|
||||
|
||||
1
third_party/README
vendored
Normal file
1
third_party/README
vendored
Normal file
@ -0,0 +1 @@
|
||||
This folder contains copies of third-party software
|
||||
24766
third_party/nlohmann/json.hpp
vendored
Normal file
24766
third_party/nlohmann/json.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -33,10 +33,6 @@ mark_as_advanced(SKIP_DEATH_TESTS)
|
||||
if(SKIP_DEATH_TESTS)
|
||||
add_compile_definitions(LAMMPS_SKIP_DEATH_TESTS)
|
||||
endif()
|
||||
# import
|
||||
foreach(_FLAG ${CMAKE_TUNE_FLAGS})
|
||||
add_compile_options(${_FLAG})
|
||||
endforeach()
|
||||
|
||||
# must repeat handling coverage for older CMake
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") AND ENABLE_COVERAGE)
|
||||
|
||||
@ -49,6 +49,10 @@ add_executable(test_fmtlib test_fmtlib.cpp)
|
||||
target_link_libraries(test_fmtlib PRIVATE lammps GTest::GMockMain)
|
||||
add_test(NAME FmtLib COMMAND test_fmtlib)
|
||||
|
||||
add_executable(test_json test_json.cpp)
|
||||
target_link_libraries(test_json PRIVATE lammps GTest::GMockMain)
|
||||
add_test(NAME JSON COMMAND test_json)
|
||||
|
||||
add_executable(test_math_eigen_impl test_math_eigen_impl.cpp)
|
||||
target_include_directories(test_math_eigen_impl PRIVATE ${LAMMPS_SOURCE_DIR})
|
||||
add_test(NAME MathEigen COMMAND test_math_eigen_impl 10 5)
|
||||
|
||||
78
unittest/utils/test_json.cpp
Normal file
78
unittest/utils/test_json.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS Development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using ::testing::Eq;
|
||||
|
||||
#define STRINGIFY(val) XSTR(val)
|
||||
#define XSTR(val) #val
|
||||
|
||||
// this tests a subset of the JSON class that is most relevant to LAMMPS
|
||||
|
||||
TEST(JSON, namespace)
|
||||
{
|
||||
std::string expected = "nlohmann_lmp::json_abi";
|
||||
expected += "_v" STRINGIFY(NLOHMANN_JSON_VERSION_MAJOR);
|
||||
expected += "_" STRINGIFY(NLOHMANN_JSON_VERSION_MINOR);
|
||||
expected += "_" STRINGIFY(NLOHMANN_JSON_VERSION_PATCH);
|
||||
|
||||
const std::string ns{STRINGIFY(NLOHMANN_JSON_NAMESPACE)};
|
||||
ASSERT_THAT(expected, Eq(ns));
|
||||
}
|
||||
|
||||
TEST(JSON, serialize_deserialize)
|
||||
{
|
||||
json j1;
|
||||
j1["pi"] = 3.141;
|
||||
j1["happy"] = true;
|
||||
j1["name"] = "Niels";
|
||||
j1["nothing"] = nullptr;
|
||||
|
||||
std::string expected = "{\"happy\":true,\"name\":\"Niels\",\"nothing\":null,\"pi\":3.141}";
|
||||
std::string dumped = j1.dump();
|
||||
ASSERT_THAT(expected, Eq(dumped));
|
||||
|
||||
json j2 = json::parse(expected);
|
||||
ASSERT_TRUE(j1 == j2);
|
||||
}
|
||||
|
||||
TEST(JSON, init_vs_incremental)
|
||||
{
|
||||
json j1;
|
||||
j1["pi"] = 3.141;
|
||||
j1["happy"] = true;
|
||||
j1["name"] = "Niels";
|
||||
j1["nothing"] = nullptr;
|
||||
j1["answer"]["everything"] = 42;
|
||||
j1["list"] = {1, 0, 2};
|
||||
j1["object"] = {{"currency", "USD"}, {"value", 42.99}};
|
||||
|
||||
json j2 = {{"pi", 3.141},
|
||||
{"happy", true},
|
||||
{"name", "Niels"},
|
||||
{"nothing", nullptr},
|
||||
{"answer", {{"everything", 42}}},
|
||||
{"list", {1, 0, 2}},
|
||||
{"object", {{"currency", "USD"}, {"value", 42.99}}}};
|
||||
|
||||
ASSERT_TRUE(j1 == j2);
|
||||
}
|
||||
Reference in New Issue
Block a user