In this appendix, we will give a brief tutorial on how to build LAMMPS with CMake. Unlike the traditional Makefile, CMake can detect available hardware, tools, features, and libraries and adjust the LAMMPS default build configuration accordingly. CMake allows customized settings with a text mode or graphical user interface, without requiring any knowledge of file formats or complex command-line syntax. In addition, CMake can automate dependency tracking for all files and configuration options.
To execute the instructions in this chapter, you need a platform to compile LAMMPS (for example, a Linux Terminal).
Before we start working with LAMMPS, we need to get a few things up and running for hassle-free execution:
We'll look at the preceding points in the following sections.
You can download the LAMMPS source code from GitHub by entering the following command in the terminal:
git clone https://github.com/lammps/lammps.git
If, instead, the source code is downloaded from other sources (for example, the LAMMPS download page at https://lammps.sandia.gov/download.html), please make sure to unzip accordingly.
The following commands will install the necessary components (use sudo before each apt command if required):
apt install build-essential
apt install cmake
apt install gfortran
apt update
apt upgrade
As the preceding components are being installed, progress will be displayed on the terminal screen. As for the Fast Fourier Transform package, if there is no third-party package detected on the machine, CMake will use the embedded KISS FFT library by default.
To enable parallel computation of LAMMPS and communication among the cores and nodes, a framework or Message Passing Interface (MPI) is needed. MPICH is a high performance and widely portable implementation of the MPI standard. The required source code can be downloaded directly from the terminal by entering this:
sudo apt install mpich
Alternatively, the source code can be downloaded using the instructions provided on the official site (www.mpich.org) and has to be decompressed and built:
tar -zxvf mpich3.tar.gz
./configure –enable-shared=yes
In the preceding command, the --enable-shared=yes option is necessary to build a library. The final command is to complete the make:
make && make install
Once MPICH has been installed, LAMMPS can be built with parallel processing capabilities. Otherwise, LAMMPS can only be built to process in serial with a single processor.
When building LAMMPS, an additional folder should be set up to temporarily store configuration files. In LAMMPS, CMake supports out-of-source compilation, and multiple configurations containing different choices of LAMMPS packages, settings, or compilers can be created in other folders outside the source.
In the folder where the LAMMPS source code has been downloaded and unzipped, enter the following command to access the relevant folder:
cd lammps
Then, a new build folder can be created to store different configurations:
mkdir build
This folder can then be accessed with the following command:
cd build
Once accessed, the rest of the installation process can be continued inside it.
When building LAMMPS, the source code in the src folder is automatically selected for compilation. The optional packages can be included or excluded as required. The selected packages will influence the compilation time and the size of the executable, and in general, there is no need to include a package if you do not plan to use its features. In the lammps/cmake/presets folder, CMake provides a list of pre-configuration files that are used in common simulation scenarios.
The following screenshot shows the preset file, minimal.cmake, which activates a few commonly used packages for fast compilation:
As you can see, on line 4, an ALL_PACKAGES variable is created that contains four packages (KSPACE, MANYBODY, MOLECULE, and RIGID). In lines 6 to 8, the packages are iteratively activated via a loop. More packages can be included by adding to the set command.
Other preset files activate other combinations of packages, such as most.cmake, as shown in the next screenshot:
As you can see, this file lists a longer collection of packages to activate (line 5). Other preset files include all_on.cmake, which activates all existing packages, and all_off.cmake, which deactivates all existing packages to reset.
The required preset file can be called when compiling LAMMPS, as will be explained later in this section.
CMake automatically builds the source code files that start with pair_, fix_, compute_, and so on. When compiling, custom-written source code files will be automatically included if they are preceded by these terms. If not, the filenames have to be added to the appropriate style header file in the src folder. The full list of automatically detected terms is available in StyleHeaderUtils.cmake, located in the lammps/cmake/modules/ folder.
By default, CMake automatically selects a compiler based on internal preferences and it will add optimization flags as appropriate. Here is a list of advanced flags that are empty by default and can be modified by the user before compilation:
-D CMAKE_TUNE_FLAGS=value
-D CMAKE_CXX_COMPILER=name
-D CMAKE_C_COMPILER=name
-D CMAKE_Fortran_COMPILER=name
-D CMAKE_CXX_FLAGS=string
-D CMAKE_C_FLAGS=string
-D CMAKE_Fortran_FLAGS=string
-D CMAKE_INSTALL_PREFIX=path
-D CMAKE_BUILD_TYPE=value
-D LAMMPS_MACHINE=string
More information about CMake flags can be found in the LAMMPS manual (https://lammps.sandia.gov/doc/Howto_cmake.html).
As an example, the following command installs the packages in the minimal.cmake preset file and prepares a compiled executable file called lmp_test:
cmake -C ../cmake/presets/minimal.cmake -D LAMMPS_MACHINE=test -D CMAKE_BUILD_TYPE=Debug ../cmake
A summary of build configurations is provided on the screen, as shown in the following screenshot:
As you can see, if the settings displayed are satisfactory, the build can be commenced with the make command:
make
The preceding step creates the executable file that can be used to run LAMMPS scripts. Every time a modification is made to the source code, cleaning via the make clean command followed by recompilation are required to create a new executable that registers the modification.
Important Note:
It should be noted that depending on machine configurations (for example, standalone or HPC clusters) and/or the operating system used, the preceding steps may not compile LAMMPS properly. In such cases, it is advisable to web search for specific solutions or to contact the appropriate support staff.
This section describes a LAMMPS compilation in a Linux environment. In the next section, we will describe a LAMMPS compilation in Windows.
In this section, the procedure to build LAMMPS in Windows using CMake is detailed. Before beginning, please make sure to update Windows to its latest version.
First, the source code needs to be downloaded and CMake for Windows needs to be installed. The source code can be downloaded using Git for Windows, as described next.
You can download Git from the link: https://git-scm.com/downloads.
Once downloaded and installed, Git for Windows can be used to download the LAMMPS source code as described in the next section.
You can download the LAMMPS source code from GitHub with the following command in Windows Command Prompt or PowerShell:
git clone https://github.com/lammps/lammps.git
Alternatively, you can download the zipped file from the official LAMMPS GitHub repository: https://github.com/lammps/lammps.
The following screenshot shows the downloaded .zip file from the aforementioned link:
Unzip the zipped file, lammps-master.zip, in your desired directory, which we will refer to as LAMMPS_DIR in the following instructions.
Next, we outline the installation of CMake for Windows.
You can download CMake for Windows from the following link: https://cmake.org/download
Download the installer suitable for your platform and install it, as shown in the following screenshot:
Once completed, you will have access to the source code and CMake for Windows. The instructions in the following section will describe the installation of MPI to facilitate parallel processing and Codeblocks to provide an Integrated Development Environment (IDE).
You can download MS-MPI from the following link: https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi.
Important Note:
Please note that MS-MPI is only required if you want to run LAMMPS on multiple parallel processes (similar to MPICH).
The following screenshot shows the downloadable versions available:
Download both msmpisetup.exe and msmpisdk.msi, and install them.
You can download Codeblocks with MinGW (for example, codeblocks-20.03mingw-setup.exe) from the following link: http://www.codeblocks.org/downloads/binaries
MinGW refers to Minimalist GNU for Windows, so installing Codeblocks with MinGW will include the GCC/G++/GFortran compiler and the GDB debugger, which will allow you to build LAMMPS with more convenience.
Having completed the preceding prerequisite installations, we move on to building LAMMPS using these tools.
We follow these steps to start building LAMMPS:
In the preceding screenshot, the folder that contains the source code (that is, LAMMPS_DIR) for this particular example is the I:/lammps folder entered in the two boxes at the top.
As you can see, packages can be selected by checking their corresponding boxes under the Value column. However, some packages may require additional steps, for example, BUILD_DOC, PKG_KOKKOS, and PKG_LATTE, for which the LAMMPS manual (https://lammps.sandia.gov/doc/Build_extras.html) should be consulted.
Tip:
For a minimal installation, the default selection of packages can be used.
As demonstrated, after successful compilation you may notice the message Process terminated with status 0 and 0 error(s) in the Build log at the bottom. Concurrently, an executable file titled lmp.exe is generated in the build directory of the LAMMPS folder, LAMMPS_DIR.
This executable can be used to run a LAMMPS script from Command Prompt. Also, you can add the location of lmp.exe in the user or system path variable to access it from anywhere in the system. To set LAMMPS as a user path variable, open Command Prompt, and type the following:
setx PATH "LAMMPS_DIRuild;%PATH%"
To set LAMMPS as a system path variable, open Command Prompt as administrator, and type this:
setx /m PATH "LAMMPS_DIRuild;%PATH%"
As described earlier, LAMMPS_DIR entered in both the aforementioned Command Prompt lines should refer to the folder containing the source code.
To verify that LAMMPS has been properly built, select an existing LAMMPS input script to test run, for example, the in.crack script located in examples/crack/ in the LAMMPS folder. Open Command Prompt or PowerShell to navigate to this directory and enter either of the followings commands:
lmp -in in.crack
mpiexec -n 2 lmp -in in.crack
Successful execution of the in.crack script produces a screenshot similar to the following:
In this section, we learned about the LAMMPS compilation process in Windows. While Windows offers its own set of conveniences, it does not facilitate other features. Please see this webpage (https://lammps.sandia.gov/doc/Build_windows.html) from the LAMMPS manual for a brief overview of building LAMMPS in Windows.
Apart from using CMake, LAMMPS can be built using traditional Make, which offers a quicker way to compile and is discussed in the next section.
Make is a traditional method to build LAMMPS that uses a configuration file, called a makefile, to specify build options. The LAMMPS optional packages need to be included manually in this method.
First, you should change your directory to the source code folder:
cd src
Before compilation, each desired package should be included using the make yes-<package> command, where <package> is the name of the selected package. For example, you would use this if you wanted to include the MOLECULE package:
make yes-molecule
This operation copies all the files in src/MOLECULE to the src folder and prepares them for compilation.
In order to build LAMMPS, a customized Makefile.<machine> file is required based on the system used, where <machine> represents the type of machine setup being used (for example, serial or mpi).
The src/MAKE folder contains these customized files, the OPTIONS folder contains specific options that can be enabled, the MACHINES folder stores configurations for specific machines, and MINE usually stores your customized makefiles.
If we need to change some flags, such as for the integer data size, we open a certain makefile (for example, Makefile.serial or Makefile.mpi) in the src/MAKE folder, find the LMP_INC line, and add the required –D flags:
LMP_INC = -DLAMMPS_GZIP _DLAMMPS_SMALLBIG
The complete list of flags can be found on the appropriate page of the LAMMPS manual (https://lammps.sandia.gov/doc/Build_settings.html).
After completing the previous steps, we can type make <machine> -jN to compile the code, where <machine> corresponds to the same text as in Makefile.<machine>. For example, entering make mpi will use Makefile.mpi as the configuration file. Additionally, the –jN flag can be used to specify the number of cores used to compile:
make mpi –j4
When LAMMPS is built for the first time, it assembles a list of dependencies. When LAMMPS is rebuilt, recompilation is necessary. If settings in the makefile are changed, then all existing objects must be deleted using the make clean-<machine> command, as here:
make clean–all
It should be noted that if this traditional Make is used in the LAMMPS source directory, CMake will generate an error if this is attempted in the same directory. In such a case, the make no-all purge command has to be used to uninstall and delete existing files before CMake can proceed.
Build LAMMPS with CMake: https://lammps.sandia.gov/doc/Build_cmake.html
Build LAMMPS with Make: https://lammps.sandia.gov/doc/Build_make.html
3.21.93.44