00001
00013 #if ! defined _HIERLB_H_
00014 #define _HIERLB_H_
00015
00016 #include "HierarchicalLBTypes.h"
00017 #include "DistBaseLB.h"
00018 #include "HierarchicalLB.decl.h"
00019
00020 #include "ckheap.h"
00021
00022 #include <vector>
00023 #include <unordered_map>
00024 #include <map>
00025 #include <list>
00026 #include <limits>
00027
00028 void CreateHierarchicalLB();
00029
00030 struct ChildLoadInfo : HierLBTypes {
00031 double cur_load = 0.0;
00032 int node_size = 0, pe = 0;
00033 bool final_child = false;
00034 cont_hier_objid_t recs;
00035
00036 ChildLoadInfo() = default;
00037 };
00038
00039 struct HierarchicalLB : HierLBTypes, CBase_HierarchicalLB {
00040 using dist_base_lb_t = DistBaseLB;
00041 using lb_stats_t = dist_base_lb_t::LDStats;
00042 using child_load_t = ChildLoadInfo;
00043
00044 HierarchicalLB(const CkLBOptions &);
00045 HierarchicalLB(CkMigrateMessage *m);
00046
00047 void avg_load_reduction(double x);
00048 void done_hier();
00049 void turnOn();
00050 void turnOff();
00051
00052 static hier_objid_t convert_to_hier_objid(int const& obj_id, int const& pe);
00053 static int hier_objid_get_pe(hier_objid_t const& id);
00054 static int hier_objid_get_id(hier_objid_t const& id);
00055
00056 void setup_tree();
00057 void calc_load_over();
00058 void lb_tree_msg(
00059 double const child_load, int const child, cont_hier_objid_t load,
00060 int child_size
00061 );
00062 child_load_t* find_min_child();
00063 void down_tree_msg(
00064 int const& from, cont_hier_objid_t excess_load, bool final_child
00065 );
00066 void transfer_objects(
00067 int const& to_pe, std::vector<int> const& lst
00068 );
00069 void finished_transfer_requests();
00070
00071 void send_down_tree();
00072 void distribute_amoung_children();
00073
00074 bool QueryBalanceNow(int step) { return true; };
00075
00076 private:
00077 int rank = 0, nproc = 0;
00078 double my_load = 0.0, avg_load = 0.0, thr_avg = 0.0, total_child_load = 0.0;
00079 bool tree_is_setup = false;
00080
00081
00082 cont_hier_objid_t obj_sample, given_objs, taken_objs, load_over;
00083 std::unordered_map<int, child_load_t*> children, live_children;
00084 std::unordered_map<int, std::vector<int>> transfers;
00085 int transfer_count = 0;
00086 int parent = -1, bottomParent = -1, child_msgs = 0, agg_node_size = 0;
00087
00088 void clear_obj_map(cont_hier_objid_t& objs);
00089
00090 lb_stats_t const* my_stats = nullptr;
00091
00092 void InitLB(const CkLBOptions &);
00093 void LoadBalance();
00094 void Strategy(const DistBaseLB::LDStats* const stats);
00095 int histogram_time_sample(double const& time_milli);
00096 };
00097
00098 #endif