From time to time I need to debug LAMMPS code to find out why a simulation does not work as expected. The easiest way is to jump into the runtime using a debugger. Although
gdb does the job, it is not the most intuitive and easy to use the tool.
In my daily work, whenever I can, I use JetBrains toolbox, for C++ programming - CLion. It definitely simplifies work, allowing as well to easy debug the code.
LAMMPS uses CMake to control the build process. Fortunately for us, CLion integrates with CMake projects very well.
So let's start.
- Open CLion, if you end up in the Welcome Window then click on Open and select the root of LAMMPS directory.
That is it, now you can compile your LAMMPS code directly from CLion, run and debug.
LAMMPS contains multiple packages, which enables various of capabilities. This modular design allows compiling the final binary executables with only these functions that are needed to simulate your system.
You can enable/disable features and settings by -D argument. The other, more convenient option, is to use CMake presets, which contains predefined variables.
The preset can be enabled from command line:
$ mkdir build; cd build $ cmake -C ../cmake/presets/minimal.cmake ../cmake
and to enable multiple one at the same time
$ cmake -C ../cmake/presets/nolib.cmake -C ../cmake/presets/gcc.cmake -C ../cmake/presets/most.cmake ../cmake
Now, when we set up our project, we can run our simulation script.
In the list of targets, search for lmp and click on Copy icon, change the name of the target.
Next, set the Working directory to the path where your simulation scripts are located. In the Program arguments you can specify which simulation script to run, e.g.
-in in.lmp if your simulation script is in