A small change in the assignment algorithm
[charm.git] / src / ck-ldb / TopoCentLB.h
1 #ifndef _TOPOCENTLB_H_
2 #define _TOPOCENTLB_H_
3
4 #include "CentralLB.h"
5 #include "topology.h"
6
7 void CreateTopoCentLB ();
8
9 class TopoCentLB : public CentralLB
10 {
11   public:
12     TopoCentLB (const CkLBOptions &opt);
13     TopoCentLB (CkMigrateMessage *m) : CentralLB (m) { };
14
15     void work (CentralLB::LDStats *stats, int count);
16
17     void pup (PUP::er &p) { CentralLB::pup(p); }
18
19                 typedef struct{
20                         double key;
21                         int node;
22                 } HeapNode;
23
24                 class PartGraph {
25                 public:
26                         typedef struct{
27                                 int degree;
28                                 int *obj_list;
29                                 int num_objs;
30                                 double comm;    //Amount of communication done by this partition -- num of bytes
31                         } Node;
32                         
33                         typedef double Edge;
34
35                         PartGraph(int num_parts,int init_num_objs){
36                                 
37                                 n_nodes = num_parts;
38                                 nodes = new Node[num_parts];
39                                 for(int i=0;i<num_parts;i++)
40                                 {
41                                         nodes[i].obj_list = new int[init_num_objs];
42                                         nodes[i].num_objs=0;
43                                         nodes[i].degree=0;
44                                         nodes[i].comm=0;
45                                 }
46                                 
47                                 n_edges = num_parts*num_parts;
48                                 edges = new Edge*[num_parts];
49                                 for(int i=0;i<num_parts;i++)
50                                 {
51                                         edges[i] = new Edge[num_parts];
52                                         for(int j=0;j<num_parts;j++)
53                                                 edges[i][j] = 0;
54                                 }
55                         }
56
57                         PartGraph(PartGraph *pg,int init_num_objs){
58
59                                 n_nodes = pg->n_nodes;
60                                 n_edges = pg->n_edges;
61                                 nodes = new Node[n_nodes];
62                                 for(int i=0;i<n_nodes;i++){
63                                         nodes[i].obj_list=new int[init_num_objs];
64                                         nodes[i].num_objs = pg->nodes[i].num_objs;
65                                         nodes[i].degree = pg->nodes[i].degree;
66                                         nodes[i].comm = pg->nodes[i].comm;
67                                         for(int j=0;j<pg->nodes[i].num_objs;j++)
68                                                 nodes[i].obj_list[j] = pg->nodes[i].obj_list[j];
69                                 }
70                                 
71                                 edges = new Edge*[n_nodes];
72                                 for(int i=0;i<n_nodes;i++){
73                                         edges[i] = new Edge[n_nodes];
74                                         for(int j=0;j<n_nodes;j++)
75                                                 edges[i][j] = pg->edges[i][j];
76                                 }
77                         }
78
79                         ~PartGraph(){
80                                 for(int i=0;i<n_nodes;i++)
81                                         delete[] nodes[i].obj_list;
82                                 delete[] nodes;
83                                 delete[] edges;
84                         }
85                 //private:
86                         Node *nodes;
87                         Edge **edges;
88                         int n_nodes;
89                         int n_edges;
90                 };
91                 
92                 PartGraph *partgraph;
93                 LBTopology                      *topo;
94                 double **hopCount;
95
96                 //int **topoGraph;
97                 //int *topoDegree;
98                 
99                 void calculateMST(PartGraph *partgraph,LBTopology *topo,int *proc_mapping,int max_comm_part);
100                 void increaseKey(HeapNode *heap,int i,double wt);
101                 HeapNode extractMax(HeapNode *heap,int *heapSize);
102                 void BuildHeap(HeapNode *heap,int heapSize);
103                 void Heapify(HeapNode *heap, int node, int heapSize);
104                 int findMaxObjs(int *map,int totalobjs,int count);
105                 void computePartitions(CentralLB::LDStats *stats,int count,int *newmap);
106                 //static int compare(const void *p,const void *q);
107   private:
108     
109                 CmiBool QueryBalanceNow (int step);
110 };
111
112 #endif /* _TOPOCENTLB_H_ */