Unverified Commit b0e067ba authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

Merge branch 'master' into progguide

# Conflicts:
#	doc/utils/sphinx-config/false_positives.txt
parents 727264b7 f35d517a
Loading
Loading
Loading
Loading
+46 −20
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ check_for_autogen_files(${LAMMPS_SOURCE_DIR})
# compiler tests
# these need ot be done early (before further tests).
#####################################################################
include(CheckCCompilerFlag)
include(CheckIncludeFileCXX)

# set required compiler flags and compiler/CPU arch specific optimizations
@@ -83,15 +82,6 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# GNU compiler specific features for testing
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  option(ENABLE_COVERAGE "Enable collecting code coverage data" OFF)
  mark_as_advanced(ENABLE_COVERAGE)
  if(ENABLE_COVERAGE)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
  endif()
endif()

########################################################################
# User input options                                                   #
########################################################################
@@ -122,8 +112,8 @@ install(TARGETS lmp EXPORT LAMMPS_Targets DESTINATION ${CMAKE_INSTALL_BINDIR})
option(CMAKE_VERBOSE_MAKEFILE "Generate verbose Makefiles" OFF)

set(STANDARD_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS DIPOLE
  GRANULAR KSPACE LATTE MANYBODY MC MESSAGE MISC MOLECULE PERI POEMS QEQ
  REPLICA RIGID SHOCK SPIN SNAP SRD KIM PYTHON MSCG MPIIO VORONOI
  GRANULAR KSPACE LATTE MANYBODY MC MESSAGE MISC MLIAP MOLECULE PERI POEMS
  QEQ REPLICA RIGID SHOCK SPIN SNAP SRD KIM PYTHON MSCG MPIIO VORONOI
  USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-MESODPD USER-CGSDK USER-COLVARS
  USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF USER-FEP USER-H5MD USER-LB
  USER-MANIFOLD USER-MEAMC USER-MESONT USER-MGPT USER-MISC USER-MOFFF USER-MOLFILE
@@ -210,6 +200,7 @@ endif()

# "hard" dependencies between packages resulting
# in an error instead of skipping over files
pkg_depends(MLIAP SNAP)
pkg_depends(MPIIO MPI)
pkg_depends(USER-ATC MANYBODY)
pkg_depends(USER-LB MPI)
@@ -248,6 +239,48 @@ if(BUILD_OMP)
  target_link_libraries(lammps PRIVATE OpenMP::OpenMP_CXX)
endif()

# Compiler specific features for testing
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
  option(ENABLE_COVERAGE "Enable collecting code coverage data" OFF)
  mark_as_advanced(ENABLE_COVERAGE)
  if(ENABLE_COVERAGE)
    if(CMAKE_VERSION VERSION_LESS 3.13)
      if(CMAKE_CXX_FLAGS)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
      else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_${CMAKE_BUILD_TYPE}_FLAGS} --coverage")
      endif()
    else()
      target_compile_options(lammps PUBLIC --coverage)
      target_link_options(lammps PUBLIC --coverage)
    endif()
  endif()
endif()

