BISMG:SarahS/profiling glimmer

Debugging Notes
There appears to be two choices of debugger, idb (intel) and gdb (gnu). The disadvantage of gdb is that it does not allow you to look at allocatable arrays inside derived types. idb can do this. The disadvantage of idb, is that it does not work well with the emacs gui. For example, you can not do point and click breakpoints.

How to start using gdb on the command line

 * open an emacs window emacs &
 * alt x gdb
 * enter name of binary (including full path)
 * cd to where the naelists are
 * run
 * Gud, GUD -IU, display other windows
 * p (variable name) will print the variable name.
 * pt (variable name) will print variable type
 * p &(variable name) will print memory address of variable
 * set var variable name = a value will set a value (no need to compile just type n to go to the next step
 * Remember to compile with debugger flag and optimisation switched off i.e. gfortran -O0 -g

How to start using idb on the command line

 * You can compile using ifort or gfortran44.
 * Load in the idb module intel/idb/10.1.015
 * Compile your code using the -g flag. Remember to switch off any optimization flags (e.g. -O2)
 * to run the debugger type idb program_name
 * If you would like to output an array to a netCDF file you can use Gethin's routines to do this. You will have to compile his routines called ncdump_routines.f90. A makefile is provided to do this. To quickly link to routines, tack 'ncdump_routines.o' on to the command that links the object files & libraries.
 * Here is an example of how to write a 3d array to netCDF file if you have compiled with gfortran44
 * 'type 'call __ncdump_MOD_d3dncdump(variable,z,x,y)'. If you have compiled with ifort replace 'MOD' with 'mp'. There is a similar routine to write a 2 d array. Note you need to know beforehand the dimension of the array which you can find using the ptype command.
 * Examples of useful commands:
 * insert a break point: break simple_glide.F90:153
 * make this a conditional break point: condition 1 model%temper%temp(11,30,8)<-24.0
 * list all break points: info break
 * print a variable: p time
 * shell ls - list files in current directory while in the bugger
 * The complete manual for idb is here http://cache-www.intel.com/cd/00/00/40/60/406036_406036.pdf

How to start using idb with the emacs GUI

 * compile in the same way as above
 * open emacs
 * type altgr x
 * type gdb
 * type idb -gdb -fullname myprog remove the annotate 3 that is at the prompt by default.
 * If using gdb then just type the name of your program at the prompt
 * GDB-/IU --> display other windows
 * type run at the command prompt to start running your executable

Segmentation faults: How to find out more info on the cause

 * A binary file can be created when a seg fault occurs that contains all the variables at the time of the crash. This is caused a core dump file.
 * Compile with -g
 * set your ulimit to unlimited by typing' ulimit -c unlimited'
 * run program as normal
 * when the seg fault occurs a core dump file is created. The file as the name core.number
 * to see what is in the file type 'idb my_program core.number'
 * type 'back' to see the list of subroutines called prior to the crash

Profiling notes
How to using gprof:


 * Compile with -p flag (when using ifort compiler)
 * run as program as normal. A file called gmon.out is written to the directory
 * gprof my_file.exe gmon.out