High Performance Computing

Introduction to Debuggers

A debugger is a tool which the user can employ to interrogate their code with a list of enquires. The user can, for example, step into do-loops and check array elements on each loop. This page serves as a simple example to encourage users to start using this tool when developing their code.
To employ the debugger use the -g flag when compiling your code. The resulting binary can then be interrogated by the debugger. The following example defines an array of size N but tries to loop through it N+1 times.

  • Download the example
  • look at the source code and the comment at the top
  • compile it: pgf90 -g debugex.f90 and run it
  • start the debugger: pgdbg a.out . This is the Portland Group debugger.

This is a trivial example but it is often the case we have a do-loop looping maybe 10s of thousands of times with several arrays in it of differing dimensions. The user might know there is something wrong within it but would like to be able to test array elements at differing loop numbers without having to recompile the code with a pile of write statements dumping vast amounts of data. Once in the debugger;


List code on lines 2 to 10
pgdbg> list 2:20

Track the do-loop dummy variable i
pgdbg> track i
Running the code will print out i at each step in the loop even if we did not have the write(*,*) statement

Now run the code
pgdbg> run

To unset the track before running again:
pgdbg> del all

Let's say we want to skip the first 4 loops and then print i:
pgdbg> if(i>4) {print i; step}
Note the use of step (another way of stepping through a loop), and print (another way to print a variable).


pgdbg>