[lammps-users] cmake lammps building

Dear developper,
I have install 27May 2021 using cmake on Centos 7.9 gcc version is 4.8.5
For enabling KOKKOS I need gcc version > 5
So I used devetoolset-8 for installing gcc-8.3.1-3
This is verified by checking gcc -v

[pascal@gremi27 ~] gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl= --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC) But making a simple build show that the default gcc 4.85 is selected: [pascal@gremi27 build] cmake -C …/cmake/presets/most.cmake -C …/cmake/presets/nolib.cmake …/cmake loading initial cache file …/cmake/presets/most.cmake loading initial cache file …/cmake/presets/nolib.cmake – Running check for auto-generated files from make-based build system – Could NOT find FFMPEG (missing: FFMPEG_EXECUTABLE) – Checking for module ‘fftw3’ – No package ‘fftw3’ found CMake Warning at CMakeLists.txt:507 (message): Plugin loading will not work unless BUILD_SHARED_LIBS is enabled – Generating style headers… – Generating package headers… – Generating lmpinstalledpkgs.h… – The following tools and libraries have been found and configured: * Git * MPI * OpenMP * PkgConfig – <<< Build configuration >>> Operating System: Linux CentOS Linux 7 Build type: RelWithDebInfo Install path: /home/pascal/.local Generator: Unix Makefiles using /usr/bin/gmake – Enabled packages: ASPHERE;BODY;CLASS2;COLLOID;CORESHELL;DIPOLE;GRANULAR;KSPACE;MANYBODY;MC;MISC;MLIAP;MOLECULE;OPT;PERI;PLUGIN;POEMS;QEQ;REPLICA;RIGID;SHOCK;SNAP;SPIN;SRD;USER-BOCS;USER-BROWNIAN;USER-CGDNA;USER-CGSDK;USER-COLVARS;USER-DIFFRACTION;USER-DPD;USER-DRUDE;USER-EFF;USER-FEP;USER-MEAMC;USER-MESODPD;USER-MISC;USER-MOFFF;USER-OMP;USER-PHONON;USER-REACTION;USER-REAXC;USER-SDPD;USER-SPH;USER-UEF;USER-YAFF – <<< Compilers and Flags: >>> – C++ Compiler: /usr/bin/c++ Type: GNU Version: 4.8.5 C++ Flags: -O2 -g -DNDEBUG Defines: LAMMPS_SMALLBIG;LAMMPS_MEMALIGN=64;LAMMPS_OMP_COMPAT=3;LAMMPS_GZIP;FFT_KISS;LMP_USER_OMP – Fortran Compiler: /usr/bin/f95 Type: GNU Version: 4.8.5 Fortran Flags: -O2 -g -DNDEBUG – C compiler: /usr/bin/cc Type: GNU Version: 4.8.5 C Flags: -O2 -g -DNDEBUG – <<< Linker flags: >>> – Executable name: lmp – Static library flags: – <<< MPI flags >>> – MPI_defines: MPICH_SKIP_MPICXX;OMPI_SKIP_MPICXX;_MPICC_H – MPI includes: /home/pascal/opt/openmpi/include – MPI libraries: /home/pascal/opt/openmpi/lib/libmpi.so; – <<< FFT settings >>> – Primary FFT lib: KISS – Using double precision FFTs – Using non-threaded FFTs – <<< Building Tools >>> – Configuring done – Generating done – Build files have been written to: /home/pascal/lammps-27May2021/build How can I force LAMMPS to use 8.3.1-3 version instead of 4.8.5 ? Best regards Pascal

As you can see from the configuration summary printed at the bottom, CMake does not pick up the “gcc” or “g++” executable by default, but is looking for a compiler called “c++”, “cc”, and “f95” by default. Those exist on your system and are obviously symbolic links to the older (system) GCC compiler.

Now you have three possible strategies to change that. 1) you add the corresponding symbolic links to your custom GCC installation or 2) you set the variables CMAKE_CXX_COMPILER=g++ CMAKE_C_COMPILER=gcc CMAKE_Fortran_COMPILER=gfortran when calling cmake to tell it that you favor these compilers.
3) you use the gcc.cmake preset that will do a similar thing as 2)

Axel.

Thanks alot Axel
Best regrads
Pascal

