Changes between Initial Version and Version 1 of cypress/Programming/CodeDebugging


Ignore:
Timestamp:
08/19/15 17:02:48 (9 years ago)
Author:
fuji
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • cypress/Programming/CodeDebugging

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