00001 #ifndef _TOPOCENTLB_H_
00002 #define _TOPOCENTLB_H_
00003
00004 #include "CentralLB.h"
00005 #include "topology.h"
00006
00007
00008 extern "C" void METIS_PartGraphRecursive (int*, int*, int*, int*, int*, int*,
00009 int*, int*, int*, int*, int*);
00010
00011 extern "C" void METIS_PartGraphKway (int*, int*, int*, int*, int*, int*,
00012 int*, int*, int*, int*, int*);
00013
00014 extern "C" void METIS_PartGraphVKway (int*, int*, int*, int*, int*, int*,
00015 int*, int*, int*, int*, int*);
00016
00017 extern "C" void METIS_WPartGraphRecursive (int*, int*, int*, int*,
00018 int*, int*, int*, int*,
00019 float*, int*, int*, int*);
00020
00021 extern "C" void METIS_WPartGraphKway (int*, int*, int*, int*,
00022 int*, int*, int*, int*,
00023 float*, int*, int*, int*);
00024
00025 extern "C" void METIS_mCPartGraphRecursive (int*, int*, int*, int*,
00026 int*, int*, int*, int*,
00027 int*, int*, int*, int*);
00028
00029 extern "C" void METIS_mCPartGraphKway (int*, int*, int*, int*, int*,
00030 int*, int*, int*, int*, int*,
00031 int*, int*, int*);
00032
00033
00034
00035 void CreateTopoCentLB ();
00036
00037 class TopoCentLB : public CBase_TopoCentLB
00038 {
00039 public:
00040 TopoCentLB (const CkLBOptions &opt);
00041 TopoCentLB (CkMigrateMessage *m) : CBase_TopoCentLB (m) { };
00042 ~TopoCentLB();
00043
00044 void work (LDStats *stats);
00045
00046 void pup (PUP::er &p) { }
00047
00048 struct HeapNode {
00049 double key;
00050 int node;
00051 };
00052
00053 class PartGraph {
00054 public:
00055 typedef struct{
00056 int degree;
00057 int *obj_list;
00058 int num_objs;
00059 double comm;
00060 } Node;
00061
00062 typedef double Edge;
00063
00064 PartGraph(int num_parts,int init_num_objs){
00065 int i;
00066 n_nodes = num_parts;
00067 nodes = new Node[num_parts];
00068 for(i=0;i<num_parts;i++)
00069 {
00070 nodes[i].obj_list = new int[init_num_objs];
00071 nodes[i].num_objs=0;
00072 nodes[i].degree=0;
00073 nodes[i].comm=0;
00074 }
00075
00076 n_edges = num_parts*num_parts;
00077 edges = new Edge*[num_parts];
00078 for(i=0;i<num_parts;i++)
00079 {
00080 edges[i] = new Edge[num_parts];
00081 for(int j=0;j<num_parts;j++)
00082 edges[i][j] = 0;
00083 }
00084 }
00085
00086 PartGraph(PartGraph *pg,int init_num_objs){
00087 int i;
00088 n_nodes = pg->n_nodes;
00089 n_edges = pg->n_edges;
00090 nodes = new Node[n_nodes];
00091 for(i=0;i<n_nodes;i++){
00092 nodes[i].obj_list=new int[init_num_objs];
00093 nodes[i].num_objs = pg->nodes[i].num_objs;
00094 nodes[i].degree = pg->nodes[i].degree;
00095 nodes[i].comm = pg->nodes[i].comm;
00096 for(int j=0;j<pg->nodes[i].num_objs;j++)
00097 nodes[i].obj_list[j] = pg->nodes[i].obj_list[j];
00098 }
00099
00100 edges = new Edge*[n_nodes];
00101 for(i=0;i<n_nodes;i++){
00102 edges[i] = new Edge[n_nodes];
00103 for(int j=0;j<n_nodes;j++)
00104 edges[i][j] = pg->edges[i][j];
00105 }
00106 }
00107
00108 ~PartGraph(){
00109 for(int i=0;i<n_nodes;i++)
00110 delete[] nodes[i].obj_list;
00111 delete[] nodes;
00112
00113 for(int i=0;i<n_nodes;i++)
00114 delete[] edges[i];
00115 delete[] edges;
00116 }
00117
00118 Node *nodes;
00119 Edge **edges;
00120 int n_nodes;
00121 int n_edges;
00122 };
00123
00124 PartGraph *partgraph;
00125 LBTopology *topo;
00126 double **hopCount;
00127 int *heapMapping;
00128
00129
00130
00131 void calculateMST(PartGraph *partgraph,LBTopology *topo,int *proc_mapping,int max_comm_part);
00132 void increaseKey(HeapNode *heap,int i,double wt);
00133 HeapNode extractMax(HeapNode *heap,int *heapSize);
00134 void BuildHeap(HeapNode *heap,int heapSize);
00135 void Heapify(HeapNode *heap, int node, int heapSize);
00136 int findMaxObjs(int *map,int totalobjs,int count);
00137 void computePartitions(CentralLB::LDStats *stats,int count,int *newmap);
00138
00139 private:
00140
00141 bool QueryBalanceNow (int step);
00142 };
00143
00144 #endif