As you can see from the configuration summary printed at the bottom, CMake does not pick up the “gcc” or “g++” executable by default, but is looking for a compiler called “c++”, “cc”, and “f95” by default. Those exist on your system and are obviously symbolic links to the older (system) GCC compiler.

Now you have three possible strategies to change that. 1) you add the corresponding symbolic links to your custom GCC installation or 2) you set the variables CMAKE_CXX_COMPILER=g++ CMAKE_C_COMPILER=gcc CMAKE_Fortran_COMPILER=gfortran when calling cmake to tell it that you favor these compilers.
3) you use the gcc.cmake preset that will do a similar thing as 2)

Axel.

Dear Axel,
Last June you helped in giving me the way to build LAMMPS with installed GNU gcc11.
I try now to install KOKKOS following your recommendations.

$ cmake -C ../cmake/presets/gcc.cmake ../cmake/presets/most.cmake -C ../cmake/presets/nolib.cmake -D Kokkos_ARCH_SKX=yes -D Kokkos_ENABLE_OPENMP=yes -D BUILD_OMP=yes ../cmake

But an error message follows about OpenMP.
It seems that a library is missing, but I do know how to install it.
the error message is below.

This library should be included with the compiler. You can try adding to the cmake command line (with the correct path):
-DOpenMP_gomp_LIBRARY=/path/to/compiler/lib/libgomp.so

Dear Axel
Thanks a lot
I will try and answer you when successful
Best
Pascal

This library should be included with the compiler. You can try adding to the cmake command line (with the correct path):
-DOpenMP_gomp_LIBRARY=/path/to/compiler/lib/libgomp.so

Dear Axel

Thanks a lot again. In fact Centos is building a lib64 library instead of lib (which exists but without the relevant files).
So I have run the command

cmake -C…/cmake/presets/gcc.cmake …/cmake/presets/most.cmake -C …/cmake/presets/nolib.cmake -D OpenMP_gomp_LIBRARY=$HOME/opt/gcc-11.1.0/lib64/libgomp.so -D Kokkos_ARCH_SKX=yes -D Kokkos_ENABLE_OPENMP=yes -D BUILD_OMP=yes …/cmake

with the message

No, a missing clang-format has no negative effect. Your problem is that you are providing Kokkos configuration settings but did not enable any packages, and specifically not the KOKKOS package.

Sure I forget the main part !!!
Thus it should be better like this:
But KOKKOS does not appear in the "The following tools and libraries have been found and configured" section.
Only the warning :
Manually-specified variables were not used by the project:

KOKKOS
Thanks a lot for your help.
Best regards
Pascal

cmake -C../cmake/presets/gcc.cmake ../cmake/presets/most.cmake -C ../cmake/presets/nolib.cmake -D OpenMP_gomp_LIBRARY=$HOME/opt/gcc-11.1.0/lib64/libgomp.so -D KOKKOS=yes -D Kokkos_ARCH_SKX=yes -D Kokkos_ENABLE_OPENMP=yes -D BUILD_OMP=yes ../cmake

loading initial cache file ../cmake/presets/gcc.cmake
loading initial cache file ../cmake/presets/nolib.cmake
-- Running check for auto-generated files from make-based build system
-- Looking for C++ include omp.h
-- Looking for C++ include omp.h - found
-- Generating style headers...
-- Generating package headers...
-- Generating lmpinstalledpkgs.h...
-- Could NOT find ClangFormat (missing: ClangFormat_EXECUTABLE) (Required is at least version "8.0")
-- The following tools and libraries have been found and configured:
* Git
* MPI
* OpenMP

-- <<< Build configuration >>>
Operating System: Linux CentOS Linux 7
Build type: RelWithDebInfo
Install path: /home/pascal/.local
Generator: Unix Makefiles using /usr/bin/gmake
-- Enabled packages: <None>
-- <<< Compilers and Flags: >>>
-- C++ Compiler: /home/pascal/opt/gcc-11.1.0/bin/g++
Type: GNU
Version: 11.1.0
C++ Flags: -g -O2 -DNDEBUG
Defines: LAMMPS_SMALLBIG;LAMMPS_MEMALIGN=64;LAMMPS_OMP_COMPAT=4;LAMMPS_GZIP;LAMMPS_FFMPEG
-- <<< Linker flags: >>>
-- Executable name: lmp
-- Static library flags:
-- <<< MPI flags >>>
-- MPI_defines: MPICH_SKIP_MPICXX;OMPI_SKIP_MPICXX;_MPICC_H
-- MPI includes: /home/pascal/opt/openmpi/include
-- MPI libraries: /home/pascal/opt/openmpi/lib/libmpi.so;
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:

