| 1 | = Code Debugging = |
| 2 | Ideally, code should be debuged on your desktop computer before being moved to a cluster environment. There are a number of debugging techniques, which you can learn from the internet. |
| 3 | |
| 4 | == print == |
| 5 | Insert 'print' into the source code. |
| 6 | |
| 7 | in C/C++ |
| 8 | {{{#!c |
| 9 | /* check */ |
| 10 | #ifdef DEBUG |
| 11 | if (info == 0) printf("successfully done\n"); |
| 12 | #endif |
| 13 | }}} |
| 14 | |
| 15 | in Fortran |
| 16 | {{{#!fortran |
| 17 | #ifdef debug |
| 18 | if (info == 0) then |
| 19 | print *,"successfully done" |
| 20 | endif |
| 21 | #endif |
| 22 | }}} |
| 23 | |
| 24 | Compile with ''-DDEBUG'' option |
| 25 | {{{ |
| 26 | icc -g -pg -DDEBUG -c stokeslet2d.c |
| 27 | }}} |
| 28 | |
| 29 | Makefile |
| 30 | {{{#!make |
| 31 | # |
| 32 | # CCS WORKSHOP |
| 33 | # Stokes Flow in a Cavity |
| 34 | # |
| 35 | # Makefile |
| 36 | # |
| 37 | # |
| 38 | TARGET = ex32s ex32m |
| 39 | # |
| 40 | ALL: $(TARGET) |
| 41 | # |
| 42 | CC = icc |
| 43 | |
| 44 | #CFLAGS = -O3 |
| 45 | CFLAGS = -g -pg -DDEBUG |
| 46 | # |
| 47 | # |
| 48 | # |
| 49 | SRC_EX32c = ex32.c stokeslet2d.c gmres.c |
| 50 | # |
| 51 | # |
| 52 | MKL_SQ_LIBS = -L$(MKLROOT)/lib/intel64/ \ |
| 53 | -I$(MKLROOT)/mkl/include \ |
| 54 | -Wl,--start-group \ |
| 55 | $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a \ |
| 56 | $(MKLROOT)/lib/intel64/libmkl_sequential.a \ |
| 57 | $(MKLROOT)/lib/intel64/libmkl_core.a \ |
| 58 | -Wl,--end-group \ |
| 59 | -lpthread |
| 60 | # |
| 61 | MKL_MT_LIBS = -L$(MKLROOT)/lib/intel64/ \ |
| 62 | -I$(MKLROOT)/mkl/include \ |
| 63 | -Wl,--start-group \ |
| 64 | $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a \ |
| 65 | $(MKLROOT)/lib/intel64/libmkl_intel_thread.a \ |
| 66 | $(MKLROOT)/lib/intel64/libmkl_core.a \ |
| 67 | -Wl,--end-group \ |
| 68 | -liomp5 \ |
| 69 | -lpthread |
| 70 | # |
| 71 | # |
| 72 | # |
| 73 | OBJ_EX32c = $(SRC_EX32c:.c=.o) |
| 74 | # |
| 75 | # |
| 76 | ex32s : $(OBJ_EX32c) |
| 77 | $(CC) $(CFLAGS) -o $@ $(OBJ_EX32c) $(MKL_SQ_LIBS) |
| 78 | |
| 79 | ex32m : $(OBJ_EX32c) |
| 80 | $(CC) $(CFLAGS) -o $@ $(OBJ_EX32c) $(MKL_MT_LIBS) |
| 81 | |
| 82 | # |
| 83 | # |
| 84 | %.o : %.c |
| 85 | $(CC) $(CFLAGS) -c $< |
| 86 | |
| 87 | # |
| 88 | clean: |
| 89 | rm -f *.o $(TARGET) |
| 90 | }}} |
| 91 | |
| 92 | == GDB == |
| 93 | You can use '''GDB''' on CCS cluster. [[http://www.gnu.org/software/gdb/|GDB]] |
| 94 | |
| 95 | To debug with '''GDB''', submit an interactive job. [[https://wiki.hpc.tulane.edu/trac/wiki/cypress/using#SubmittingInteractiveJobs|See here]] |
| 96 | |
| 97 | Compiling with '''-g''' option |
| 98 | {{{ |
| 99 | icc -g -pg -DDEBUG -c stokeslet2d.c |
| 100 | }}} |
| 101 | run '''gdb''' |
| 102 | {{{ |
| 103 | user@host>gdb ./ex32s |
| 104 | GNU gdb (GDB) Red Hat Enterprise Linux (7.2-56.el6) |
| 105 | Copyright (C) 2010 Free Software Foundation, Inc. |
| 106 | License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> |
| 107 | This is free software: you are free to change and redistribute it. |
| 108 | There is NO WARRANTY, to the extent permitted by law. Type "show copying" |
| 109 | and "show warranty" for details. |
| 110 | This GDB was configured as "x86_64-redhat-linux-gnu". |
| 111 | For bug reporting instructions, please see: |
| 112 | <http://www.gnu.org/software/gdb/bugs/>... |
| 113 | Reading symbols from /ccs-autofs/u01/fuji/LabWork/FlowInCavity/ex32s...done. |
| 114 | (gdb) |
| 115 | }}} |
| 116 | |
| 117 | show source by command, list '''line#''' |
| 118 | {{{ |
| 119 | (gdb) list 44 |
| 120 | 39 printf("Usage:%s [Depth of Cavity]\n",argv[0]); |
| 121 | 40 exit(-1); |
| 122 | 41 } |
| 123 | 42 |
| 124 | 43 /* get inputed depth */ |
| 125 | 44 dp = atof(argv[1]); |
| 126 | 45 |
| 127 | 46 /* # of particles in depth */ |
| 128 | 47 numpdepth = (int)(dp / EPSILON + 0.5); |
| 129 | 48 |
| 130 | (gdb) |
| 131 | }}} |
| 132 | set breakpoint by command, '''b line#''' |
| 133 | {{{ |
| 134 | (gdb) b 47 |
| 135 | Breakpoint 1 at 0x4044c2: file ex32.c, line 47. |
| 136 | (gdb) |
| 137 | }}} |
| 138 | '''run [command line option]''' |
| 139 | {{{ |
| 140 | (gdb) run 5 |
| 141 | Starting program: /ccs-autofs/u01/fuji/LabWork/FlowInCavity/ex32s 1 |
| 142 | [Thread debugging using libthread_db enabled] |
| 143 | |
| 144 | Breakpoint 1, main (argc=2, argv=0x7fffffffd5c8) at ex32.c:47 |
| 145 | 47 numpdepth = (int)(dp / EPSILON + 0.5); |
| 146 | Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6_3.3.x86_64 |
| 147 | (gdb) |
| 148 | }}} |
| 149 | |
| 150 | print values |
| 151 | {{{ |
| 152 | (gdb) p dp |
| 153 | $1 = 5 |
| 154 | (gdb) p numpdepth |
| 155 | $2 = 0 |
| 156 | (gdb) |
| 157 | }}} |
| 158 | |
| 159 | continue one step |
| 160 | {{{ |
| 161 | (gdb) next |
| 162 | 50 numpwidth = (int)(1.0 / EPSILON + 0.5); |
| 163 | (gdb) p numpdepth |
| 164 | $3 = 1000 |
| 165 | (gdb) |
| 166 | }}} |
| 167 | |
| 168 | exit |
| 169 | {{{ |
| 170 | (gdb) quit |
| 171 | A debugging session is active. |
| 172 | |
| 173 | Inferior 1 [process 6222] will be killed. |
| 174 | |
| 175 | Quit anyway? (y or n) y |
| 176 | }}} |