[Help] [gprof] Lammps

Dear LAMMPS users and developers,

I want to use gprof to analyze the time consumption of various functions of Lammps.
Lammps version : lammps-23Jun2022
OS: Ubuntu 20.04.3 LTS
Arch: X64
I tried some compilation methods, but failed to enable the - pg option.
Can you help me?

This is what I modified:

XXX@dell:~/exp/lammps-23Jun2022/cmake$ git diff
diff --git a/cmake/presets/gcc.cmake b/cmake/presets/gcc.cmake
index 42cd30d..0f7ffeb 100644
--- a/cmake/presets/gcc.cmake
+++ b/cmake/presets/gcc.cmake
@@ -3,16 +3,16 @@
 set(CMAKE_CXX_COMPILER "g++" CACHE STRING "" FORCE)
 set(CMAKE_C_COMPILER "gcc" CACHE STRING "" FORCE)
 set(CMAKE_Fortran_COMPILER "gfortran" CACHE STRING "" FORCE)
-set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Og -g" CACHE STRING "" FORCE)
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG" CACHE STRING "" FORCE)
-set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE)
+set(CMAKE_CXX_FLAGS_DEBUG "-pg -Wall -Og -g" CACHE STRING "" FORCE)
+set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-pg -g -O2 -DNDEBUG" CACHE STRING "" FORCE)
+set(CMAKE_CXX_FLAGS_RELEASE "-pg -O3 -DNDEBUG" CACHE STRING "" FORCE)
 set(MPI_CXX "g++" CACHE STRING "" FORCE)
 set(MPI_CXX_COMPILER "mpicxx" CACHE STRING "" FORCE)
 set(MPI_C "gcc" CACHE STRING "" FORCE)
 set(MPI_C_COMPILER "mpicc" CACHE STRING "" FORCE)
-set(CMAKE_C_FLAGS_DEBUG "-Wall -Og -g" CACHE STRING "" FORCE)
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -DNDEBUG" CACHE STRING "" FORCE)
-set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "" FORCE)
+set(CMAKE_C_FLAGS_DEBUG "-pg -Wall -Og -g" CACHE STRING "" FORCE)
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "-pg -g -O2 -DNDEBUG" CACHE STRING "" FORCE)
+set(CMAKE_C_FLAGS_RELEASE "-pg -O3 -DNDEBUG" CACHE STRING "" FORCE)
 set(MPI_Fortran "gfortran" CACHE STRING "" FORCE)
 set(MPI_Fortran_COMPILER "mpifort" CACHE STRING "" FORCE)
 set(CMAKE_Fortran_FLAGS_DEBUG "-Wall -Og -g -std=f2003" CACHE STRING "" FORCE)

This is my compilation script:

XXX@dell:~/exp/lammps-23Jun2022$ cat whoway.build.sh
#!/bin/bash
mkdir -p build
mkdir -p install-cmake
cd build
cmake ../cmake -DCMAKE_INSTALL_PREFIX=/home/XXX/exp/lammps-23Jun2022/install-cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ 

If you can help with doubts, it would be really appreciated.

Your modification of a preset file has no effect, if you don’t load the preset. A simpler way would be to just set flags at the command line directly (as documented in the CMake documentation):

cmake ../cmake -D CMAKE_C_FLAGS="-Og -pg" -D CMAKE_CXX_FLAGS="-Og -pg" -D CMAKE_EXE_LINKER_FLAGS="-Og -pg" .

Please also consider using the performance counter based profiling with perf which does not require any instrumentation at all.

1 Like

Thank you for your help.:smiley:
The problem has been solved with your help.