CMake¶
CMake Example: Serial LAMMPS Build¶
Note
This is a minimal example using the command line version of CMake to build LAMMPS with no customization.
To allocate an interactive job on compute node type:
srun -p short --pty -N 1 -n 28 /bin/bash
Download the source code to LAMMPS:
cd ~ wget https://github.com/lammps/lammps/archive/refs/tags/stable_29Aug2024.tar.gz tar -xvf stable_29Aug2024.tar.gz
Load the following modules required for building LAMMPS:
module load gcc/11.1.0 module load cmake/3.23.2
For LAMMPS, you will need to create and use the build directory with the following command:
cd lammps-stable_29Aug2024 mkdir -p build cd build/
Load the CMake module and use CMake to generate a build environment in a new directory.
cmake -C ../cmake/presets/most.cmake ../cmake
Next, you will work on the compilation and linking of all objects, libraries, and executables using the selected build tool.
cmake --build . make install
The
cmake --build
command will launch the compilation, which, if successful, will ultimately generate an executablelmp
inside thebuild
folder. Now you can start running LAMMPS using./lmp
. To use the LAMMPS build, you will need to setup your environment so the binaries are in your PATH. This can be completed by including the following export statement in your sbatch script or have it as a script that you can source in your job script:#!/bin/bash #SBATCH -N 1 #SBATCH -n 1 #SBATCH -p short module load gcc/11.1.0 export PATH=/home/$USER/lammps-stable_29Aug2024/build:$PATH cd ~ lmp -in /home/$USER/lammps-stable_29Aug2024/examples/melt/in.melt
or create the following script in your
$HOME
calledlammps_env.sh
#!/bin/bash module load gcc/11.1.0 export PATH=/home/$USER/lammps-stable_29Aug2024/build:$PATH
and modify your sbatch job script to source this environment file that will setup your environment for your job:
#!/bin/bash #SBATCH -N 1 #SBATCH -n 1 #SBATCH -p short source /home/$USER/lammps_env.sh cd ~ lmp -in /home/$USER/lammps-stable_29Aug2024/examples/melt/in.melt
CMake Example: Parallel LAMMPS Build¶
See also
The following instructions to build LAMMPS using cmake.
Running LAMMPS in parallel is possible using a domain decomposition parallelization. In order to build the MPI version, first allocate an interactive job on compute node by typing:
srun -N 1 -n 28 --constraint=ib --pty /bin/bash
Download the source code to LAMMPS:
cd ~ wget https://github.com/lammps/lammps/archive/refs/tags/stable_29Aug2024.tar.gz tar -xvf stable_29Aug2024.tar.gz
Load the required modules required for building LAMMPS:
module load gcc/11.1.0 module openmpi/4.1.2-gcc11.1 module load cmake/3.23.2
For LAMMPS, you will need to create and use the build directory with the following command:
cd lammps-stable_29Aug2024 mkdir -p build cd build/
In the build directory, run the following commands with
DBUILD_MPI=yes
to build the MPI version :cmake -C ../cmake/presets/most.cmake ../cmake -DBUILD_MPI=yes cmake --build . make install
The instructions above will create a
lmp
inside thebuild
directory that is MPI compliant. To use the LAMMPS build, you will need to setup your environment so the binaries are in your PATH. This can be completed by including the following export statement in your sbatch script or have it as a script that you can source in your job script:#!/bin/bash #SBATCH -N 1 #SBATCH -n 8 #SBATCH -p short module load gcc/11.1.0 module openmpi/4.1.2-gcc11.1 export PATH=/home/$USER/lammps-stable_29Aug2024/build:$PATH cd ~ mpirun -n 8 lmp_mpi -in /home/$USER/lammps-stable_29Aug2024/examples/melt/in.melt
or create the following script in your
$HOME
calledlammps_env.sh
#!/bin/bash module load gcc/11.1.0 module openmpi/4.1.2-gcc11.1 export PATH=/home/$USER/lammps-stable_29Aug2024/build:$PATH
and modify your sbatch job script to source this environment file that will setup your environment for your job:
#!/bin/bash #SBATCH -N 1 #SBATCH -n 8 #SBATCH -p short source /home/$USER/lammps_env.sh cd ~ mpirun -n 8 lmp_mpi -in /home/$USER/lammps-stable_29Aug2024/examples/melt/in.melt
Note
When compiled with MPI, the binaries expect mpirun
or mpiexec
with the number of tasks to run.
Now, you can start running LAMMPS using mpirun -n 1 ./lmp -h
.