00001
00005
00006 #ifndef BASELB_H
00007 #define BASELB_H
00008
00009 #include "LBDatabase.h"
00010
00011 #define PER_MESSAGE_SEND_OVERHEAD_DEFAULT 3.5e-5
00012 #define PER_BYTE_SEND_OVERHEAD_DEFAULT 8.5e-9
00013 #define PER_MESSAGE_RECV_OVERHEAD 0.0
00014 #define PER_BYTE_RECV_OVERHEAD 0.0
00015
00017
00022 class BaseLB: public CBase_BaseLB
00023 {
00024 protected:
00025 int seqno;
00026 const char *lbname;
00027 LBDatabase *theLbdb;
00028 LDBarrierReceiver receiver;
00029 int notifier;
00030 int startLbFnHdl;
00031 private:
00032 void initLB(const CkLBOptions &);
00033 public:
00034 struct ProcStats {
00035 int n_objs;
00036 double pe_speed;
00041 double total_walltime;
00043 double idletime;
00046 double bg_walltime;
00047 #if CMK_LB_CPUTIMER
00048 double total_cputime;
00049 double bg_cputime;
00050 #endif
00051
00052 int pe;
00053 CmiBool available;
00054 ProcStats(): n_objs(0), pe_speed(1), total_walltime(0.0), idletime(0.0),
00055 #if CMK_LB_CPUTIMER
00056 total_cputime(0.0), bg_cputime(0.0),
00057 #endif
00058 bg_walltime(0.0), pe(-1), available(CmiTrue) {}
00059 inline void clearBgLoad() {
00060 idletime = bg_walltime =
00061 #if CMK_LB_CPUTIMER
00062 bg_cputime =
00063 #endif
00064 0.0;
00065 }
00066 inline void pup(PUP::er &p) {
00067 p|total_walltime;
00068 p|idletime;
00069 p|bg_walltime;
00070 #if CMK_LB_CPUTIMER
00071 p|total_cputime;
00072 p|bg_cputime;
00073 #endif
00074 p|pe_speed;
00075 if (_lb_args.lbversion() < 1 && p.isUnpacking()) {
00076 double dummy; p|dummy;
00077 }
00078 p|available; p|n_objs;
00079 if (_lb_args.lbversion()>=2) p|pe;
00080 }
00081 };
00082
00084 struct LDStats {
00085 int count;
00086 ProcStats *procs;
00087
00088 int n_objs;
00089 int n_migrateobjs;
00090 CkVec<LDObjData> objData;
00091 CkVec<int> from_proc;
00092 CkVec<int> to_proc;
00093
00094 int n_comm;
00095 CkVec<LDCommData> commData;
00096
00097
00098 int *objHash;
00099
00100 int hashSize;
00101
00102 int complete_flag;
00103
00104
00105 LDStats(int c=0, int complete_flag=1);
00108 inline int nprocs() const { return count; }
00109 inline int &nprocs() { return count; }
00110
00111 void assign(int oid, int pe) { CmiAssert(procs[pe].available); to_proc[oid] = pe; }
00113 void makeCommHash();
00114 void deleteCommHash();
00117 int getHash(const LDObjKey &);
00118 int getHash(const LDObjid &oid, const LDOMid &mid);
00119 int getSendHash(LDCommData &cData);
00120 int getRecvHash(LDCommData &cData);
00121 void clearCommHash();
00122 void clear() {
00123 n_objs = n_migrateobjs = n_comm = 0;
00124 objData.free();
00125 commData.free();
00126 from_proc.free();
00127 to_proc.free();
00128 deleteCommHash();
00129 }
00130 void clearBgLoad() {
00131 for (int i=0; i<nprocs(); i++) procs[i].clearBgLoad();
00132 }
00133 void computeNonlocalComm(int &nmsgs, int &nbytes);
00134 double computeAverageLoad();
00135 void normalize_speed();
00136 void print();
00137
00138 void removeObject(int obj);
00139 void pup(PUP::er &p);
00140 int useMem();
00141 };
00142
00143 BaseLB(const CkLBOptions &opt) { initLB(opt); }
00144 BaseLB(CkMigrateMessage *m):CBase_BaseLB(m) {}
00145 virtual ~BaseLB();
00146
00147 void unregister();
00148 inline const char *lbName() { return lbname; }
00149 inline int step() { return theLbdb->step(); }
00150 virtual void turnOff() { CmiAbort("turnOff not implemented"); }
00151 virtual void turnOn() { CmiAbort("turnOn not implemented"); }
00152 virtual int useMem() { return 0; }
00153 virtual void pup(PUP::er &p);
00154 virtual void flushStates();
00155
00156 CkGroupID getGroupID() {return thisgroup;}
00157 };
00158
00160 struct MigrateInfo {
00161 int index;
00162 LDObjHandle obj;
00163 int from_pe;
00164 int to_pe;
00165 int async_arrival;
00166 MigrateInfo(): async_arrival(0) {}
00167 void pup(PUP::er &p) {
00168 p | index;
00169 p | obj;
00170 p | from_pe;
00171 p | to_pe;
00172 p | async_arrival;
00173 }
00174 };
00175
00179 class LBMigrateMsg : public CMessage_LBMigrateMsg {
00180 public:
00181 int level;
00182
00183 int n_moves;
00184 MigrateInfo* moves;
00185
00186 char * avail_vector;
00187 int next_lb;
00188
00189 double * expectedLoad;
00190
00191 public:
00192 #if (defined(_FAULT_MLOG_) || defined(_FAULT_CAUSAL_))
00193 int step;
00194 int lbDecisionCount;
00195 #endif
00196 LBMigrateMsg(): level(0), n_moves(0), next_lb(0) {}
00197 void pup(PUP::er &p) {
00198 int i;
00199 p | level;
00200 p | n_moves;
00201
00202
00203 p | next_lb;
00204 int numPes = CkNumPes();
00205 p | numPes;
00206 CkAssert(numPes == CkNumPes());
00207 for (i=0; i<n_moves; ++i) p | moves[i];
00208 p(avail_vector, numPes);
00209 for (i=0; i<numPes; ++i) p | expectedLoad[i];
00210 }
00211 };
00212
00213 struct VectorMigrateInfo {
00214 int from_pe;
00215 int to_pe;
00216 double load;
00217 int async_arrival;
00218 VectorMigrateInfo(): async_arrival(0) {}
00219 };
00220
00221 class LBVectorMigrateMsg : public CMessage_LBVectorMigrateMsg {
00222 public:
00223 int level;
00224
00225 int n_moves;
00226 VectorMigrateInfo* moves;
00227
00228 public:
00229 LBVectorMigrateMsg(): level(0), n_moves(0) {}
00230 };
00231
00232
00233
00234
00235
00236
00237 #if CMK_LBDB_ON
00238
00239 #define CreateLBFunc_Def(x, str) \
00240 void Create##x(void) { \
00241 int seqno = LBDatabaseObj()->getLoadbalancerTicket(); \
00242 CProxy_##x::ckNew(CkLBOptions(seqno)); \
00243 } \
00244 \
00245 BaseLB *Allocate##x(void) { \
00246 return new x((CkMigrateMessage*)NULL); \
00247 } \
00248 \
00249 static void lbinit(void) { \
00250 LBRegisterBalancer(#x, \
00251 Create##x, \
00252 Allocate##x, \
00253 str); \
00254 }
00255
00256 #else
00257
00258 #define CreateLBFunc_Def(x, str) \
00259 void Create##x(void) {} \
00260 BaseLB *Allocate##x(void) { return NULL; } \
00261 static void lbinit(void) {}
00262
00263 #endif
00264
00265 #endif
00266