Installing via APT
We can install LAMMPS using apt.
sudo apt install lammpsThe example files can be found in /usr/share/lammps.
cp /usr/share/lammps/examples/melt ~/Documentscd ~/Documents/meltlmp -in in.meltHard to believe it’s this easy to get LAMMPS running—what a time to be alive.
Building from Source
If we want to use the GPU package, we’ll need to build LAMMPS from source.
It requires installing several dependencies, and I got it working after a fair bit of trial and error.
git, cmake, cuda, Required Packages
We’ll need to install git, cmake, cuda, and various development libraries.
sudo apt install git cmake nvidia-cuda-toolkit build-essential libopenmpi-dev libjpeg-dev libpng-dev ffmpeggit clone
git clone -b release https://github.com/lammps/lammps.git lammpsBuilding
Refer to the official guide:
https://docs.lammps.org/Build_cmake.html ⧉
cd lammpsmkdir build; cd buildcmake -C ../cmake/presets/basic.cmake -D PKG_GPU=yes -D GPU_API=cuda -D GPU_ARCH=sm_89 -D PKG_OPENMP=yes -D WITH_JPEG=yes -D WITH_PNG=yes -D WITH_FFMPEG=yes ../cmakecmake --build .make installGPU_ARCH depends on your GPU model. You can look it up here:
https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/ ⧉
Some guides suggest including -DBIN2C=/usr/local/cuda/bin/bin2c, but I was able to build it without that. Not sure what difference it makes—worth investigating.
Add to PATH
Add the appropriate paths to your .bashrc.
export PATH=/usr/username/.local/bin:PATHRunning
cd ~/Documents/meltlmp -pk gpu 1 -in in.meltIf you see an error about OMP_NUM_THREADS not being set, add something like the following to your .bashrc (adjust the number to suit your environment):
export OMP_NUM_THREADS=2