资源描述
Klicka fr att ndra format p bakgrundsrubriken,Klicka fr att ndra format p bakgrundstexten,Niv tv,Niv tre,Niv fyra,Niv fem,Chalmers University of Technology,Fabian Peng K,rrholm,Why did my program crash?,or,How to debug your OpenFOAM codes using GDB,Running your code,Coding your own software good & bad,Programming your own codes without bugs is near impossible,even for Weller & Jasak,Debugging your code,Debugging is a necessary evil to resolve bugs and examine crashes when developing all codes, and OpenFOAM is not an exception,Built-in debug feature shows more details, but gives only “passive” information,Debugging your code built-in,Debugflags available in,.OpenFOAM-1.4.1/controlDict,lduMatrix 2;,Will give output for each matrix-iteration:,DICPCG: Iteration 475 residual = 0.542126,No Recompilation of code needed.,Flags set in code by:,defineTypeNameAndDebug(PCG, 0);,Debugging your code,Alternative way:,Inserting,Info U is Ucelli endl;,Requires Re-compilation (usually many times),GDB - Introduction,GDB is the GNU project debugger,It can be used for,- Programs written in C, C+, Ada, Pascal etc,- Run & Stop at specific positions,- Examine variables at run-time,- Change your program at run-time,You need to recompile EVERYTHING!,Debug version of OpenFOAM requires 1 Gb of diskspace, vs 64 Mb for Opt,It is also slower,Even slower when run with GDB,You need to recompile,Before we start Bad news,Compiling with Debug,File:,.OpenFOAM-1.4.1/bashrc,Comment,setenv WM_COMPILE_OPTION Opt,Uncomment,setenv WM_COMPILE_OPTION Debug,Then run the Allwmake script and go for a very long break.,When youre back, some packages (e.g. the paraview reader) will have failed,Compiling with Debug,These packages can be compiled seperately with debug flags,Quick Solution:,Use the Opt version, as were most likely not interested in debugging such packages,Done by simple copy of libPackageName.so,Setup on Student Installation,Pre-compiled version of Debug done by Hkan,Used by copying,.OpenFOAM-1.4.1 from local installation to,/chalmers/users/userdir/,And editing .cshrc/.bashrc like described before,First Debug,Objective: To find out what a part of the code does,Code: icoFoam - for incompressible, laminar flow,Simple code, suitable to start debugging, as there are not that many files included.,Example icoFoam,73: U = rUA*UEqn.H();,74: phi = (fvc:interpolate(U) & mesh.Sf(),+ fvc:ddtPhiCorr(rUA, U, phi);,77: adjustPhi(phi, U, p);,79: for (int nonOrth=0; nonOrthmuu()/(rhou*epsilon);,Possible issue with division, inspection of some epsilon values shows low epsilon.,Post-debugging,Codes run without gdb that crash,Set system to dump core-file,Core-files can be used to inspect where errors occurred,In cshrc:,limit coredumpsize unlimited,In bashrc:,ulimit -c unlimited,Then simply loaded in gdb by core-file ,Questions GDB can answer,What does .flux do?,What happens when .solve is issued?,When does my variable go below x?,How does scheme x work?,Where did my code crash?,End,Thanks for listening!,
展开阅读全文