[Coin-lpsolver] Re: Re: Memory leaks (John J Forrest)

John J Forrest jjforre at us.ibm.com
Thu Sep 13 16:54:33 EDT 2007


Xavier,

With your new example, I eventually managed to get it to give me a memory 
leak with Clp/stable.  The putative leak is in Clp/trunk but is very 
unlikely to occur as the +-1 matrix is switched off by default and can not 
easily be switched on using OsiClpSolverInterface.

So I would switch to trunk.  I will fix leak anyway - but that will only 
be in trunk.  If you need a +-1 matrix for speed (and are not doing branch 
and cut) then you will have to wait a day or two.

John Forrest



"xavier warin" <xavier.warin at gmail.com> 
Sent by: coin-lpsolver-bounces at list.coin-or.org
09/13/2007 07:24 AM

To
coin-lpsolver at list.coin-or.org
cc
Olivier CORMIER <olivier.cormier at edf.fr>
Subject
[Coin-lpsolver] Re: Re: Memory leaks (John J Forrest)






Dear John

I agree on the small example i gave you. In fact i noticed yesterday that 
i was perhaps linking against an old coin version.
I crashed my whole installation and i installed Coin again.
On the small example i gave you, no problem if you add the good delete. 
On our own problem the problem is  present on Linux and Windows.

While doing optimization on the small following problem :

  //// Interface de résolution COIN
  boost::shared_ptr<OsiSolverInterface> bsi; 
  bsi = boost::shared_ptr<OsiSolverInterface> ( new OsiClpSolverInterface 
);
 
  // nombre de dates d'exercices
  int N = exerc.size() ;

  //  nombre de colonnes
  int n_cols = 2*N ;

  Array<double,1> bobjective(n_cols);
  Array<double,1> bcol_lb(n_cols);
  Array<double,1> bcol_ub(n_cols);

  // fonction objectif
  for (int i = 0 ; i < N ; ++i)
    {
      bobjective(i) =  - (future(i+1)- 
Cout_Tirage(i+1))*exp(-taux(i+1))*Duree(i+1) ; 
      bobjective(i+N) = (future(i+1) + 
Cout_Injection(i+1))*exp(-taux(i+1))*Duree(i+1);
    }
  for (int i = 0 ; i < N ; ++i)
    {
      bcol_lb(i) =  0.;
      bcol_lb(i+N) = 0.;
      bcol_ub(i) = Tirage(i+1); 
      bcol_ub(i+N) =  Injection(i+1);
    }
 
 
  // pour la matrice des contraintes
  int n_rows = N ;
 
  Array<double,1> brow_lb(n_rows);
  Array<double,1> brow_ub(n_rows); 
 
  // création matrice contrainte
  Array<int,1> bligne(N*(N+1));
  Array<int,1> bcolonne(N*(N+1));
  Array<double,1> belement(N*(N+1));
  int ielement = 0;

  for (int j = 0 ; j < N ; ++j) 
  {
    brow_lb(j) = Stock_Min(j+2) -Stock_Init ;
    brow_ub(j) = Stock_Max(j+2) -Stock_Init ;
    for (int i = 0  ;   i <= j   ; ++i)
      {
    double d = 1.;
    bcolonne(ielement) = i;
    bligne(ielement) = j; 
    belement(ielement) = -d;
    ielement++;
 
    bcolonne(ielement) = i+N;
    bligne(ielement) = j;
    belement(ielement) = d;
    ielement++;
      }
  }


  bsi->loadProblem(CoinPackedMatrix(false, bligne.data(), bcolonne.data(), 
belement.data(), ielement), 
           bcol_lb.data(), bcol_ub.data(), bobjective.data(), 
brow_lb.data(), brow_ub.data());
 
  bsi->initialSolve();

  // Check the solution 
  My_assert( bsi->isProvenOptimal() ) ;
#if defined(BZ_DEBUG)
  std::cout << "Found optimal solution!" << std::endl; 
  std::cout << "Objective value bsi is " << bsi->getObjValue() << 
std::endl; 
#endif


//  const double *solution;
  const double *bsolution;
  bsolution = bsi->getColSolution();
  // sortie Blitz des valeurs de tirages puis d'injection en chaque date 
d'exercice
  Array<double,1> sortie(n_cols, blitz::fortranArray);
  for(int i = 1; i <= n_cols; i++)
    sortie(i) = bsolution[i-1] ;    // stockage du resultat

There are leaks.
Using valgrind we found that it is due to an allocation of a 
CoinPackedMatrix in 

==29301== 1,560 bytes in 26 blocks are definitely lost in loss record 657 
of 723
==29301==    at 0x401DB31: operator new(unsigned) 
(vg_replace_malloc.c:163)
==29301==    by 0x783B56B: ClpPlusMinusOneMatrix::getPackedMatrix() const 
( ClpPlusMinusOneMatrix.cpp:1049)
==29301==    by 0x77DBAF0: ClpModel::matrix() const (ClpModel.hpp:555)
==29301==    by 0x786144A: ClpSimplex::tightenPrimalBounds(double, int) 
(ClpSimplex.cpp:3939)
==29301==    by 0x78ADAD1: ClpSimplex::initialSolve(ClpSolve&) ( 
ClpSolve.cpp:856)
==29301==    by 0x77DB54F: OsiClpSolverInterface::initialSolve() 
(OsiClpSolverInterface.cpp:274)

This is due to the fact that there are 1. in the constraint matrix. In 
this case we use  ClpPLusMinusOneMatrix ::getPackedMatrix() with an 
allocation. 
When we slightly shift the value to 1. + epsilon  the problem disappear 
because we don't construct this matrix anymore.

I hope it will help you.
Sincerely yours

Xavier Warin_______________________________________________
Coin-lpsolver mailing list
Coin-lpsolver at list.coin-or.org
http://list.coin-or.org/mailman/listinfo/coin-lpsolver

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/clp/attachments/20070913/f8130b71/attachment.html>


More information about the Clp mailing list