KOKKOS
.

It should not unless you enable the KOKKOS package. There are plenty of explanations in the manual how to correctly compile LAMMPS. That is what matters. You are not following them.

Hi Pascal,

You would need to comment out the KOKKOS line in nolib.cmake. See below.
However, if the dependencies for the Kokkos package are not already installed, LAMMPS will start to complain about those.
nolib.cmake includes all the packages that have external library dependencies and when you use that to configure the build it skips those packages.

Hope this helps…

Regards,
Vaibhav.

Dear Axel,
I go further in the documentation and use kokkos OpenMP preset
and the i run and obtain (I guess it is successful this time ?)

Hi Pascal,

You would need to comment out the KOKKOS line in nolib.cmake. See below.
However, if the dependencies for the Kokkos package are not already installed, LAMMPS will start to complain about those.
nolib.cmake includes all the packages that have external library dependencies and when you use that to configure the build it skips those packages.

That is a very good point. In fact, there is no reason to use the “nolib” preset with CMake builds. Like the “all” presets, this was added to mirror the corresponding settings in the traditional make build system, but since in the CMake build the compilation of the the bundled libraries is included in the main build and does not require separate compilation steps, there is no value in using the nolib preset. The CMake configuration will either include and compile the library in the build process, download/configure/build external libraries or fail at the configuration step, if a prerequisite is not available. This has multiple historical reasons and not all of them still apply. Also the way how CMake is used with LAMMPS has evolved significantly. Initially, the traditional make based approach was more flexible and supported more features. But that situation has changed over the years, now there are many features in compiling LAMMPS (like unit testing) that are only available via CMake and very few limitations where the traditional make has an advantage over using CMake. In fact, the only limitation I can think of is that the bundled Kokkos library requires a more recent CMake version to compile than LAMMPS does. We try to stay compatible with RHEL/CentOS 7 and Ubuntu 18.04LTS and thus try to be compatible with CMake 3.10 and later while Kokkos now requires 3.16. Requiring CMake 3.16 would allow us to simplify the CMake scripting in multiple places, but we don’t want to go that route until RHEL/CentOS 7 and Ubuntu 18.04LTS are much less commonly used (which may take another couple of years or so, and at that point we likely also raise the minimum C++ version required as well).

So a good strategy to build LAMMPS is usually:

  • first try to build without any packages enabled to validate that the compiler and build environment work and check with the LJ benchmark to see if it runs
  • from there on it depends on whether you want to build a LAMMPS package with as many packages enabled as possible or one that has just what you need. In the former case you can (safely) use the “most” preset (or make yes-most in traditional make), in the latter case you would use the “basic” preset (or make yes-basic). Please note that the “most” preset is different for the two build systems since the traditional make version skips any packages with libraries as those require additional steps.
  • Once you have a “safe” version of LAMMPS with packages included, you can now look to enable additional packages that are not included in any presets. KOKKOS is a special case there, because of its complexity to build and the fact that the Kokkos library is bundled but also needs to be configured. in that case we have a few presets we use for automated compilation testing, that you may adjust and use, or just follow the documentation and create a custom setup.

Axel.

Thanks a lot Axel

I will start from the beginning as you clearly explain. Forget my previous email with the kokkos preset.
Best regards

Pascal

Dear Axel,
I have remove the nolib.cmake preset I keep the most.cmake since it include the various package I use. But when compiling the error
– Checking for module ‘fftw3’
– No package ‘fftw3’ found
But fftw3 libraries are installed and accessible in usr/lib64 . Is the problem that LAMMPS only searchs for it in usr/lib ?

There is also a Python error. But it comes from CEntos 7 which has python 2.7 and this should be upgraded.
Best
Pascal

