00001
00007
00008
00009
00010
00011
00012
00013
00024 #ifndef REFINEONLY_DEFS_H
00025 #define REFINEONLY_DEFS_H
00026
00027 #include "elements.h"
00028 #include "heap.h"
00029 #if USE_TOPOMAP
00030 #include "TopoManager.h"
00031 #endif
00032 #include "ProxyMgr.decl.h"
00033 #include "ProxyMgr.h"
00034
00035 #define LDB_DEBUG 0 // for verbose LDB output
00036 #define PROXY_CORRECTION 0
00037 #define COMPUTE_CORRECTION 0
00038
00039 #include "ckhashtable.h"
00040
00041 class ProxyUsageKey {
00042 protected:
00043 int processor;
00044 int patch;
00045
00046 public:
00047 ProxyUsageKey (int pe, int patch) {
00048 this->processor = pe;
00049 this->patch = patch;
00050 }
00051
00052 CkHashCode hash (void) const {
00053 return (patch << 16) + processor;
00054 }
00055
00056 static CkHashCode staticHash (const void *x, size_t size) {
00057 return ((ProxyUsageKey *)x)->hash();
00058 }
00059
00060 int compare (const ProxyUsageKey &in) const {
00061 if ((in.patch == patch) && (in.processor == processor))
00062 return 1;
00063
00064 return 0;
00065 }
00066
00067 static int staticCompare (const void *a, const void *b, size_t size) {
00068 return ((ProxyUsageKey *)a)->compare(* (ProxyUsageKey *)b);
00069 }
00070 };
00071
00072 class ProxyUsage {
00073 protected:
00074 CkHashtableT <ProxyUsageKey, int> htable;
00075
00076 public:
00077
00078 ProxyUsage () : htable (1217, 0.5) {}
00079
00080
00081 void increment (int pe, int patch) {
00082 ProxyUsageKey pkey (pe, patch);
00083
00084 int val = htable.get (pkey);
00085 htable.put (pkey) = val + 1;
00086 }
00087
00088 void decrement (int pe, int patch) {
00089 ProxyUsageKey pkey (pe, patch);
00090
00091 int val = htable.get (pkey);
00092 CkAssert (val > 0);
00093 val --;
00094
00095 if (val == 0)
00096 htable.remove (pkey);
00097 else
00098 htable.put (pkey) = val;
00099 }
00100
00101 int getVal (int pe, int patch) {
00102 ProxyUsageKey pkey (pe, patch);
00103 return htable.get (pkey);
00104 }
00105 };
00106
00107
00108 class Rebalancer {
00109 public:
00110 struct pcpair {
00111 processorInfo *p;
00112 computeInfo *c;
00113 pcpair() : p(0),c(0) {;}
00114 void reset () { p = 0; c = 0; }
00115 };
00116
00117 Rebalancer(computeInfo *computeArray, patchInfo *patchArray,
00118 processorInfo *processorArray,
00119 int nComps, int nPatches, int nPes);
00120 ~Rebalancer();
00121
00122 protected:
00123 int bytesPerAtom;
00124 typedef pcpair pcgrid[3][3][2];
00125 ProxyUsage proxyUsage;
00126 const char *strategyName;
00127 computeInfo *computes;
00128 patchInfo *patches;
00129 processorInfo *processors;
00130 minHeap *pes;
00131 maxHeap *computePairHeap;
00132 maxHeap *computeSelfHeap;
00133 maxHeap *computeBgPairHeap;
00134 maxHeap *computeBgSelfHeap;
00135 int P;
00136 int numPatches;
00137 int numComputes;
00138 int numProxies;
00139 int numPesAvailable;
00140 double averageLoad;
00141 int firstAssignInRefine;
00142 #if USE_TOPOMAP
00143 TopoManager tmgr;
00144 #endif
00145
00146 int isAvailableOn(patchInfo *patch, processorInfo *p);
00147 void numAvailable(computeInfo *c, processorInfo *p,
00148 int *nPatches, int *nProxies, int *isBadForCommunication);
00149 void refine_togrid(pcgrid &grid, double thresholdLoad,
00150 processorInfo *p, computeInfo *c);
00151 void strategy();
00152 void makeHeaps();
00153 void makeTwoHeaps();
00154 void assign(computeInfo *c, processorInfo *pRec);
00155 void assign(computeInfo *c, int p);
00156 void deAssign(computeInfo *c, processorInfo *pRec);
00157 int refine();
00158 void multirefine(double overload_start=1.02);
00159 void printSummary();
00160 void printResults();
00161 void printLoads();
00162 double computeAverage();
00163 void adjustBackgroundLoadAndComputeAverage();
00164 double computeMax();
00165 double overLoad;
00166 void createSpanningTree();
00167 void decrSTLoad();
00168 void incrSTLoad();
00169 void InitProxyUsage();
00170
00176 inline void brickDim(int a, int b, int dim, int &min, int &max) {
00177 int x1, x2, x3, x4, temp, i;
00178 if(a < b)
00179 { x1 = a; x2 = b; }
00180 else
00181 { x1 = b; x2 = a; }
00182
00183 x3 = x2 - x1;
00184 x4 = dim - x3;
00185 if(x3 < x4) {
00186 min = x1; max = x2;
00187 } else {
00188 min = x2; max = x1 + dim;
00189 }
00190 }
00191
00196 inline int withinBrick(int x, int y, int z, int xm, int xM, int dimX,
00197 int ym, int yM, int dimY, int zm, int zM, int dimZ) {
00198 int wbX, wbY, wbZ;
00199 if( ((x >= xm) && (x <= xM)) || ((x < xm) && (x+dimX <= xM)) ) wbX = 1; else return 0;
00200 if( ((y >= ym) && (y <= yM)) || ((y < ym) && (y+dimY <= yM)) ) wbY = 1; else return 0;
00201 if( ((z >= zm) && (z <= zM)) || ((z < zm) && (z+dimZ <= zM)) ) wbZ = 1; else return 0;
00202
00203
00204 return 1;
00205 }
00206
00207 };
00208
00209 #endif