Changeset 903 for trunk/Cbc


Ignore:
Timestamp:
Apr 7, 2008 4:51:02 AM (12 years ago)
Author:
forrest
Message:

exit faster if no columns and mods for threads

File:
1 edited

Legend:

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

    r899 r903  
    2323#include <cmath>
    2424#include <cfloat>
     25
    2526
    2627#ifdef COIN_HAS_CLP
     
    7172//#define CBC_DETERMINISTIC_THREAD
    7273#ifdef CBC_THREAD
     74
    7375#ifdef CBC_DETERMINISTIC_THREAD
    7476//#define DELETE_OUTSIDE
     
    7779#endif
    7880#include <pthread.h>
     81//#include "clocktime.hpp"
     82//#undef small
     83
     84struct Coin_pthread_t {
     85        pthread_t       thr;
     86        long            status;
     87};
    7988#ifndef CLP_FAST_CODE
    8089#define CBC_THREAD_DEBUG 1
     
    98107  CbcNode * node; // filled in every time
    99108  CbcNode * createdNode; // filled in every time on return
    100   pthread_t threadIdOfBase;
     109  Coin_pthread_t threadIdOfBase;
    101110  pthread_mutex_t * mutex; // for locking data
    102111  pthread_mutex_t * mutex2; // for waking up threads
     
    161170  return b;
    162171}
    163 
    164172
    165173
     
    258266
    259267
    260 
    261268#ifdef CHECK_CUT_COUNTS
    262269
     
    344351
    345352
    346 
    347353//#define CHECK_CUT_SIZE
    348354#ifdef CHECK_CUT_SIZE
     
    381387
    382388 /* End unnamed namespace for CbcModel.cpp */
    383 
    384389
    385390
     
    583588          continuousMultiplier=1.0;
    584589        else
    585           continuousMultiplier=0.5;
     590          continuousMultiplier=0.0; // 0.5 was incorrect;
    586591#ifdef COIN_DEVELOP
    587592        if (continuousMultiplier)
     
    843848  return ;
    844849}
    845 
    846850
    847851
     
    12331237    solverCharacteristics_ = NULL;
    12341238    return ;
     1239  } else if (!numberObjects_) {
     1240    // nothing to do
     1241    solverCharacteristics_ = NULL;
     1242    bestObjective_ = solver_->getObjValue()*solver_->getObjSense();
     1243    int numberColumns = solver_->getNumCols();
     1244    delete [] bestSolution_;
     1245    bestSolution_ = new double[numberColumns];
     1246    CoinCopyN(solver_->getColSolution(),numberColumns,bestSolution_);
     1247    return ;
    12351248  }
    12361249  // Convert to Osi if wanted
     
    17001713    }
    17011714  //newNode->createInfo(this,NULL,NULL,NULL,NULL,0,0) ;
    1702     newNode->nodeInfo()->addCuts(cuts,
    1703                                  newNode->numberBranches(),whichGenerator_) ;
     1715    //newNode->nodeInfo()->addCuts(cuts,
     1716    //                   newNode->numberBranches(),whichGenerator_) ;
    17041717    if (lastws) delete lastws ;
    17051718    lastws = dynamic_cast<CoinWarmStartBasis*>(solver_->getWarmStart()) ;
     
    17761789  CbcNode * createdNode=NULL;
    17771790  CbcModel ** threadModel = NULL;
    1778   pthread_t * threadId = NULL;
     1791  Coin_pthread_t * threadId = NULL;
    17791792  int * threadCount = NULL;
    17801793  pthread_mutex_t mutex;
     
    17971810  if (numberThreads_) {
    17981811    nodeCompare_->sayThreaded(); // need to use addresses
    1799     threadId = new pthread_t [numberThreads_];
     1812    threadId = new Coin_pthread_t [numberThreads_];
    18001813    threadCount = new int [numberThreads_];
    18011814    CoinZeroN(threadCount,numberThreads_);
     
    18201833      pthread_mutex_init(mutex2+i,NULL);
    18211834      pthread_cond_init(condition2+i,NULL);
    1822       threadId[i]=0;
     1835      threadId[i].status =0;
    18231836      threadInfo[i].baseModel=this;
    18241837      threadModel[i]=new CbcModel(*this);
     
    18361849      threadInfo[i].node=NULL;
    18371850      threadInfo[i].createdNode=NULL;
    1838       threadInfo[i].threadIdOfBase=pthread_self();
     1851          threadInfo[i].threadIdOfBase.thr =pthread_self();
    18391852      threadInfo[i].mutex=&mutex;
    18401853      threadInfo[i].mutex2=mutex2+i;
     
    18591872      threadInfo[i].iterationsThisTime=0;
    18601873#endif
    1861       pthread_create(threadId+i,NULL,doNodesThread,threadInfo+i);
     1874          pthread_create(&(threadId[i].thr),NULL,doNodesThread,threadInfo+i);
     1875          threadId[i].status = 1;
    18621876    }
    18631877    strategy_ = saveStrategy;
     
    19361950        int iThread;
    19371951        for (iThread=0;iThread<numberThreads_;iThread++) {
    1938           if (threadId[iThread]) {
     1952          if (threadId[iThread].status) {
    19391953            if (threadInfo[iThread].returnCode==0)
    19401954              break;
     
    19841998          // now check if any have just finished
    19851999          for (iThread=0;iThread<numberThreads_;iThread++) {
    1986             if (threadId[iThread]) {
     2000            if (threadId[iThread].status) {
    19872001              if (threadInfo[iThread].returnCode==1)
    19882002                break;
     
    20122026        }
    20132027        for (iThread=0;iThread<numberThreads_;iThread++) {
    2014           if (threadId[iThread]) {
     2028          if (threadId[iThread].status) {
    20152029            if (threadInfo[iThread].returnCode!=-1) {
    20162030              printf("bad end of tree\n");
     
    29402954      //pthread_join(threadId[i],NULL);
    29412955      int returnCode;
    2942       returnCode=pthread_join(threadId[i],NULL);
     2956          returnCode=pthread_join(threadId[i].thr,NULL);
    29432957      assert (!returnCode);
     2958          threadId[i].status = 0;
    29442959        //else
    29452960        //pthread_kill(threadId[i]); // kill rather than try and synchronize
     
    33583373  return ;
    33593374 }
    3360 
    33613375
    33623376
     
    51615175    node: (i)     So we can update dynamic pseudo costs
    51625176*/
    5163                        
     5177
    51645178
    51655179{
     
    51745188#ifdef CBC_THREAD
    51755189  CbcModel ** threadModel = NULL;
    5176   pthread_t * threadId = NULL;
     5190  Coin_pthread_t * threadId = NULL;
    51775191  pthread_cond_t condition_main;
    51785192  pthread_mutex_t condition_mutex;
     
    51825196  void * saveMutex = NULL;
    51835197  if (numberThreads_&&(threadMode_&2)!=0&&!numberNodes_) {
    5184     threadId = new pthread_t [numberThreads_];
     5198    threadId = new Coin_pthread_t [numberThreads_];
    51855199    pthread_cond_init(&condition_main,NULL);
    51865200    pthread_mutex_init(&condition_mutex,NULL);
     
    51935207      pthread_mutex_init(mutex2+i,NULL);
    51945208      pthread_cond_init(condition2+i,NULL);
    5195       threadId[i]=0;
     5209      threadId[i].status =0;
    51965210      threadModel[i]=new CbcModel;
    51975211      threadModel[i]->generator_ = new CbcCutGenerator * [1];
     
    52025216      threadInfo[i].thisModel=(CbcModel *) threadModel[i];
    52035217      threadInfo[i].baseModel=this;
    5204       threadInfo[i].threadIdOfBase=pthread_self();
     5218          threadInfo[i].threadIdOfBase.thr=pthread_self();
    52055219      threadInfo[i].mutex2=mutex2+i;
    52065220      threadInfo[i].condition2=condition2+i;
    52075221      threadInfo[i].returnCode=-1;
    5208       pthread_create(threadId+i,NULL,doCutsThread,threadInfo+i);
     5222          pthread_create(&threadId[i].thr,NULL,doCutsThread,threadInfo+i);
     5223          threadId[i].status = 1;
     5224
    52095225    }
    52105226    // Do a partial one for base model
     
    56385654        numberRowCutsAfter = theseCuts.sizeRowCuts() ;
    56395655        numberColumnCutsAfter = theseCuts.sizeColCuts() ;
    5640        
     5656
    56415657        if ((specialOptions_&1)!=0) {
    56425658          if (onOptimalPath) {
     
    56825698        }
    56835699        countRowCuts[i] += numberRowCutsAfter-numberRowCutsBefore ;
    5684        
     5700
    56855701        bool dodgyCuts=false;
    56865702        for (j = numberRowCutsBefore;j<numberRowCutsAfter;j++) {
     
    59475963        }
    59485964        countRowCuts[i] += numberRowCutsAfter-numberRowCutsBefore ;
    5949        
     5965
    59505966        for (j = numberRowCutsBefore;j<numberRowCutsAfter;j++) {
    59515967          whichGenerator_[numberBefore++] = i ;
     
    66046620        if (howOften==1)
    66056621          generator_[i]->setWhatDepth(1);
    6606        
     6622
    66076623        if (howOften>=0&&generator_[i]->generator()->mayGenerateRowCutsInTree())
    66086624          willBeCutsInTree=1;
     
    67836799      threadInfo[i].returnCode=0;
    67846800      pthread_cond_signal(threadInfo[i].condition2); // unlock
    6785       pthread_join(threadId[i],NULL);
     6801      pthread_join(threadId[i].thr,NULL);
     6802          threadId[i].status = 0;
     6803
    67866804      pthread_mutex_destroy (threadInfo[i].mutex2);
    67876805      pthread_cond_destroy (threadInfo[i].condition2);
     
    90999117          numberTightened++;
    91009118        int saveFixed=numberFixed;
    9101        
     9119
    91029120        int jColumn;
    91039121        if (generator) {
     
    94959513        delete [] addedCuts_;
    94969514        addedCuts_ = NULL;
    9497        
     9515
    94989516        // maximum depth for tree walkback
    94999517        maximumDepth_=10;
    95009518        delete [] walkback_;
    95019519        walkback_ = new CbcNodeInfo * [maximumDepth_];
    9502        
     9520
    95039521        OsiCuts cuts;
    95049522        numberOldActiveCuts_=0;
     
    1136611384        // point to useful information
    1136711385        OsiBranchingInformation usefulInfo=usefulInformation();
    11368        
     11386
    1136911387        for (iObject = 0 ; iObject < numberObjects_ ; iObject++) {
    1137011388          double infeasibility =
     
    1156911587                  } else {
    1157011588                    inBetween=true;
    11571                   }            
     11589                  }
    1157211590                } else {
    1157311591                  // must have been up branch
     
    1202012038      if (j!=data.objectNumber_) {
    1202112039        printf("bad number\n");
    12022       } 
     12040      }
    1202312041      break;
    1202412042    }
Note: See TracChangeset for help on using the changeset viewer.