Installing LAMMPS on Ubuntu 24.04


Installing LAMMPS on Ubuntu 24.04

Installing via APT

We can install LAMMPS using apt.

Terminal window
sudo apt install lammps

The example files can be found in /usr/share/lammps.

Terminal window
cp /usr/share/lammps/examples/melt ~/Documents
cd ~/Documents/melt
lmp -in in.melt

Hard 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.

Terminal window
sudo apt install git cmake nvidia-cuda-toolkit build-essential libopenmpi-dev libjpeg-dev libpng-dev ffmpeg

git clone

Terminal window
git clone -b release https://github.com/lammps/lammps.git lammps

Building

Refer to the official guide:

https://docs.lammps.org/Build_cmake.html

Terminal window
cd lammps
mkdir build; cd build
cmake -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 ../cmake
cmake --build .
make install

GPU_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.

.bashrc
export PATH=/usr/username/.local/bin:PATH

Running

Terminal window
cd ~/Documents/melt
lmp -pk gpu 1 -in in.melt

If 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):

.bashrc
export OMP_NUM_THREADS=2

Author

me

Fumito Iriya

Scientist (Ph.D.), Programer, Web Developer, Guitarist, Photographer

more...