00001 00005 00006 #ifndef NBORBASELB_H 00007 #define NBORBASELB_H 00008 00009 #include "BaseLB.h" 00010 #include "NborBaseLB.decl.h" 00011 00012 #include "topology.h" 00013 00014 void CreateNborBaseLB(); 00015 00017 typedef LBMigrateMsg NLBMigrateMsg; 00018 00019 class NLBStatsMsg; 00020 00021 class NborBaseLB : public CBase_NborBaseLB 00022 { 00023 private: 00024 LBTopology *topo; 00025 public: 00026 NborBaseLB(const CkLBOptions &); 00027 NborBaseLB(CkMigrateMessage *m):CBase_NborBaseLB(m) {} 00028 ~NborBaseLB(); 00029 00030 static void staticAtSync(void*); 00031 void AtSync(void); // Everything is at the PE barrier 00032 00033 void ReceiveStats(CkMarshalledNLBStatsMessage &&m); // Receive stats on PE 0 00034 void ResumeClients(); 00035 void ResumeClients(int balancing); 00036 void ReceiveMigration(LBMigrateMsg *); // Receive migration data 00037 00038 // Migrated-element callback 00039 static void staticMigrated(void* me, LDObjHandle h, int waitBarrier); 00040 void Migrated(LDObjHandle h, int waitBarrier); 00041 00042 void MigrationDone(int balancing); // Call when migration is complete 00043 00044 struct LDStats { // Passed to Strategy 00045 int from_pe; 00046 LBRealType total_walltime; 00047 LBRealType idletime; 00048 LBRealType bg_walltime; 00049 LBRealType obj_walltime; 00050 #if CMK_LB_CPUTIMER 00051 LBRealType total_cputime; 00052 LBRealType bg_cputime; 00053 LBRealType obj_cputime; 00054 #endif 00055 int pe_speed; 00056 bool available; 00057 bool move; 00058 00059 int n_objs; 00060 LDObjData* objData; 00061 int n_comm; 00062 LDCommData* commData; 00063 00064 inline void clearBgLoad() { 00065 bg_walltime = idletime = 0.0; 00066 #if CMK_LB_CPUTIMER 00067 bg_cputime = 0.0; 00068 #endif 00069 } 00070 }; 00071 00072 protected: 00073 virtual bool QueryBalanceNow(int) { return true; }; 00074 virtual bool QueryMigrateStep(int) { return true; }; 00075 virtual LBMigrateMsg* Strategy(LDStats* stats, int n_nbrs); 00076 00077 int NeighborIndex(int pe); // return the neighbor array index 00078 00079 LDStats myStats; 00080 00081 private: 00082 void FindNeighbors(); 00083 NLBStatsMsg* AssembleStats(); 00084 00085 int stats_msg_count; 00086 NLBStatsMsg** statsMsgsList; 00087 LDStats* statsDataList; 00088 int migrates_completed; 00089 int migrates_expected; 00090 LBMigrateMsg** mig_msgs; 00091 int mig_msgs_received; 00092 int mig_msgs_expected; 00093 int* neighbor_pes; 00094 bool receive_stats_ready; 00095 double start_lb_time; 00096 }; 00097 00098 class NLBStatsMsg { 00099 public: 00100 int from_pe; 00101 int serial; 00102 int pe_speed; 00103 double total_walltime; 00104 double idletime; 00105 double bg_walltime; 00106 double obj_walltime; // may not needed 00107 #if CMK_LB_CPUTIMER 00108 double total_cputime; 00109 double bg_cputime; 00110 double obj_cputime; // may not needed 00111 #endif 00112 int n_objs; 00113 LDObjData *objData; 00114 int n_comm; 00115 LDCommData *commData; 00116 public: 00117 NLBStatsMsg(int osz, int csz); 00118 NLBStatsMsg(NLBStatsMsg *s); 00119 NLBStatsMsg() {} 00120 ~NLBStatsMsg(); 00121 void pup(PUP::er &p); 00122 }; 00123 00124 #endif /* NBORBASELB_H */ 00125