
From time to time I need to debugLAMMPS code to find out why a simulation does not work as expected. The easiest way is to jump into the runtime using a debugger. Althoughgdb
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 usesCMake to control the build process. Fortunately for us, CLion integrates with CMake projects very well.
So let's start.
Setup project
- Open CLion, if you end up in the Welcome Window then click onOpen
and select the root of LAMMPS directory.
If you end up in the main window with an already opened project, you can go toOpen ➡️ File ➡️ Open... and select the root of LAMMPS directory.
2. To enable CMake project, opencmake/CMakeLists.txt
. You should see in the editor window on the top link toLoad CMake project, click on it.
That is it, now you can compile your LAMMPS code directly from CLion, run and debug.
Enable/disable different compilation options
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 useCMake presets, which contains predefined variables.
The preset can be enabled from command line:
$mkdirbuild;cdbuild$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
You can attach the same settings in the Clion project configuration by putting CMake command line option inCMake options field.
Run your simulation script
Now, when we set up our project, we can run our simulation script.
The easiest way is to make a copy of an existing configuration and include the simulation script.
Go toRun ➡️ Edit Configurations...
In the list of targets, search forlmp and click onCopy icon, change the name of the target.
Next, set theWorking directory to the path where your simulation scripts are located. In theProgram arguments you can specify which simulation script to run, e.g.-in in.lmp
if your simulation script is inin.lmp
file.
Run debugger
Running debugger is pretty simple. In the main window select the target to run, and click on the Debug icon.
I have guided you step by step on how to set up debugging for LAMMPS package. However, you can debug yourGROMACS orESPResSo++ simulations.
Happy debugging!
If you liked the post, then you canbuy me a coffee. Thanks in advance.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse