LdbCoordinator.h

Go to the documentation of this file.
00001 
00007 /*****************************************************************************
00008  * $Source: /home/cvs/namd/cvsroot/namd2/src/LdbCoordinator.h,v $
00009  * $Author: jim $
00010  * $Date: 2013/09/06 19:11:37 $
00011  * $Revision: 1.47 $
00012  *****************************************************************************/
00013 
00014 #ifndef LDBCOORDINATOR_H
00015 #define LDBCOORDINATOR_H
00016 
00017 #include <stdio.h>
00018 
00019 #include <charm++.h>
00020 #include <LBDatabase.h>
00021 
00022 #include "NamdTypes.h"
00023 #include "BOCgroup.h"
00024 #include "LdbCoordinator.decl.h"
00025 
00033 #if CMK_LBID_64BIT
00034 typedef CmiUInt8 LdbId;
00035 #else
00036 typedef LDObjid LdbId;
00037 #endif
00038 
00039 inline const int& LdbIdField(const LdbId& id, const int index) {
00040 #if CMK_LBID_64BIT
00041   return *(((int*)&id) + index);
00042 #else
00043   return id.id[index];
00044 #endif
00045 }
00046 
00047 inline int& LdbIdField(LdbId& id, const int index) {
00048 #if CMK_LBID_64BIT
00049   return *(((int*)&id) + index);
00050 #else
00051   return id.id[index];
00052 #endif
00053 }
00054 
00059 enum {
00060   NONBONDED_OR_SELF_TYPE = -1,  
00061   PATCH_TYPE = -2,              
00062   BONDED_TYPE = -3              
00063 };
00064 
00065 class PatchMap;
00066 class ComputeMap;
00067 class Controller;
00068 class Sequencer;
00069 class computeInfo;
00070 class patchInfo;
00071 class processorInfo;
00072 
00073 enum {LDB_PATCHES = 4096};
00074 enum {LDB_COMPUTES = 16384};
00075 enum {COMPUTEMAX = 16384};
00076 enum {PATCHMAX = 4096};
00077 enum {PROCESSORMAX = 512};
00078 
00079 void LdbCoordinator_initproc();
00080 
00081 class LdbCoordinator : public CBase_LdbCoordinator
00082 {
00083 public:
00084   LdbCoordinator();
00085   ~LdbCoordinator(void);
00086   static LdbCoordinator *Object()  { 
00087     return CkpvAccess(LdbCoordinator_instance); 
00088   }
00089 
00090   void initialize(PatchMap *pmap, ComputeMap *cmap, int reinit=0);
00091   void createLoadBalancer();
00092   void patchLoad(PatchID id, int nAtoms, int timestep);
00093 
00094   void startWork(const LDObjHandle &handle) {  // start timer
00095     theLbdb->ObjectStart(handle);
00096   }
00097   void pauseWork(const LDObjHandle &handle) {  // stop timer only
00098     theLbdb->ObjectStop(handle);
00099   }
00100   void skipWork(const LDObjHandle &handle) {  // increment counter only
00101     nComputesReported++;
00102   }
00103   void endWork(const LDObjHandle &handle) {  // both
00104     theLbdb->ObjectStop(handle);
00105     nComputesReported++;
00106   }
00107 
00108   void rebalance(Sequencer *seq, PatchID id);
00109   void rebalance(Controller *seq);
00110   void nodeDone(CkReductionMsg *);
00111   void updateComputesReady();
00112   void barrier(void);
00113   void resume(void);
00114   void resumeReady(CkQdMsg *msg);
00115   void resume2(void);
00116   int getNumStepsToRun(void) { return numStepsToRun; }
00117   static void staticMigrateFn(LDObjHandle handle, int dest);
00118   static void staticStatsFn(LDOMHandle h, int state);
00119   static void staticQueryEstLoadFn(LDOMHandle h);
00120   static void staticReceiveAtSync(void* data);
00121   static void staticResumeFromSync(void* data);
00122   void ReceiveAtSync(void);
00123   void Migrate(LDObjHandle handle, int dest);
00124   void RecvMigrate(LdbMigrateMsg*);
00125   void ExpectMigrate(LdbMigrateMsg*);
00126   void ResumeFromSync(void);
00127 
00128 public:
00129   void ExecuteMigrations(void);
00130   void awakenSequencers(void);
00131   int requiredProxies(PatchID id, int []);
00132   void printRequiredProxies(PatchID id, FILE *fp);
00133   void printLocalLdbReport(void);
00134 
00135   int stepsPerLdbCycle;
00136   int nLocalComputes;
00137   int nLocalPatches;
00138   int nPatchesReported;
00139   int nPatchesExpected;
00140   int nComputesReported;
00141   int nComputesExpected;
00142   int controllerReported;
00143   int controllerExpected;
00144   int nStatsMessagesReceived;
00145   int nStatsMessagesExpected;
00146   ComputeMap *computeMap;
00147   PatchMap *patchMap;
00148   int *patchNAtoms;
00149   int  nPatches;
00150   Controller *controllerThread;
00151   Sequencer **sequencerThreads;
00152 
00153   int ldbCycleNum;
00154   int numStepsToRun;    // tells Controller how many time steps to run 
00155                         // before another load balancing
00156   int firstLdbStep;
00157   int totalStepsDone;   // keeps a count of the total number of
00158                         // time steps to stop load balancing
00159   int takingLdbData;
00160 
00161   FILE *ldbStatsFP;
00162   computeInfo *computeArray;
00163   patchInfo *patchArray;
00164   processorInfo *processorArray;
00165   LBDatabase *theLbdb;
00166   LDOMid myOMid;
00167   LDOMHandle myHandle;
00168   LdbMigrateMsg *migrateMsgs;
00169   int numComputes;
00170   int nRegisteredObjs;
00171   LDBarrierClient ldBarrierHandle;
00172   int reg_all_objs;
00173   LDObjHandle* patchHandles;
00174 
00175   void sendCollectLoads(CollectLoadsMsg*);
00176   void collectLoads(CollectLoadsMsg*);
00177 private:
00178   int collPes;
00179   int reverted;
00180   int initTotalProxies;
00181   int finalTotalProxies;
00182   int initMaxPeProxies;
00183   int finalMaxPeProxies;
00184   int initMaxPatchProxies;
00185   int finalMaxPatchProxies;
00186   double initTime;
00187   double finalTime;
00188   double initMemory;
00189   double finalMemory;
00190   double initAvgPeLoad;
00191   double finalAvgPeLoad;
00192   double initMaxPeLoad;
00193   double finalMaxPeLoad;
00194 };
00195 
00196 class CollectLoadsMsg : public CMessage_CollectLoadsMsg {
00197 public:
00198   int firstPe;
00199   int lastPe;
00200   int reverted;
00201   int initTotalProxies;
00202   int finalTotalProxies;
00203   int initMaxPeProxies;
00204   int finalMaxPeProxies;
00205   int initMaxPatchProxies;
00206   int finalMaxPatchProxies;
00207   double initTime;
00208   double finalTime;
00209   double initMemory;
00210   double finalMemory;
00211   double initAvgPeLoad;
00212   double finalAvgPeLoad;
00213   double initMaxPeLoad;
00214   double finalMaxPeLoad;
00215   char strategyName[16];
00216 };
00217 
00218 class LdbMigrateMsg : public CMessage_LdbMigrateMsg
00219 {
00220 public:
00221   LDObjHandle handle;
00222   int from;
00223   int to;
00224   LdbMigrateMsg *next;
00225 };
00226 
00227 
00228 #endif // LDBCOORDINATOR_H
00229 

Generated on Sun Jul 22 01:17:14 2018 for NAMD by  doxygen 1.4.7