(work in progress - ideas welcome!)
What is my Debugger
On Linux, this is most likely to be gdb (now that Intel have dropped idb).
Serial Debugging
- compile with -g (and usually with -O0 to turn off any optimisations)
- start the debugger for the given executable, e.g. gdb ./a.out
- within the debugger you can either run or if you wish to pass arguments you use run arg1 arg2 for example
- if there's a memory issue, then gdb will halt at the bad line. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command
Debugging OpenMP
- compile with -g (and usually with -O0 to turn off any optimisations) and the OpenMP compilation flag e.g. -fopenmp
- set the number of OpenMP threads e.g. export OMP_NUM_THREADS=2
- start the debugger for the given executable, e.g. gdb ./a.out
- within the debugger you can either run or if you wish to pass arguments you use run arg1 arg2 for example
- if there's a memory issue, then gdb will halt at the bad line on the first thread that has a problem. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command
Debugging MPI
- compile with -g (and usually with -O0 to turn off any optimisations) for your favored MPI installation e.g. mpiicc -g -O0
- we need to use mpirun -np N (for N processes) and for this to launch a terminal, e.g. xterm in which we can then start the debugger for the given executable. That is we will have a command line akin to
mpirun -np N xterm -e gdb ./a.out - within the debugger in each terminal you can either run or if you wish to pass arguments you use run arg1 arg2 for example
- if there's a memory issue, then gdb will halt at the bad line on the first process that has a problem. if there's no issues it will continue until completion or until you CNTL-C and enter a gdb command
Useful gdb commands
run | run (or continue to run) the executable |
step [N] | step one line [or N lines] |
list [N] | list from current point in source file [or from line N] |
print the current value of the variable VAR | |
output the type of variable VAR | |
break | set a breakpoint (i.e. when re-run the debugger will stop at this point) |
watch EXP | stop execution when expression EXP changes |
help CMD | give the help information for command CMD |