Gprof¶
On Lawrencium, gprof is available as part of the standard GNU binutils and does not require loading a module. Below is a concise guide on how to use it to profile your C,C++, or Fortran applications; please consult with gprof documentation for further details.
-
Compile with Profiling Enabled
To use
gprof, compile and link your code with-pgflag. This tells the compiler to insert code to collect profiling information.gcc -pg -o program program.cg++ -pg -o program program.cppgfortran -pg -o program program.f90 -
Run the Program
Execute the program normally. You should run this within a slurm job or an interactive session (not on a login node).
When the program finishes execution, it will generate a file named
gmon.outin the current working directory. For MPI applications, set the environment variable:export GMON_OUT_PREFIX=gmon.outsuch that each MPI rank will produce a unique file
gmon.out.pidwherepidis the process ID of the MPI process. -
Generate the Profile Report
After the run completes and
gmon.outis created, usegprofto analyze the data.gprof program gmon.out > analysis.txtThe output file called
analysis.txtin the example above contains a flat profile and a call graph.