parmaster.h

Go to the documentation of this file.
00001 
00034 #ifndef ABA_PARMASTER_H
00035 #define ABA_PARMASTER_H
00036 
00037 #include "abacus/abacusroot.h"
00038 #include "abacus/array.h"
00039 #include "abacus/sub.h"
00040 #include "abacus/idmap.h"
00041 #include "abacus/message.h"
00042 #include "abacus/broadcast.h"
00043 #include "abacus/dualbound.h"
00044 
00045 class ABA_MASTER;
00046 class ABA_NOTIFYSERVER;
00047 class ABA_SUBSERVER;
00048 class ABA_BALANCER;
00049 template <class Type> class ABA_IDMAP;
00050 
00051   class  ABA_PARMASTER :  public ABA_ABACUSROOT  {
00052     public:
00053 
00058       ABA_PARMASTER(ABA_MASTER *master);
00059 
00061       ~ABA_PARMASTER();
00062 
00065       void initializeParameters();
00066 
00070       void setDefaultParameters();
00071 
00075       void printParameters();
00076 
00079       void outputStatistics();
00080       int hostId() const;
00081       int hostCount() const;
00082       bool isHostZero() const;
00083       const ABA_STRING& hostname(int i) const;
00084       const ABA_STRING& hostname() const;
00085 
00092       int registerPool(void *pool);
00093 
00099       void unregisterPool(int index);
00100 
00105       void *getPool(int index);
00106       ABA_IDMAP<ABA_SUB> *subIdentificationMap() const;
00107 
00112       void connectService(int port, ABA_MESSAGE& msg, int destId);
00113       ACE_SOCK_Stream& notifyStream(int i);
00114 
00121       void newHostDualBound(double x);
00122 
00130       void newHostDualBound(ABA_MESSAGE& msg);
00131 
00134       void newPrimalBound(double x);
00135 
00139       void newPrimalBound(ABA_MESSAGE& msg);
00140 
00145       void newOpenSubCount(int n, double best);
00146 
00151       void newOpenSubCount(ABA_MESSAGE& msg);
00152 
00167       bool balance();
00168 
00183       void terminationCheck();
00184 
00188       void terminationCheck(ABA_MESSAGE& msg);
00189 
00192       void startTerminationCheck();
00193 
00199       void incWorkCount();
00200 
00206       void decWorkCount();
00207 
00210       void terminate();
00211 
00219       int newId(int fatherId);
00220       void incSubSentCount();
00221       void incSubReceivedCount();
00222       void startIdleTime();
00223       void stopIdleTime();
00224       void updateIdleTimers(bool first);
00225 
00231       void printId(int id);
00232 
00233     private:
00234       ABA_MASTER            *master_;
00235       int                    hostId_;
00236       int                    hostCount_;
00237       ABA_STRING             myHostname_;
00238       ABA_ARRAY<ABA_STRING*> hostname_;
00239       int                    connectTimeout_;
00240       ABA_ARRAY<void*>       registeredPools_;
00241       int                    lastRegisteredPool_;
00242       ABA_DUALBOUND          hostDualBounds_;
00243       ACE_Thread_Mutex       newHostDualBoundMutex_;
00244       ACE_Thread_Mutex       newPrimalBoundMutex_;
00245       int                    notifyPort_;
00246       ACE_SOCK_Stream       *notifyStreams_;
00247       ABA_NOTIFYSERVER      *notify_;
00248       int                    subserverPort_;
00249       ABA_SUBSERVER         *subserver_;
00250       int                    balancerPort_;
00251       double                 bestFirstTolerance_;
00252       ABA_BALANCER          *balancer_;
00253       ABA_ARRAY<int>         openSubCount_;
00254       ABA_DUALBOUND          openSubBest_;
00255       ACE_Thread_Mutex       newOpenSubCountMutex_;
00256       ACE_Thread_Mutex       terminationCheckMutex_;
00257       volatile bool          terminationCheckAgain_;
00258       ACE_Thread_Mutex       terminationMutex_;
00259       volatile bool          terminationOk_;
00260       volatile bool          hasTerminated_;
00261       int                    workCount_;
00262       ACE_Thread_Mutex       idCounterMutex_;
00263       int                    idCounter_;
00264       int                    subSentCount_;
00265       int                    subReceivedCount_;
00266       ABA_COWTIMER           idleCowTimeFirst_;
00267       ABA_COWTIMER           idleCowTimeMiddle_;
00268       ABA_COWTIMER           idleCowTimeLast_;
00269   };
00270 
00271 inline int ABA_PARMASTER::hostId() const {
00272   return hostId_;
00273 }
00274 
00275 inline int ABA_PARMASTER::hostCount() const {
00276   return hostCount_;
00277 }
00278 
00279 inline bool ABA_PARMASTER::isHostZero() const {
00280   return hostId_==0;
00281 }
00282 
00283 inline const ABA_STRING& ABA_PARMASTER::hostname(int i) const {
00284   return *(hostname_[i]);
00285 }
00286 
00287 inline const ABA_STRING& ABA_PARMASTER::hostname() const {
00288   return *(hostname_[hostId_]);
00289 }
00290 
00291 inline ACE_SOCK_Stream& ABA_PARMASTER::notifyStream(int i) {
00292   return notifyStreams_[i];
00293 }
00294 
00295 inline void ABA_PARMASTER::incSubSentCount() {
00296   subSentCount_++;
00297 }
00298 
00299 inline void ABA_PARMASTER::incSubReceivedCount() {
00300   subReceivedCount_++;
00301 }
00302   
00303 inline void ABA_PARMASTER::startIdleTime() {
00304   idleCowTimeLast_.start();
00305 }
00306 
00307 inline void ABA_PARMASTER::stopIdleTime() {
00308   idleCowTimeLast_.stop();
00309 }
00310 
00311 inline void ABA_PARMASTER::updateIdleTimers(bool first) {
00312   if (first)
00313     idleCowTimeFirst_.addCentiSeconds(idleCowTimeLast_.centiSeconds());
00314   else
00315     idleCowTimeMiddle_.addCentiSeconds(idleCowTimeLast_.centiSeconds());
00316   idleCowTimeLast_.reset();
00317 }
00318 
00319 #endif  // ABA_PARMASTER_H
00320 

Generated on Tue Aug 14 18:09:54 2007 for ABACUS by  doxygen 1.5.1