← Back to team overview

dolfin team mailing list archive

Re: memory leak in GTS/IntersectionDetector?

 

Thanks Garth,
that seems to have done the trick. Both the test program and the full application seem to be working without the massive memory leak now. Many thanks for tracking this down (I'm still confused about how the GTS interface works...)
cheers
marc

On Feb 8, 2009, at 12:56 PM, Garth N. Wells wrote:



mspieg wrote:
On Feb 6, 2009, at 6:35 PM, Garth N. Wells wrote:


mspieg wrote:
Hi All,
I'm playing with some characteristic based advection schemes in Dolfin (0.9.0) which require a large number of discrete Function evals. This seems to be leading to a large memory leak as the process grows considerably in size with every time-step. I've put together a small (badly written) program that demonstrates the problem which I've tried to isolate just to IntersectionDetector (and the underlying GTS). I suspect the problem is in GTS, but thought I would start with Dolfin support. Any thoughts/help greatly appreciated...

I recall that quite some time ago some memory leaks were fixed in the DOLFIN GTS interface, but there remained some GTS problems. Have you run valgrind?
Thanks Garth,
I've been developing on mac OSX 10.4 which valgrind doesn't support (yet ?). I can probably dig up a linux box and run valgrind (but if someone else can do it faster that would be great). Apple has an application MallocDebug, which I've started playing with, but it seems to be choking on some of the libraries. I'll let you know if I make any progress. If anyone else has some insight or can easily run valgrind on this code (assuming that it develops the same memory issues under Linux as MacOSX), that would be great.

I think that I've fixed the leak (using top to view the memory use, it now remains constant). I ran valgrind on the original code and it didn't pick anything up but there was definitely a leak. GTS has an odd interface which I would say contributed to the DOLFIN-side leak.

Garth

cheers
marc

Garth

Cheers
marc
----------------------------------------------------
Marc Spiegelman
Lamont-Doherty Earth Observatory
Dept. of Applied Physics/Applied Math
Columbia University
http://www.ldeo.columbia.edu/~mspieg
tel: 845 704 2323 (SkypeIn)
----------------------------------------------------
p.s. Some basic info
Dolfin (0.9.0) hg development version (ported to PETSc-3.0.0)
GTS (0.7.6) built from source
MacOSX 10.4.11
g++ i686-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5370)
boost 1.33.1
test code
----------------------------------------------
// Copyright (C) 2009 Marc Spiegelman
// Licensed under the GNU LGPL Version 2.1.
//
// First added:  2008-10-08
// Last changed:  5 Feb 2009 17:16:07
//
// Heavily modified from dolfin/demo/mesh/intersection code
// Program to demonstrated memory leak from large number of random GTS intersectionDetector tests
// uses boost uniform random number generator for fun
// // Note: if you just continually test the point {0.5, 0.5} (comment out the random number generator) // the number of intersected cells is 6 rather than 1 and the memory leak is much more pronounced
// #include <dolfin.h>
#include <boost/random.hpp>
using namespace dolfin;
typedef boost::mt19937 base_generator_type;
int main()
{
  // Create square mesh
  unsigned int N = 64;
  UnitSquare mesh(N, N);
  //create IntersectionDetector
  IntersectionDetector ID(mesh);
      // set initial point
  double x[2] = {0.5, 0.5 };
  Point p(2,x);
  //initialize cell Array
  std::vector<dolfin::uint> cells;
  std::vector<dolfin::uint>::iterator cellIterator;
  //setup boost uniform variate random number generators
  base_generator_type  generator(42u);
  boost::uniform_real<> uni_dist(0,1);
boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator, uni_dist);
    dolfin::uint k, k_max = N*N*5000, k_print = 100;
  dolfin::uint n_cells, n_cells_print=2;
  //calculate a random intersection k_max times
  for (k = 0; k < k_max; k++ ) {
    ID.intersection(p, cells);
    n_cells = cells.size();
//print out information if number of cells in intersection matches n_cells_print (or every k_print grid_sweep)
    if (n_cells >= n_cells_print || k%(N*N*k_print) == 0 ) {
printf("k=%d, p=[%f, %f], NCells=%d: ", k, p.x(), p.y(), (int) cells.size()) ; for (cellIterator = cells.begin(); cellIterator < cells.end(); cellIterator++) {
printf("%d ",*cellIterator);
      }
      printf("\n");
    }
    // get new random point (comment out to really blow up)
    p[0] = uni();
    p[1] = uni();
// clear cells array (cells grows with every test otherwise, not sure if this generates a memory leak)
    cells.clear();   }
  return(0);
}
------------------------------------------------------------------- -----
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx <mailto:DOLFIN-dev@xxxxxxxxxx>
http://www.fenics.org/mailman/listinfo/dolfin-dev

----------------------------------------------------
Marc Spiegelman
Lamont-Doherty Earth Observatory
Dept. of Applied Physics/Applied Math
Columbia University
http://www.ldeo.columbia.edu/~mspieg
tel: 845 704 2323 (SkypeIn)
----------------------------------------------------


----------------------------------------------------
Marc Spiegelman
Lamont-Doherty Earth Observatory
Dept. of Applied Physics/Applied Math
Columbia University
http://www.ldeo.columbia.edu/~mspieg
tel: 845 704 2323 (SkypeIn)
----------------------------------------------------



References