| <p>This guide is modified from section (d) of the worksheet inside Module 10 of Phys 6810 Computational Physics (Spring 2023).</p>
<p>NOTE: gprof does <strong>not</strong> work on macOS. Please use a linux machine (such as OSC)</p>
<p>To use gprof, compile and link the relevant codes with the <strong>-pg</strong> option:<br />
Take a look at the Makefile <strong>make_hello_world</strong> and modify both the <strong>CFLAGS</strong> and <strong>LDFLAGS</strong> lines to include <strong>-pg</strong><br />
<br />
Compile and link the script by typing<br />
make -f make_hello_world</p>
<p>Execute the program<br />
./hello_world.x</p>
<p>With the <strong>-pg</strong> flags, the execution will generate a file called <strong>gmon.out</strong> that is used by gprof.<br />
The program has to exit normally (e.g. we can't stop with a ctrl-C).<br />
<strong>Warning: </strong>Any existing gmon.out file will be overwritten.</p>
<p>Run gprof and save the output to a file (e.g., gprof.out) by<br />
gprof hello_world.x > gprof.out</p>
<p>We should at this point see a text file called <strong>gprof.out</strong> which contains the profile of hello_world.cpp<br />
vim gprof.out</p> |