The messages are below
cmake -C…/cmake/presets/gcc.cmake -C …/cmake/presets/most.cmake -C …/cmake/presets/kokkos-openmp.cmake -D OpenMP_gomp_LIBRARY=$HOME/opt/gcc-11.1.0/lib64/libgomp.so -D KOKKOS=yes -D Kokkos_ARCH_SKX=yes -D Kokkos_ENABLE_OPENMP=yes -D BUILD_OMP=yes …/cmake

loading initial cache file …/cmake/presets/gcc.cmake
loading initial cache file …/cmake/presets/most.cmake
loading initial cache file …/cmake/presets/kokkos-openmp.cmake
– The CXX compiler identification is GNU 11.1.0
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /home/pascal/opt/gcc-11.1.0/bin/g++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Found Git: /usr/local/bin/git (found version “2.28.0”)
– Running check for auto-generated files from make-based build system
– Found MPI_CXX: /home/pascal/opt/openmpi/lib/libmpi.so (found version “3.1”)
– Found MPI: TRUE (found version “3.1”)
– Looking for C++ include omp.h
– Looking for C++ include omp.h - found
– Found OpenMP_CXX: -fopenmp (found version “4.5”)
– Found OpenMP: TRUE (found version “4.5”)
– Found GZIP: /usr/bin/gzip
– Found FFMPEG: /usr/bin/ffmpeg
– Found PkgConfig: /usr/bin/pkg-config (found version “0.27.1”)
– Checking for module ‘fftw3’
– No package ‘fftw3’ found
CMake Error at /usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
Could NOT find Python (missing: Python_INCLUDE_DIRS Python_LIBRARIES
Development Development.Module Development.Embed)
Call Stack (most recent call first):
/usr/local/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.19/Modules/FindPython.cmake:470 (find_package_handle_standard_args)
Modules/Packages/PYTHON.cmake:6 (find_package)
CMakeLists.txt:445 (include)

– Configuring incomplete, errors occurred!
See also “/home/pascal/lammps-29Sep2021/build/CMakeFiles/CMakeOutput.log”.

Having the fftw library itself installed is a necessary but not the only requirement. It is sufficient to run executables.
To compile you also need the corresponding development package (fftw-devel) which has the include files and the symbolic links required for linking.
That said, compiling LAMMPS with the fallback KISS fft is just fine and will rarely make a significant difference. The importance of an optimized FFT for classical MD is often overestimated and that is increasingly true as on modern CPUs the limiting factor is less the time spent on computation, but the time spent on moving and accessing data.
Example. If I run the rhodo benchmark on my desktop with `kspace_modify fftbench yes’ added. I can see that ~11% of the total time is spent in the Kspace style and only 5% of that time on computing the FFTs. Then even if KISS FFT would be 20% slower than FFTW3 the impact on the total time would be around 0.1%. The importance of optimizing access to data structures can be far more significant. if I run the same input on the same machine with the same executable with adding: -sf omp -pk omp 1
i.e. use the styles from the OPENMP package but without using threads, I see more than 10% improvement (mostly on Pair, which is the dominant term).

The issue for Python is the same. Python 2.7 is supported by LAMMPS for the PYTHON package, but you must have the corresponding development package installed as well to compile the PYTHON package. The error message clearly indicates that this is missing (otherwise it would complain about the missing interpreter as well).

axel.

Thanks a lot for the detailed explanation and information.

Warm regards,
Vaibhav.

Dear Axel
First of all, I warmly thank you for all the time you spent for helping me.
All issues were solved by installing python-devel and fftw-devel packages in Centos 7. There were not installed by default.
See attached cmake command and diagnostics (Kokkos_CMake-build.txt) as well as output of bench/in.lj test (Kokkos-test_inlj.txt). There is a warning for improving KOKKOS performance but I do not know how to implement it. Is it through -D OMP_PROC_BIND=spread -D OMP_PLACES=threads (OpenMP 4.5 here) in the cmake building ?
Thanks a lot again.

See attached cmake command and diagnostics (Kokkos_CMake-build.txt) as well as output of bench/in.lj test (Kokkos-test_inlj.txt). There is a warning for improving KOKKOS performance but I do not know how to implement it. Is it through -D OMP_PROC_BIND=spread -D OMP_PLACES=threads (OpenMP 4.5 here) in the cmake building ?

No. Those are environment variables that matter at runtime. Those are not compile time settings. Try using google to find the corresponding OpenMP documentation.

Axel.