00001 00011 00012 #ifndef _WSLB_H_ 00013 #define _WSLB_H_ 00014 00015 #include "BaseLB.h" 00016 #include "WSLB.decl.h" 00017 00018 #include "topology.h" 00019 00020 void CreateWSLB(); 00021 00022 class WSLBStatsMsg; 00023 00024 class WSLB : public CBase_WSLB 00025 { 00026 public: 00027 WSLB(const CkLBOptions &); 00028 WSLB(CkMigrateMessage *m):CBase_WSLB(m) {} 00029 ~WSLB(); 00030 static void staticAtSync(void*); 00031 void AtSync(void); // Everything is at the PE barrier 00032 00033 void ReceiveStats(WSLBStatsMsg *); // Receive stats on PE 0 00034 void ResumeClients(); 00035 void ReceiveMigration(LBMigrateMsg *); // Receive migration data 00036 00037 // Migrated-element callback 00038 static void staticMigrated(void* me, LDObjHandle h, int waitBarrier); 00039 void Migrated(LDObjHandle h, int waitBarrier); 00040 00041 void MigrationDone(void); // Call when migration is complete 00042 int step() { return mystep; }; 00043 00044 struct LDStats { // Passed to Strategy 00045 int from_pe; 00046 double total_walltime; 00047 double total_cputime; 00048 double idletime; 00049 double bg_walltime; 00050 double bg_cputime; 00051 double obj_walltime; 00052 double obj_cputime; 00053 double usage; 00054 int proc_speed; 00055 bool vacate_me; 00056 }; 00057 00058 protected: 00059 virtual bool QueryBalanceNow(int); 00060 virtual LBMigrateMsg* Strategy(LDStats* stats,int count); 00061 #if 0 00062 virtual int num_neighbors() { 00063 return (CkNumPes() > 5) ? 4 : (CkNumPes()-1); 00064 }; 00065 virtual void neighbors(int* _n) { 00066 const int me = CkMyPe(); 00067 const int npe = CkNumPes(); 00068 if (npe > 1) 00069 _n[0] = (me + npe - 1) % npe; 00070 if (npe > 2) 00071 _n[1] = (me + 1) % npe; 00072 00073 int bigstep = (npe - 1) / 3 + 1; 00074 if (bigstep == 1) bigstep++; 00075 00076 if (npe > 3) 00077 _n[2] = (me + bigstep) % npe; 00078 if (npe > 4) 00079 _n[3] = (me + npe - bigstep) % npe; 00080 }; 00081 #endif 00082 00083 struct { 00084 int proc_speed; 00085 double total_walltime; 00086 double total_cputime; 00087 double idletime; 00088 double bg_walltime; 00089 double bg_cputime; 00090 int obj_data_sz; 00091 LDObjData* objData; 00092 int comm_data_sz; 00093 LDCommData* commData; 00094 double obj_walltime; 00095 double obj_cputime; 00096 } myStats; 00097 00098 private: 00099 void FindNeighbors(); 00100 WSLBStatsMsg* AssembleStats(); 00101 00102 LBTopology *topo; 00103 int mystep; 00104 int stats_msg_count; 00105 WSLBStatsMsg** statsMsgsList; 00106 LDStats* statsDataList; 00107 int migrates_completed; 00108 int migrates_expected; 00109 LBMigrateMsg** mig_msgs; 00110 int mig_msgs_received; 00111 int mig_msgs_expected; 00112 int* neighbor_pes; 00113 int receive_stats_ready; 00114 double start_lb_time; 00115 double first_step_time; 00116 double usage; 00117 double usage_int_err; 00118 bool vacate; 00119 }; 00120 00121 class WSLBStatsMsg : public CMessage_WSLBStatsMsg { 00122 public: 00123 int from_pe; 00124 int serial; 00125 int proc_speed; 00126 double total_walltime; 00127 double total_cputime; 00128 double idletime; 00129 double bg_walltime; 00130 double bg_cputime; 00131 double obj_walltime; 00132 double obj_cputime; 00133 double usage; 00134 bool vacate_me; 00135 }; 00136 00137 00138 #endif /* _WSLB_H_ */ 00139 00140