1 / 21

Why did my program crash? or How to debug your OpenFOAM codes using GDB

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.

Download Presentation

Why did my program crash? or How to debug your OpenFOAM codes using GDB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Why did my program crash? or How to debug your OpenFOAM codes using GDB

  2. Running your code Coding your own software – good & bad Programming your own codes without bugs is near impossible even for Weller & Jasak

  3. 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

  4. 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);

  5. Debugging your code Alternative way: Inserting Info << "U is " << U[celli] << endl; Requires Re-compilation (usually many times)

  6. 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

  7. Before we start – Bad news You need to recompile… 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…

  8. 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 you're back, some packages (e.g. the paraview reader) will have failed…

  9. Compiling with Debug These packages can be compiled seperately with debug flags Quick Solution: Use the Opt version, as we're most likely not interested in debugging such packages Done by simple copy of libPackageName.so

  10. Setup on Student Installation Pre-compiled version of Debug done by Håkan Used by copying .OpenFOAM-1.4.1 from local installation to /chalmers/users/userdir/ And editing .cshrc/.bashrc like described before

  11. 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.

  12. 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; nonOrth<=nNonOrthCorr; nonOrth++) { fvScalarMatrix pEqn ( fvm::laplacian(rUA, p) == fvc::div(phi) ); What does adjustPhi do?

  13. Example - icoFoam Start GDB in case directory: gdb icoFoam GNU gdb 6.5 ... (gdb) Start off by inserting a breakpoint where we want to inspect the code b icoFoam.C:77

  14. Starting the Debug Program can be started in two ways: start <root> <case>- Stops at main or run . . - Runs Program If all is well, program should now stop at line 77 of icoFoam: Breakpoint 1, main (argc=3, argv=0x7fffc346b128) at icoFoam.C:77 77 adjustPhi(phi, U, p);

  15. Two Ways of Stepping Next [n] – Step until next line in the current program, will not debug functions and included files Step [s] – Step until next source line, will debug subfunctions Both commands can be followed by a number to step a certain amount of lines

  16. adjustPhi where – shows which file we are debugging and which file called it list – gives a listing of the source code around the current line, e.g. list 40,60 lists lines 40-60 Now in: cfdTools/general/adjustPhi/adjustPhi.C:42 Stepping and listing the code will show how adjustPhi ensures continuity

  17. Useful Commands See GDBCommands.pdf for a quick guide to the commands available in GDB. This list is by no means complete and a full listing is available at: http://sourceware.org/gdb/documentation/

  18. Tutorial Example Why does Xoodles crash when starting the pitzDaily3D case? Known error from forums, output from Opt: #6 main in "/c3se/users/f98faka/OpenFOAM/OpenFOAM-1.4.1/applications/bin/linux64GccDPOpt/Xoodles" #7 __libc_start_main in "/lib64/tls/libc.so.6" With Debug version of OF: #7 main at ~/OpenFOAM/OpenFOAM- 1.4.1/applications/solvers/combustion/Xoodles/../XiFoam/bEqnn.H:79 #8 __libc_start_main in "/lib64/libc.so.6"

  19. Tutorial Example Start Xoodles with GDB and a breakpoint at this location: Breakpoint 1, main (argc=3, argv=0x7fffb8830fc8) at ../XiFoam/bEqn.H:79 79 volScalarField tauEta = sqrt(thermo->muu()/(rhou*epsilon)); Possible issue with division, inspection of some epsilon values shows low epsilon.

  20. 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?

  21. End Thanks for listening!

More Related