00001
00005
00006 #ifndef HBMLB_H
00007 #define HBMLB_H
00008
00009 #include "CentralLB.h"
00010 #include "HbmLB.decl.h"
00011
00012 #include "topology.h"
00013
00014 void CreateHbmLB();
00015
00017 typedef LBMigrateMsg NLBMigrateMsg;
00018
00019
00020 class MyHmbHierarchyTree {
00021 public:
00022 MyHmbHierarchyTree() {}
00023 virtual ~MyHmbHierarchyTree() {}
00024 virtual int numLevels() = 0;
00025 virtual int parent(int mype, int level) = 0;
00026 virtual bool isroot(int mype, int level) = 0;
00027 virtual int numChildren(int mype, int level) = 0;
00028 virtual void getChildren(int mype, int level, int *children, int &count) = 0;
00029 };
00030
00031
00032
00033
00034
00035
00036
00037 class HypercubeTree: public MyHmbHierarchyTree {
00038 private:
00039 int toproot;
00040 int nLevels;
00041 public:
00042 HypercubeTree() {
00043 nLevels = 0;
00044 int npes = CkNumPes();
00045 while ( npes != (1 << nLevels)) { nLevels++; }
00046 nLevels++;
00047 toproot = 0;
00048 }
00049 virtual ~HypercubeTree() {}
00050 virtual int numLevels() { return nLevels; }
00051 virtual int parent(int mype, int level) {
00052 if (level == nLevels-1) return -1;
00053 return (mype & ~(1<<level));
00054 }
00055 virtual bool isroot(int mype, int level) {
00056 if (level == 0) return false;
00057 return (mype & ((1<<level)-1)) == 0;
00058 }
00059 virtual int numChildren(int mype, int level) {
00060 return 2;
00061 }
00062 virtual void getChildren(int mype, int level, int *children, int &count) {
00063 CmiAssert(isroot(mype, level));
00064 count = numChildren(mype, level);
00065 children[0] = mype;
00066 children[1] = mype | (1<<(level-1));
00067 }
00068 };
00069
00070 class HbmLB : public CBase_HbmLB
00071 {
00072 public:
00073 HbmLB(const CkLBOptions &);
00074 HbmLB(CkMigrateMessage *m):CBase_HbmLB(m) {}
00075 ~HbmLB();
00076
00077 static void staticAtSync(void*);
00078 void AtSync(void);
00079 void ProcessAtSync(void);
00080
00081 void ReceiveStats(double t, int frompe, int fromlevel);
00082 void ResumeClients(double result);
00083 void ResumeClients(int balancing);
00084 void ReceiveMigrationCount(int, int lblevel);
00085 void ReceiveMigrationDelta(double t, int lblevel, int level);
00086
00087
00088 static void staticMigrated(void* me, LDObjHandle h, int waitBarrier);
00089 void Migrated(LDObjHandle h, int waitBarrier);
00090 void ObjMigrated(LDObjData data, LDCommData *cdata, int n);
00091 void collectCommData(int objIdx, CkVec<LDCommData> &comms);
00092
00093 void MigrationDone(int balancing);
00094 void NotifyObjectMigrationDone(int level, int lblevel);
00095 virtual void Loadbalancing(int level);
00096 void LoadbalancingDone(int level);
00097 void ReceiveResumeClients(int fromlevel, int balancing);
00098 void reportLBQulity(double mload, double mCpuLoad, double totalload, int nmsgs, double bytesentry );
00099
00100 struct MigrationRecord {
00101 LDObjHandle handle;
00102 int fromPe;
00103 int toPe;
00104 MigrationRecord(): fromPe(-1), toPe(-1) {}
00105 MigrationRecord(LDObjHandle &k, int f, int t): handle(k), fromPe(f), toPe(t) {}
00106 void pup(PUP::er &p) { p|handle; p|fromPe; p|toPe; }
00107 };
00108
00109 private:
00110 int foundNeighbors;
00111 LDStats myStats;
00112
00113 protected:
00114 virtual bool QueryBalanceNow(int) { return true; };
00115 virtual bool QueryMigrateStep(int) { return true; };
00116
00117 virtual void work(LDStats* stats);
00118
00119 virtual int useMem();
00120 int NeighborIndex(int pe, int atlevel);
00121
00122 MyHmbHierarchyTree *tree;
00123
00124 class LevelData {
00125 public:
00126 int parent;
00127 int* children;
00128 int nChildren;
00129 double statsList[2];
00130 int stats_msg_count;
00131 LDStats *statsData;
00132 int obj_expected, obj_completed;
00133 int migrates_expected, migrates_completed;
00134 int mig_reported;
00135 int info_recved;
00136 int vector_expected, vector_completed;
00137 int resumeAfterMigration;
00138 CkVec<MigrationRecord> outObjs;
00139 CkVec<Location> unmatchedObjs;
00140 CkVec<Location> matchedObjs;
00141 public:
00142 LevelData(): parent(-1), children(NULL), nChildren(0), stats_msg_count(0),
00143 statsData(NULL), obj_expected(-1), obj_completed(0),
00144 migrates_expected(-1), migrates_completed(0),
00145 mig_reported(0), info_recved(0),
00146 vector_expected(-1), vector_completed(0),
00147 resumeAfterMigration(0)
00148 { statsList[0] = statsList[1] = 0.0; }
00149 ~LevelData() {
00150 if (children) delete [] children;
00151 if (statsData) delete statsData;
00152 }
00153 int migrationDone() {
00154
00155 return (migrates_expected == 0 || (migrates_completed == migrates_expected && obj_completed == migrates_expected));
00156 }
00157 int vectorReceived() {
00158 return vector_expected==0 || vector_expected == vector_completed;
00159 }
00160 void clear() {
00161 obj_expected = -1;
00162 obj_completed = 0;
00163 migrates_expected = -1;
00164 migrates_completed = 0;
00165 mig_reported = 0;
00166 info_recved = 0;
00167 vector_expected = -1;
00168 vector_completed = 0;
00169 resumeAfterMigration = 0;
00170 statsList[0] = statsList[1] = 0.0;
00171 if (statsData) statsData->clear();
00172 outObjs.free();
00173 matchedObjs.free();
00174 unmatchedObjs.free();
00175 }
00176 int useMem() {
00177 int memused = sizeof(LevelData);
00178 if (statsData) memused += statsData->useMem();
00179 memused += outObjs.size() * sizeof(MigrationRecord);
00180 memused += (unmatchedObjs.size()+matchedObjs.size()) * sizeof(Location);
00181 return memused;
00182 }
00183 };
00184
00185 CkVec<LevelData *> levelData;
00186
00187 int currentLevel;
00188 int lbLevel;
00189
00190 private:
00191 void FindNeighbors();
00192
00193 int migrate_expected;
00194 LBMigrateMsg** mig_msgs;
00195 int mig_msgs_received;
00196 int cur_ld_balancer;
00197 double start_lb_time;
00198
00199 double maxLoad;
00200 double maxCpuLoad;
00201 double maxCommBytes;
00202 int maxCommCount;
00203 double totalLoad;
00204 double maxMem;
00205
00206 int vector_n_moves;
00207
00208 CkVec<LDObjHandle> newObjs;
00209 };
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 #endif
00238