Tuesday, August 13, 2013

C Programming Memory Debugging: Valgrind

     I wanted to spread the word about Valgrind, a memory management debugger for C programs. I just found out about it and in the last hour or so has already caused me to identify numerous bugs in my CFD program. My CFD program (which is an unsteady, multi-block, structured grid, incompressible Navier-Stokes solver) is the largest program I have ever written and bugs occasionally pop up when inputs change (in my case, larger grids and thus larger memory allocations), and in my search for solutions I came across Valgrind. It is also very easy to use and well documented. Go to the Valgrind website and check out the 'Quick Start' section to try it out yourself.

5 comments:

  1. Hello lordvon!

    I was looking at your work and it is really good. I'm using OpenFOAM to validate an analytical method to calculate forces on a pitching and plunging airfoil.

    My simulations run well and the flow field seems very physical, however, I'm suffering from segmentation faults which are arising from run-time post processing, So I stopped run-time postprocessing and depending on post run postprocessing. I wrote a shell script as a work around for the memory leak issues. It just restarts the force calculation from the last crash point.

    I want to know if you faced similar issues with pimpleDyMFoam. I must add that I haven't issues like this with pimpleFoam. My mesh log says everything is OK. Here is a link to the github repository in case you want to take a look at the case. https://github.com/pruthvi1991/pimpleDyMFoam-Tutorials/tree/master/onemeterplate_coarse

    Thanks,
    Pru.

    ReplyDelete
  2. Hi Pruthvi,
    If it is not the flow solution that is diverging, then it could be accessing of partially complete data.

    ReplyDelete
  3. Hi lordvon,

    My solution is not diverging. Nothing is blowing up and my results look very physical. When I comment out the forceCoeffs file from controlDict I have no issues. When it is turned on I get segmentationfaults which crash the simulation. As I mentioned I use a shell script to post process the force data. This works but it has a disadvantage though. The time resolution of the force data is now dependent on my writeTime. Have you ever faced issues like this in OpenFOAM specifically pimpleDyMFOAM.

    ReplyDelete
  4. Hi Robert,

    This is a bug in the OpenFOAM code. I reported the bug and it was resolved this morning. Here is the link in case you are interested in the details. http://www.openfoam.org/mantisbt/view.php?id=1560

    ReplyDelete
    Replies
    1. Thanks for that and good work! Sorry I couldn't be of much help; I was not familiar with execFlowFunctionObjects.

      Delete