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 double origMaxLoad;
00142 int firstAssignInRefine;
00143 #if USE_TOPOMAP
00144 TopoManager tmgr;
00145 #endif
00146
00147 int isAvailableOn(patchInfo *patch, processorInfo *p);
00148 void numAvailable(computeInfo *c, processorInfo *p,
00149 int *nPatches, int *nProxies, int *isBadForCommunication);
00150 void refine_togrid(pcgrid &grid, double thresholdLoad,
00151 processorInfo *p, computeInfo *c);
00152 void strategy();
00153 void makeHeaps();
00154 void makeTwoHeaps();
00155 void assign(computeInfo *c, processorInfo *pRec);
00156 void assign(computeInfo *c, int p);
00157 void deAssign(computeInfo *c, processorInfo *pRec);
00158 int refine();
00159 void multirefine(double overload_start=1.02);
00160 void printSummary();
00161 void printResults();
00162 void printLoads();
00163 double computeAverage();
00164 void adjustBackgroundLoadAndComputeAverage();
00165 double computeMax();
00166 double overLoad;
00167 void createSpanningTree();
00168 void decrSTLoad();
00169 void incrSTLoad();
00170 void InitProxyUsage();
00171
00177 inline void brickDim(int a, int b, int dim, int &min, int &max) {
00178 int x1, x2, x3, x4, temp, i;
00179 if(a < b)
00180 { x1 = a; x2 = b; }
00181 else
00182 { x1 = b; x2 = a; }
00183
00184 x3 = x2 - x1;
00185 x4 = dim - x3;
00186 if(x3 < x4) {
00187 min = x1; max = x2;
00188 } else {
00189 min = x2; max = x1 + dim;
00190 }
00191 }
00192
00197 inline int withinBrick(int x, int y, int z, int xm, int xM, int dimX,
00198 int ym, int yM, int dimY, int zm, int zM, int dimZ) {
00199 int wbX, wbY, wbZ;
00200 if( ((x >= xm) && (x <= xM)) || ((x < xm) && (x+dimX <= xM)) ) wbX = 1; else return 0;
00201 if( ((y >= ym) && (y <= yM)) || ((y < ym) && (y+dimY <= yM)) ) wbY = 1; else return 0;
00202 if( ((z >= zm) && (z <= zM)) || ((z < zm) && (z+dimZ <= zM)) ) wbZ = 1; else return 0;
00203
00204
00205 return 1;
00206 }
00207
00208 };
00209
00210 #endif