Compiling LAMMPS with cmake as a user on a computing cluster
Why I want to write a page on how to compile LAMMPS.#
As a participant of the LAMMPS users forum, it is quite often that we see people using outdated version of LAMMPS and telling us that:
This is the version installed on our cluster. I’ll ask to install a more recent one.
This is a coping strategy with regard to the problem for two reasons:
-
Computing clusters cannot track updates of all modern scientific softwares. There are thousands of different softwares for all the scientific disciplines in existence and new softwares come up every day from teams labs etc., each tailored to specific needs or implementing new algorithms. It is impossible for a cluster managment team to follow each and every new versions of every loads of software people need.In addition, people can use several softwares for the same usage such as different molecular simulation codes… Because “reasons”.
-
You are limiting yourself to the software installed on the cluster by the maintenance team and expecting them to suits your needs. Spoiler: they can’t. They can help you tailor your computing environment, but won’t make development or look for the specific libraries you need because this is your work. Learning how to install new codes yourself is possible on most cluster for this very reason. Else, scientific computing would be barely useless.
Now bear in mind that the following will be a shortened version of what is explained in the manual and will focus on the The previous compiling method using "make" is planned to be phased out.
What you need to compile LAMMPS.#
The first thing you’ll need will be access to git and cmake software on
If you want to compile LAMMPS on Windows, refer to the manual. I know NO
computing cluster that runs on windows server, and that would be a particularly
stupid idea in my opinion.
If not available using the default environment, these are
often activated through the use of modules. You load modules using the module load
command followed by the name of the module. For example:
module load cmake
To know which module are available to load, you can use the module spider
command. For example:
module spider git
It should provide you the list of modules which make the git command available upon loading. Sometimes You need at least cmake 3.20. To compile LAMMPS. can be loaded. This can be important in certain cases, for example for compilers.
If you have trouble at this stage, reach your cluster maintenance team. This is the part they are most likely to be eager to help you with.
Getting LAMMPS source#
LAMMPS code is hosted on a Github repository can be accessed from the command line through the use of the git software. git is the backend of many modern forge such as Github, GitLab or CodeBerg. git is different from the GitHub CLI. The latter is not required. You can create a local copy of the source of the development version of the code from the command line by using the command:
git clone git@github.com:lammps/lammps --branch=develop
This will create a lammps directory in your working directory with a copy of
the current state of the develop branch of the code. If you want the latest
release version, you can replace the develop argument with release. If
disk usage is an issue, please see these advice.
This repository is now synced with the Github repository which is now its
upstream repo in the jargon. If you want to include new changes in the code,
you can go to the directory and use the git pull command. This will download
updated versions of the files and new files to your local repository.
If you need to setup an ssh key#
Cloning the git repository will require that you setup a github account and an ssh key. The former is straight forward. For the latter, you can follow the Github tutorial.
If you want to learn how to use Git#
A good book on the topic is Learning Git from Anna Skoulikari published by
O’Reilly press..
Going cover to cover and following the book code snippets along should teach you
more than enough for your daily use of Git. It is also not that long. You’ll
thank me (and Ms. Skoulikari) later.
Compiling LAMMPS#
The steps to follow are rather straight forward:
- Go to the lammps folder:
cd lammps - Create a directory where to build the executable:
mkdir build; cd build - Configure the building environment with cmake scripts:
cmake ../cmake - Compile:
cmake --build .
The most important steps are 3 and 4. During step 3, the cmake scripts
contained in the cmake directory will set the compilation options. That is
which library to use for MPI or FFT, which version of Python to use, which
optional package to include, etc.
Pay special attention if an MPI library has been found. If not, your simulation
will not be parallelized, and using MPI related commands will only launch
several instances of the same simulation.
Note that the final message should tell you if everything is ready for
compilation or not. Warning and error message often indicate that some
necessary library were not found and might require loading more modules or
setting environment variables. If you want to include special packages,
you can either use the -D PKG_NAME=yes flags at this stage or use the method
below. You can also pass other cmake options here using the -D flag.
During step 4 you are calling the compiler and building the actual executable.
If you want to use several CPUs for compilation, you can use the -j n flag
where n is the number of CPUs. For example: cmake --build . -j 8 will use 8
CPUs. As the files compilation is split among all the CPUs, a file that makes
compilation fail is often lost in the screen output. Sometimes it is better to
compile with a reduced number of CPUs to catch faulty files better.
Adding packages#
By default, the compiled files do not add any external package to the LAMMPS
executable. As said, you can add packages during the step 3 of the compilation
process with the -D flag. Another way of doing is using the cmake presets
files found in cmake/presets. For example, assuming your build repository
is at the same level as your cmake repository, you can add all the packages
using the command cmake -C ../cmake/presets/all_on.cmake ../cmake. Note that
some package require additional
steps. Modifying one of the files
to only contain the package that interest you is straight forward.
Adding the executable to your path#
The compiled executable will be available in your build directory under
the name lmp. You can either copy it somewhere in your path or make a link.
On computing cluster home repository are often shared across machines but
the specifics of installation depend on your cluster. Generally having a specific
bin repository in your home and adding it to your path is sufficient. You can
then add the copy or the link to the executable and you will be good.
It is also possible to install LAMMPS to your user session using the
make install command in your compilation directory. Note that this will
copy a lot of files to the .local repo in your home by default. Use the
-D CMAKE_INSTALL_PREFIX=path/to/installation option at step 3 to change this.