set(ENABLE_SANITIZER "none" CACHE STRING "Select a code sanitizer option (none (default), address, thread, undefined)")
mark_as_advanced(ENABLE_SANITIZER)
set(ENABLE_SANITIZER_VALUES none address thread undefined)
set_property(CACHE ENABLE_SANITIZER PROPERTY STRINGS ${ENABLE_SANITIZER_VALUES})
validate_option(ENABLE_SANITIZER ENABLE_SANITIZER_VALUES)
string(TOLOWER ${ENABLE_SANITIZER} ENABLE_SANITIZER)
if(NOT ENABLE_SANITIZER STREQUAL "none")
  if((${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang"))
    if(CMAKE_VERSION VERSION_LESS 3.13)
      if(CMAKE_CXX_FLAGS)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=${ENABLE_SANITIZER}")
      else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_${CMAKE_BUILD_TYPE}_FLAGS} -fsanitize=${ENABLE_SANITIZER}")
      endif()
    else()
      target_compile_options(lammps PUBLIC -fsanitize=${ENABLE_SANITIZER})
      target_link_options(lammps PUBLIC -fsanitize=${ENABLE_SANITIZER})
    endif()
  else()
    message(WARNING "ENABLE_SANITIZER option not supported by ${CMAKE_CXX_COMPILER_ID} compilers. Ignoring.")
    set(ENABLE_SANITIZER "none")
  endif()
endif()

if(PKG_MSCG OR PKG_USER-ATC OR PKG_USER-AWPMD OR PKG_USER-QUIP OR PKG_LATTE)
  enable_language(C)
  find_package(LAPACK)
@@ -335,15 +368,8 @@ endforeach()

set(CMAKE_TUNE_FLAGS "${CMAKE_TUNE_DEFAULT}" CACHE STRING "Compiler specific optimization or instrumentation")
separate_arguments(CMAKE_TUNE_FLAGS)
include(CheckCXXCompilerFlag)
foreach(_FLAG ${CMAKE_TUNE_FLAGS})
  string(REGEX REPLACE "[=\"]" "" _FLAGX ${_FLAG})
  check_cxx_compiler_flag("${_FLAG}" COMPILER_SUPPORTS${_FLAGX})
  if(COMPILER_SUPPORTS${_FLAGX})
  target_compile_options(lammps PRIVATE ${_FLAG})
  else()
    message(WARNING "${_FLAG} found in CMAKE_TUNE_FLAGS, but not supported by the compiler, skipping")
  endif()
endforeach()
########################################################################
# Basic system tests (standard libraries, headers, functions, types)   #
+8 −25
Original line number Diff line number Diff line
@@ -14,40 +14,23 @@ endif()
option(DOWNLOAD_SCAFACOS "Download ScaFaCoS library instead of using an already installed one" ${DOWNLOAD_SCAFACOS_DEFAULT})
if(DOWNLOAD_SCAFACOS)
  message(STATUS "ScaFaCoS download requested - we will build our own")
  # create variables to pass our compiler flags along to the subsystem compile
  # need to apply -fallow-argument-mismatch, if the fortran compiler supports it
  include(CheckFortranCompilerFlag)
  check_fortran_compiler_flag("-fallow-argument-mismatch" GNUFortran_ARGUMENT_MISMATCH_FLAG)
  if(GNUFortran_ARGUMENT_MISMATCH_FLAG)
    set(APPEND_Fortran_FLAG "-fallow-argument-mismatch")
  endif()
  if(CMAKE_Fortran_FLAGS)
    set(SCAFACOS_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${APPEND_Fortran_FLAG}")
  else()
    set(SCAFACOS_Fortran_FLAGS "${CMAKE_Fortran_${CMAKE_BUILD_TYPE}_FLAGS} ${APPEND_Fortran_FLAG}")
  endif()
  if(CMAKE_CXX_FLAGS)
      set(SCAFACOS_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
      set(SCAFACOS_CXX_FLAGS "${CMAKE_CXX_${CMAKE_BUILD_TYPE}_FLAGS}")
  endif()
  if(CMAKE_C_FLAGS)
      set(SCAFACOS_C_FLAGS "${CMAKE_C_FLAGS}")
    else()
      set(SCAFACOS_C_FLAGS "${CMAKE_C_${CMAKE_BUILD_TYPE}_FLAGS}")
  endif()

  # version 1.0.1 needs a patch to compile and linke cleanly with GCC 10 and later.
  file(DOWNLOAD https://download.lammps.org/thirdparty/scafacos-1.0.1-fix.diff ${CMAKE_CURRENT_BINARY_DIR}/scafacos-1.0.1.fix.diff
          EXPECTED_HASH MD5=4baa1333bb28fcce102d505e1992d032)

  include(ExternalProject)
  ExternalProject_Add(scafacos_build
    URL https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz
    URL_MD5 bd46d74e3296bd8a444d731bb10c1738
    PATCH_COMMAND patch -p1 < ${CMAKE_CURRENT_BINARY_DIR}/scafacos-1.0.1.fix.diff
    CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --disable-doc
                                             --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m
                                             --with-internal-fftw --with-internal-pfft
                                             --with-internal-pnfft ${CONFIGURE_REQUEST_PIC}
                                             FC=${CMAKE_MPI_Fortran_COMPILER} FCFLAGS=${SCAFACOS_Fortran_FLAGS}
                                             CXX=${CMAKE_MPI_CXX_COMPILER} CXXFLAGS=${SCAFACOS_CXX_FLAGS}
                                             CC=${CMAKE_MPI_C_COMPILER} CFLAGS=${SCAFACOS_C_FLAGS}
                                             FC=${CMAKE_MPI_Fortran_COMPILER}
                                             CXX=${CMAKE_MPI_CXX_COMPILER}
                                             CC=${CMAKE_MPI_C_COMPILER}
                                             F77=
    BUILD_BYPRODUCTS
      <INSTALL_DIR>/lib/libfcs.a
+2 −2
Original line number Diff line number Diff line
set(WIN_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE GPU
                 GRANULAR KSPACE LATTE MANYBODY MC MISC MOLECULE OPT PERI
                 POEMS QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI
                 GRANULAR KSPACE LATTE MANYBODY MC MISC MLIAP MOLECULE OPT
                 PERI POEMS QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI
                 USER-ATC USER-AWPMD USER-BOCS USER-CGDNA USER-CGSDK
                 USER-COLVARS USER-DIFFRACTION USER-DPD USER-DRUDE USER-EFF
                 USER-FEP USER-INTEL USER-MANIFOLD USER-MEAMC USER-MESODPD
+2 −2
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
# external libraries. Compared to all_on.cmake some more unusual packages
# are removed. The resulting binary should be able to run most inputs.

set(ALL_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL
        DIPOLE GRANULAR KSPACE MANYBODY MC MISC MOLECULE OPT PERI
set(ALL_PACKAGES ASPHERE BODY CLASS2 COLLOID COMPRESS CORESHELL DIPOLE
        GRANULAR KSPACE MANYBODY MC MISC MLIAP MOLECULE OPT PERI
        POEMS PYTHON QEQ REPLICA RIGID SHOCK SNAP SPIN SRD VORONOI
        USER-BOCS USER-CGDNA USER-CGSDK USER-COLVARS USER-DIFFRACTION
        USER-DPD USER-DRUDE USER-EFF USER-FEP USER-MEAMC USER-MESODPD
+64 −22
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@ useful during development, testing or debugging.

.. _compilation:

Verify compilation flags
------------------------
Monitor compilation flags
-------------------------

Sometimes it is necessary to verify the complete sequence of compilation flags
generated by the CMake build. To enable a more verbose output during
@@ -19,7 +19,8 @@ compilation you can use the following option.

   -D CMAKE_VERBOSE_MAKEFILE=value    # value = no (default) or yes

Another way of doing this without reconfiguration is calling make with variable VERBOSE set to 1:
Another way of doing this without reconfiguration is calling make with
variable VERBOSE set to 1:

.. code-block:: bash

@@ -33,25 +34,26 @@ Address, Undefined Behavior, and Thread Sanitizer Support
---------------------------------------------------------

Compilers such as GCC and Clang support generating instrumented binaries
which use different sanitizer libraries to detect problems in code
which use different sanitizer libraries to detect problems in the code
during run-time. They can detect issues like:

 - `memory leaks <https://clang.llvm.org/docs/AddressSanitizer.html>`_
 - `undefined behavior <https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html>`_
 - `data races <https://clang.llvm.org/docs/ThreadSanitizer.html>`_

Please note that this kind of instrumentation usually comes with a small
performance hit (much less than using tools like `Valgrind
<https://valgrind.org>`_).  The to enable these features additional
compiler flags need to be added to the compilation and linking stages.
This is most easily done through setting the ``CMAKE_TUNE_FLAGS``
variable during configuration. Examples:
Please note that this kind of instrumentation usually comes with a
performance hit (but much less than using tools like `Valgrind
<https://valgrind.org>`_ with a more low level approach).  The to enable
these features additional compiler flags need to be added to the
compilation and linking stages.  This is done through setting the
``ENABLE_SANITIZER`` variable during configuration. Examples:

.. code-block:: bash

   -D CMAKE_TUNE_FLAGS=-fsanitize=address    # enable address sanitizer / memory leak checker
   -D CMAKE_TUNE_FLAGS=-fsanitize=undefined  # enable undefined behavior sanitizer
   -D CMAKE_TUNE_FLAGS=-fsanitize=thread     # enable thread sanitizer
   -D ENABLE_SANITIZER=none       # no sanitizer active (default)
   -D ENABLE_SANITIZER=address    # enable address sanitizer / memory leak checker
   -D ENABLE_SANITIZER=undefined  # enable undefined behavior sanitizer
   -D ENABLE_SANITIZER=thread     # enable thread sanitizer

----------

@@ -86,19 +88,21 @@ The output of this command will be looking something like this::
   [...]$ ctest
   Test project /home/akohlmey/compile/lammps/build-testing
         Start  1: MolPairStyle:hybrid-overlay
    1/26 Test  #1: MolPairStyle:hybrid-overlay .........   Passed    0.02 sec
   1/109 Test  #1: MolPairStyle:hybrid-overlay .........   Passed    0.02 sec
         Start  2: MolPairStyle:hybrid
    2/26 Test  #2: MolPairStyle:hybrid .................   Passed    0.01 sec
   2/109 Test  #2: MolPairStyle:hybrid .................   Passed    0.01 sec
         Start  3: MolPairStyle:lj_class2
    [...]
         Start 25: AngleStyle:harmonic
   25/26 Test #25: AngleStyle:harmonic .................   Passed    0.01 sec
         Start 26: AngleStyle:zero
   26/26 Test #26: AngleStyle:zero .....................   Passed    0.01 sec
         Start 107: PotentialFileReader
 107/109 Test #107: PotentialFileReader ................   Passed    0.04 sec
         Start 108: EIMPotentialFileReader
 108/109 Test #108: EIMPotentialFileReader .............   Passed    0.03 sec
         Start 109: TestSimpleCommands
 109/109 Test #109: TestSimpleCommands .................   Passed    0.02 sec

   100% tests passed, 0 tests failed out of 26

   Total Test time (real) =   0.27 sec
   Total Test time (real) =  25.57 sec


The ``ctest`` command has many options, the most important ones are:
@@ -193,8 +197,8 @@ In this particular case, 5 out of 6 sets of tests were conducted, the
tests for the ``lj/cut/opt`` pair style was skipped, since the tests
executable did not include it.  To learn what individual tests are performed,
you (currently) need to read the source code.  You can use code coverage
recording (see next section) to confirm how well the tests cover the individual
source files.
recording (see next section) to confirm how well the tests cover the code
paths in the individual source files.

The force style test programs have a common set of options:

@@ -211,6 +215,14 @@ The force style test programs have a common set of options:
   * - -v
     - verbose output: also print the executed LAMMPS commands

The ``ctest`` tool has no mechanism to directly pass flags to the individual
test programs, but a workaround has been implemented where these flags can be
set in an environment variable ``TEST_ARGS``. Example:

.. code-block:: bash

   env TEST_ARGS=-s ctest -V -R BondStyle

To add a test for a style that is not yet covered, it is usually best
to copy a YAML file for a similar style to a new file, edit the details
of the style (how to call it, how to set its coefficients) and then
@@ -244,6 +256,16 @@ and working.
     of mis-compiled code (or an undesired large loss of precision due
     to significant reordering of operations and thus less error cancellation).

Tests for other components and utility functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Additional tests that validate utility functions or specific components
of LAMMPS are implemented as standalone executable which may, or may not
require creating a suitable LAMMPS instance.  These tests are more specific
and do not require YAML format input files.  To add a test, either an
existing source file needs to be extended or a new file added, which in turn
requires additions to the ``CMakeLists.txt`` file in the source folder.

Collect and visualize code coverage metrics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@@ -306,3 +328,23 @@ The images below illustrate how the data is presented.
             :target: JPG/coverage-file-branches.png

          Source page with branches

Coding style utilities
----------------------

To aid with enforcing some of the coding style conventions in LAMMPS
some additional build targets have been added. These require Python 3.5
or later and will only work on Unix-like operating and file systems.
The following options are available.

.. code-block:: bash

   make check-whitespace    # generate coverage report in HTML format
   make fix-whitespace      # generate coverage report in XML format
   make check-permissions   # delete folder with HTML format coverage report
   make fix-permissions     # delete all collected coverage data and HTML output

For the code in the ``unittest`` tree we are using the `clang-format`
tool (Clang version 8.0 or later is required). If available, the source
code files in the ``unittest`` tree can be updated to conform to the
formatting settings using ``make format-tests``.
Loading