Changeset 2097 for trunk


Ignore:
Timestamp:
Nov 21, 2014 5:57:22 AM (4 years ago)
Author:
forrest
Message:

try and improve memory leaks (and clean up Clp pthread build problem)

Location:
trunk/Cbc/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcModel.cpp

    r2094 r2097  
    47884788        master_->stopThreads(-1);
    47894789        master_->waitForThreadsInTree(2);
    4790         delete master_;
    4791         master_ = NULL;
    4792         masterThread_ = NULL;
    47934790        // adjust time to allow for children on some systems
    47944791        //dblParam_[CbcStartSeconds] -= CoinCpuTimeJustChildren();
     
    48124809            double dummyBest;
    48134810            tree_->cleanTree(this, -COIN_DBL_MAX, dummyBest) ;
     4811#ifdef CBC_THREAD
     4812            if (parallelMode() > 0 && master_) {
     4813              // see if any dangling nodes
     4814              int numberThreads = master_->numberThreads();
     4815              for (int i=0;i<numberThreads;i++) {
     4816                CbcThread * child = master_->child(i);
     4817                //if (child->createdNode())
     4818                //printf("CHILD_NODE %p\n",child->createdNode());
     4819                delete child->createdNode();
     4820              }
     4821            }
     4822#endif
    48144823        }
    48154824        delete nextRowCut_;
     
    48504859        }
    48514860    }
     4861#ifdef CBC_THREAD
     4862    if (master_) {
     4863        delete master_;
     4864        master_ = NULL;
     4865        masterThread_ = NULL;
     4866    }
     4867#endif
    48524868    /*
    48534869      That's it, we've exhausted the search tree, or broken out of the loop because
     
    99249940    int firstOldCut = numberRowsAtContinuous_ ;
    99259941    int totalNumberCuts = numberNewCuts_ + numberOldActiveCuts_ ;
     9942    assert (numberRowsAtContinuous_+totalNumberCuts==
     9943            solver_->getNumRows());
    99269944    int *solverCutIndices = new int[totalNumberCuts] ;
    99279945    int *newCutIndices = new int[numberNewCuts_] ;
  • trunk/Cbc/src/CbcNode.cpp

    r2096 r2097  
    6666{
    6767#ifdef CHECK_NODE
    68     printf("CbcNode %x Constructor\n", this);
     68    printf("CbcNode %p Constructor\n", this);
    6969#endif
    7070}
     
    8989{
    9090#ifdef CHECK_NODE
    91     printf("CbcNode %x Constructor from model\n", this);
     91    printf("CbcNode %p Constructor from model\n", this);
    9292#endif
    9393    model->setObjectiveValue(this, lastNode);
     
    41004100  double * originalSolution;
    41014101  CoinWarmStart * ws;
     4102  double * newObjective;
    41024103# ifdef COIN_HAS_CLP
    41034104  ClpDualRowSteepest * dualRowPivot;
     
    41114112  StrongInfo * choice;
    41124113  OsiSolverInterface * solver;
     4114  double * tempSolution;
     4115  CoinWarmStart * tempBasis;
    41134116  int whichChoice;
    41144117} StrongBundle;
     
    41434146  for (int iWay=0;iWay<2;iWay++) {
    41444147    if (choice->numIters[iWay]==0) {
     4148      int numberColumns=solver->getNumCols();
    41454149      if (solveType!=100) {
    41464150        double saveBound;
     
    41974201        int numberModified=0;
    41984202        double sumModified=0.0;
    4199         int numberColumns=solver->getNumCols();
    42004203        int numberInfeas=0;
    42014204        for (int i=0;i<numberColumns;i++) {
     
    42354238        choice->movement[iWay] = newObjectiveValue ;
    42364239      } else {
     4240# ifdef COIN_HAS_CLP
     4241        OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
     4242        ClpSimplex * simplex = osiclp ? osiclp->getModelPtr() : NULL;
     4243#endif
    42374244        // doing continuous and general integer
    42384245        solver->setColSolution(staticInfo->originalSolution);
     
    42414248        double newBound;
    42424249        if (iWay==0) {
    4243           solver->setObjCoeff(iColumn,1.0);
    42444250          saveBound=solver->getColUpper()[iColumn];
    42454251          solver->setColUpper(iColumn,choice->downUpperBound);
    42464252          newBound=choice->downUpperBound;
    42474253        } else {
    4248           solver->setObjCoeff(iColumn,-1.0);
    42494254          saveBound=solver->getColLower()[iColumn];
    42504255          solver->setColLower(iColumn,choice->upLowerBound);
    42514256          newBound=choice->upLowerBound;
    42524257        }
     4258# if 0 //def COIN_HAS_CLP
     4259        if (simplex) {
     4260          // set solution to new bound (if basic will be recomputed)
     4261          simplex->primalColumnSolution()[iColumn]=newBound;
     4262        }
     4263#endif
    42534264        solver->setHintParam(OsiDoDualInResolve, true, OsiHintDo) ;
     4265#define PRINT_ANALYZE  0
     4266#if PRINT_ANALYZE>0
     4267        osiclp->getModelPtr()->setLogLevel(1);
     4268        solver->setHintParam(OsiDoReducePrint, false, OsiHintTry);
     4269#endif
    42544270        solver->resolve();
    42554271        if (iWay==0) {
     4272#if PRINT_ANALYZE>0
     4273          printf("column %d down original %g <= %g <= %g upper now %g - result %s\n",
     4274                 iColumn,solver->getColLower()[iColumn],
     4275                 staticInfo->originalSolution[iColumn],saveBound,
     4276                 newBound,solver->isProvenOptimal() ? "ok" : "infeas");
     4277#endif
    42564278          solver->setColUpper(iColumn,saveBound);
    42574279        } else {
     4280#if PRINT_ANALYZE>0
     4281          printf("column %d up original %g <= %g <= %g lower now %g - result %s\n",
     4282                 iColumn,saveBound,staticInfo->originalSolution[iColumn],
     4283                 solver->getColUpper()[iColumn],
     4284                 newBound,solver->isProvenOptimal() ? "ok" : "infeas");
     4285#endif
    42584286          solver->setColLower(iColumn,saveBound);
    42594287        }
     
    42654293          choice->movement[iWay] = newBound;
    42664294        } else {
     4295          // zero objective
     4296          double offset;
     4297          solver->getDblParam(OsiObjOffset,offset);
     4298          solver->setDblParam(OsiObjOffset, 0.0);
     4299          solver->setObjective(staticInfo->newObjective+numberColumns);
     4300          if (iWay==0) {
     4301            solver->setObjCoeff(iColumn,1.0);
     4302          } else {
     4303            solver->setObjCoeff(iColumn,-1.0);
     4304          }
    42674305          solver->setColSolution(staticInfo->originalSolution);
    42684306          solver->setWarmStart(staticInfo->ws);
     
    42734311          choice->movement[iWay] = solver->getColSolution()[iColumn];
    42744312          choice->numIters[iWay] += solver->getIterationCount();
     4313#if PRINT_ANALYZE>0
     4314          if (iWay==0) {
     4315            printf("column %d down can get to %g - result %s\n",
     4316                 iColumn,solver->getColSolution()[iColumn],solver->isProvenOptimal() ? "ok" : "infeas");
     4317          } else {
     4318            printf("column %d up can get to %g - result %s\n",
     4319                 iColumn,solver->getColSolution()[iColumn],solver->isProvenOptimal() ? "ok" : "infeas");
     4320          }
     4321#endif
     4322          // reset objective
     4323          solver->setDblParam(OsiObjOffset, offset);
     4324          solver->setObjective(staticInfo->newObjective);
    42754325          if (!solver->isProvenOptimal()) {
     4326# ifdef COIN_HAS_CLP
     4327            OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
     4328            ClpSimplex * simplex = osiclp->getModelPtr();
     4329            double sum = simplex->sumPrimalInfeasibilities();
     4330            sum /= static_cast<double>(simplex->numberPrimalInfeasibilities());
     4331            if (sum>1.0e-3) {
     4332#endif
    42764333            choice->modified[0]=1;
    42774334            returnStatus=1;
     4335            solver->writeMps("bad","mps");
     4336            abort();
     4337# ifdef COIN_HAS_CLP
     4338            }
     4339#endif
    42784340          }
    42794341        }
    4280         solver->setObjCoeff(iColumn,0.0);
     4342        //solver->setObjCoeff(iColumn,0.0);
    42814343      }
    42824344    }
     
    42844346  return returnStatus;
    42854347}
    4286 #ifdef CBC_THREAD
     4348#ifdef THREADS_IN_ANALYZE
    42874349void * cbc_parallelManager(void * stuff)
    42884350{
     
    43174379    if (unLock==3)
    43184380      unLock=0;
    4319     //printf("child pointer %x status %d\n",threadInfo,threadInfo->status);
     4381    //printf("child pointer %p status %d\n",threadInfo,threadInfo->status);
    43204382    assert(threadInfo->status>=0);
    43214383    if (threadInfo->status==1000)
     
    45584620  StrongInfo * choices = new StrongInfo[maxChoices];
    45594621  StrongStaticInfo staticInfo;
    4560   StrongBundle * bundles = new StrongBundle[CoinMax(1,numberThreads)];
     4622  int numberBundles = CoinMax(1,numberThreads);
     4623  StrongBundle * bundles = new StrongBundle[numberBundles];
    45614624  /*
    45624625    0 - available - no need to look at results
     
    45934656  }
    45944657#endif
    4595   for (int i=0;i<CoinMax(1,numberThreads);i++)
     4658  for (int i=0;i<numberBundles;i++) {
     4659    memset(bundles+i,0,sizeof(StrongBundle));
    45964660    bundles[i].staticInfo=&staticInfo;
    4597 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP)
     4661  }
     4662#if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP)
    45984663#define USE_STRONG_THREADS
    45994664  CoinPthreadStuff threadInfo(numberThreads,cbc_parallelManager);
     
    51435208  if ((solveType&2)!=0) {
    51445209# ifdef COIN_HAS_CLP
    5145   if (osiclp&&(solveType&2)!=0) {
    5146     ClpPrimalColumnPivot * primalColumnPivot=NULL;
    5147   }
     5210    int saveOptions = osiclp ? osiclp->specialOptions() : 0;
     5211    if (osiclp) {
     5212      //ClpPrimalColumnPivot * primalColumnPivot=NULL;
     5213      osiclp->setSpecialOptions(saveOptions|2048); // off crunch
     5214    }
    51485215#endif
    51495216    double * newLower = new double [2*numberColumns];
     
    51515218    // look at ints/all - should be parametrics - for now primal
    51525219    OsiSolverInterface * temp = solver->clone();
     5220    // add constraint
     5221    int * indices = reinterpret_cast<int *>(newUpper);
     5222    double * obj = newLower;
     5223    memcpy(obj,solver->getObjCoefficients(),numberColumns*sizeof(double));
     5224    int n=0;
     5225    for (int i=0;i<numberColumns;i++) {
     5226      if (obj[i]) {
     5227        indices[n]=i;
     5228        obj[n++]=obj[i];
     5229      }
     5230    }
     5231    if (n) {
     5232      double cutoff=model->getCutoff();
     5233      // relax a little bit
     5234      cutoff += 1.0e-4;
     5235      double offset;
     5236      temp->getDblParam(OsiObjOffset, offset);
     5237      temp->addRow(n,indices,obj,-COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset);
     5238      temp->setDblParam(OsiObjOffset, 0.0);
     5239#if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP)
     5240      for (int iThread=0;iThread<numberThreads;iThread++) {
     5241        OsiSolverInterface * solver=
     5242          reinterpret_cast<OsiSolverInterface *>(threadInfo.threadInfo_[iThread].extraInfo2);
     5243        solver->addRow(n,indices,obj,-COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset);
     5244      }
     5245#endif
     5246    }
    51535247    //temp->setHintParam(OsiDoDualInResolve, false, OsiHintDo) ;
    51545248    temp->setHintParam(OsiDoReducePrint, true, OsiHintTry);
     
    51665260    ws = temp->getWarmStart();
    51675261    staticInfo.ws=ws;
    5168     // add constraint
    5169     int * indices = reinterpret_cast<int *>(newUpper);
    5170     double * obj = newLower;
    5171     memcpy(obj,solver->getObjCoefficients(),numberColumns*sizeof(double));
    5172     int n=0;
    5173     for (int i=0;i<numberColumns;i++) {
    5174       if (obj[i]) {
    5175         indices[n]=i;
    5176         obj[n++]=obj[i];
    5177       }
    5178     }
    5179     if (n) {
    5180       double cutoff=model->getCutoff();
    5181       // relax a little bit
    5182       cutoff += 1.0e-4;
    5183       double offset;
    5184       temp->getDblParam(OsiObjOffset, offset);
    5185       temp->addRow(n,indices,obj,-COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset);
    5186 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP)
    5187       for (int iThread=0;iThread<numberThreads;iThread++) {
    5188         OsiSolverInterface * solver=
    5189           reinterpret_cast<OsiSolverInterface *>(threadInfo.threadInfo_[iThread].extraInfo2);
    5190         solver->addRow(n,indices,obj,-COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset);
    5191       }
    5192 #endif
    5193     }
    5194     // zero objective
    5195     for (int i = 0; i < numberColumns; i++) {
    5196       newLower[i]=0.0;
    5197     }
    5198     temp->setObjective(newLower);
    5199 #if defined (CBC_THREAD) && defined (COIN_HAS_CLP)
     5262    staticInfo.newObjective = new double[2*numberColumns];
     5263    memcpy(staticInfo.newObjective,solver->getObjCoefficients(),numberColumns*sizeof(double));
     5264    memset(staticInfo.newObjective+numberColumns,0,numberColumns*sizeof(double));
     5265#if defined (THREADS_IN_ANALYZE) && defined (COIN_HAS_CLP)
    52005266    for (int iThread=0;iThread<numberThreads;iThread++) {
    52015267      OsiSolverInterface * solver=
     
    53185384          // go down
    53195385          double value = choice.movement[0];
    5320           if (value>newLower[iColumn]+10.0*integerTolerance) {
     5386          if (value>newLower[iColumn]+100.0*integerTolerance) {
    53215387            if (back[iColumn]>=0)
    53225388              value = ceil(value);
    53235389            else
    5324               value = CoinMax(newLower[iColumn],value-1.0e-7-1.0e-8*fabs(value));
     5390              value = CoinMax(newLower[iColumn],value-1.0e-5-1.0e-8*fabs(value));
    53255391            if (value>newLower[iColumn]+1.0e-8*(1.0+fabs(value))) {
    53265392              sprintf(general,"Secondary analysis solve increases lower bound on %d from %g to %g%s",
     
    53445410          // go up
    53455411          double value=choice.movement[1];
    5346           if (value<newUpper[iColumn]-10.0*integerTolerance) {
     5412          if (value<newUpper[iColumn]-100.0*integerTolerance) {
    53475413            if (back[iColumn]>=0)
    53485414              value = floor(value);
    53495415            else
    5350               value = CoinMin(newUpper[iColumn],value+1.0e-7+1.0e-8*fabs(value));
     5416              value = CoinMin(newUpper[iColumn],value+1.0e-5+1.0e-8*fabs(value));
    53515417            if (value<newUpper[iColumn]-1.0e-8*(1.0+fabs(value))) {
    53525418              sprintf(general,"Secondary analysis solve decreases upper bound on %d from %g to %g%s",
     
    54005466    delete temp;
    54015467    delete [] newLower;
     5468# ifdef COIN_HAS_CLP
     5469    if (osiclp) {
     5470      //ClpPrimalColumnPivot * primalColumnPivot=NULL;
     5471      osiclp->setSpecialOptions(saveOptions);
     5472    }
     5473#endif
    54025474  }
     5475  delete [] staticInfo.newObjective;
    54035476# ifdef COIN_HAS_CLP
    54045477  if (osiclp) {
     
    54395512  }
    54405513  delete [] choices;
     5514  for (int i=0;i<numberBundles;i++) {
     5515    delete [] bundles[i].tempSolution;
     5516    delete bundles[i].tempBasis;
     5517  }
    54415518  delete [] bundles;
    54425519#ifdef USE_STRONG_THREADS
     
    55155592{
    55165593#ifdef CHECK_NODE
    5517     printf("CbcNode %x Constructor from rhs %x\n", this, &rhs);
     5594    printf("CbcNode %p Constructor from rhs %p\n", this, &rhs);
    55185595#endif
    55195596    if (rhs.nodeInfo_)
     
    55695646#ifdef CHECK_NODE
    55705647    if (nodeInfo_) {
    5571         printf("CbcNode %x Destructor nodeInfo %x (%d)\n",
     5648        printf("CbcNode %p Destructor nodeInfo %p (%d)\n",
    55725649               this, nodeInfo_, nodeInfo_->numberPointingToThis());
    55735650        //assert(nodeInfo_->numberPointingToThis()>=0);
    55745651    } else {
    5575         printf("CbcNode %x Destructor nodeInfo %x (?)\n",
     5652        printf("CbcNode %p Destructor nodeInfo %p (?)\n",
    55765653               this, nodeInfo_);
    55775654    }
     
    55885665            delete nodeInfo_;
    55895666        } else {
    5590             //printf("node %x nodeinfo %x parent %x\n",this,nodeInfo_,nodeInfo_->parent());
     5667            //printf("node %p nodeinfo %p parent %p\n",this,nodeInfo_,nodeInfo_->parent());
    55915668            // anyway decrement parent
    55925669            //if (parent)
  • trunk/Cbc/src/CbcNodeInfo.cpp

    r1943 r2097  
    6262{
    6363#ifdef CHECK_NODE
    64     printf("CbcNodeInfo %x Constructor\n", this);
     64    printf("CbcNodeInfo %p Constructor\n", this);
    6565#endif
    6666}
     
    108108{
    109109#ifdef CHECK_NODE
    110     printf("CbcNodeInfo %x Constructor from parent %x\n", this, parent_);
     110    printf("CbcNodeInfo %p Constructor from parent %p\n", this, parent_);
    111111#endif
    112112    //setParentBasedData();
     
    129129{
    130130#ifdef CHECK_NODE
    131     printf("CbcNodeInfo %x Copy constructor\n", this);
     131    printf("CbcNodeInfo %p Copy constructor\n", this);
    132132#endif
    133133    if (numberCuts_) {
     
    164164{
    165165#ifdef CHECK_NODE
    166     printf("CbcNodeInfo %x Constructor from parent %x\n", this, parent_);
     166    printf("CbcNodeInfo %p Constructor from parent %p\n", this, parent_);
    167167#endif
    168168    //setParentBasedData();
     
    177177{
    178178#ifdef CHECK_NODE
    179     printf("CbcNodeInfo %x Destructor parent %x\n", this, parent_);
     179    printf("CbcNodeInfo %p Destructor parent %p\n", this, parent_);
     180    printf("cuts %p - number %d\n",cuts_,numberCuts_);
    180181#endif
    181182
     
    219220            int number = cuts_[i]->decrement(changeThis);
    220221            if (!number) {
    221                 //printf("info %x del cut %d %x\n",this,i,cuts_[i]);
     222                //printf("info %p del cut %d %p\n",this,i,cuts_[i]);
    222223#ifndef GLOBAL_CUTS_JUST_POINTERS
    223224                delete cuts_[i];
     
    398399            CbcCountRowCut * thisCut = cut[i];
    399400            thisCut->setInfo(this, numberCuts_);
    400             //printf("info %x cut %d %x\n",this,i,thisCut);
     401            //printf("info %p cut %d %p\n",this,i,thisCut);
    401402            thisCut->increment(numberToBranchOn);
    402403            cuts_[numberCuts_++] = thisCut;
  • trunk/Cbc/src/CbcThread.cpp

    r2094 r2097  
    651651    int anyLeft = 0;
    652652    // May be able to combine parts later
    653 
    654653    if (type == 0) {
    655654        bool locked = true;
     
    662661            for (iThread = 0; iThread < numberThreads_; iThread++) {
    663662                if (children_[iThread].status()) {
    664                     if (children_[iThread].returnCode() == 0)
     663                  if (children_[iThread].returnCode() == 0) {
    665664                        break;
     665                  }
    666666                }
    667667            }
     
    766766        // Start one off if any available
    767767        for (iThread = 0; iThread < numberThreads_; iThread++) {
    768             if (children_[iThread].returnCode() == -1)
     768          if (children_[iThread].returnCode() == -1) {
    769769                break;
     770          }
    770771        }
    771772        if (iThread < numberThreads_) {
     
    889890            if (children_[i].deterministic() > 0)
    890891                delete [] children_[i].delNode();
     892            if (children_[i].node()) {
     893              delete children_[i].node();
     894              children_[i].setNode(NULL);
     895            }
    891896            children_[i].setReturnCode( 0);
    892897            children_[i].unlockFromMaster();
     
    14281433CbcModel::moveToModel(CbcModel * baseModel, int mode)
    14291434{
     1435#ifdef THREAD_DEBUG
     1436    {
     1437      CbcThread * stuff = reinterpret_cast<CbcThread *> (masterThread_);
     1438      if (stuff)
     1439        printf("mode %d node_ %p createdNode_ %p - stuff %p\n",
     1440               mode,stuff->node(),stuff->createdNode(),stuff);
     1441      else
     1442        printf("mode %d null stuff\n",mode);
     1443    }
     1444#endif
    14301445    if (mode == 0) {
    14311446        setCutoff(baseModel->getCutoff());
  • trunk/Cbc/src/CbcTree.cpp

    r2094 r2097  
    646646            // take off node
    647647            if (model->addedCuts()[i]) {
    648                 if (model->parallelMode()!=1) {
     648                if (model->parallelMode()!=1||true) {
    649649                  if (!model->addedCuts()[i]->decrement(numberLeft))
    650650                    delete model->addedCuts()[i];
     
    653653          }
    654654        }
     655#ifdef CBC_THREAD
     656        if (model->parallelMode() > 0 && model->master()) {
     657          // delete reference to node
     658          int numberThreads = model->master()->numberThreads();
     659          for (int i=0;i<numberThreads;i++) {
     660            CbcThread * child = model->master()->child(i);
     661            if (child->createdNode()==node)
     662              child->setCreatedNode(NULL);
     663          }
     664        }
     665#endif
    655666        // node should not have anything pointing to it
    656667        if (node->nodeInfo())
  • trunk/Cbc/src/unitTestClp.cpp

    r2094 r2097  
    229229    PUSH_MPS("harp2", 112, 2993, -73899798.00, -74353341.502, 6, false);
    230230    PUSH_MPS("khb05250", 101, 1350, 106940226, 95919464.0, 0, false);
    231 #endif
    232231    PUSH_MPS("l152lav", 97, 1989, 4722, 4656.36, 1, false);
    233232    PUSH_MPS("lseu", 28, 89, 1120, 834.68, 0, false);
     
    266265    PUSH_MPS("swath", 884, 6805, 497.603, 334.4968581, 7, false);
    267266    PUSH_MPS("vpm1", 234, 378, 20, 15.4167, 0, false);
     267#endif
    268268    PUSH_MPS("vpm2", 234, 378, 13.75, 9.8892645972, 0, false);
    269269  }
Note: See TracChangeset for help on using the changeset viewer.