NAMD
Rebalancer.h
Go to the documentation of this file.
1 
7 /*****************************************************************************
8  * $Source: /home/cvs/namd/cvsroot/namd2/src/Rebalancer.h,v $
9  * $Author: jim $
10  * $Date: 2013/08/30 18:18:20 $
11  * $Revision: 1.35 $
12  *****************************************************************************/
13 
24 #ifndef REFINEONLY_DEFS_H
25 #define REFINEONLY_DEFS_H
26 
27 #include "elements.h"
28 #include "heap.h"
29 #if USE_TOPOMAP
30 #include "TopoManager.h"
31 #endif
32 #include "ProxyMgr.decl.h"
33 #include "ProxyMgr.h"
34 
35 #define LDB_DEBUG 0 // for verbose LDB output
36 #define PROXY_CORRECTION 0
37 #define COMPUTE_CORRECTION 0
38 
39 #include "ckhashtable.h"
40 
42  protected:
43  int processor;
44  int patch;
45 
46  public:
47  ProxyUsageKey (int pe, int patch) {
48  this->processor = pe;
49  this->patch = patch;
50  }
51 
52  CkHashCode hash (void) const {
53  return (patch << 16) + processor;
54  }
55 
56  static CkHashCode staticHash (const void *x, size_t size) {
57  return ((ProxyUsageKey *)x)->hash();
58  }
59 
60  int compare (const ProxyUsageKey &in) const {
61  if ((in.patch == patch) && (in.processor == processor))
62  return 1;
63 
64  return 0;
65  }
66 
67  static int staticCompare (const void *a, const void *b, size_t size) {
68  return ((ProxyUsageKey *)a)->compare(* (ProxyUsageKey *)b);
69  }
70 };
71 
72 class ProxyUsage {
73  protected:
74  CkHashtableT <ProxyUsageKey, int> htable;
75 
76  public:
77 
78  ProxyUsage () : htable (1217, 0.5) {} //pass in a large prime close to
79  //1k processors
80 
81  void increment (int pe, int patch) {
82  ProxyUsageKey pkey (pe, patch);
83 
84  int val = htable.get (pkey);
85  htable.put (pkey) = val + 1;
86  }
87 
88  void decrement (int pe, int patch) {
89  ProxyUsageKey pkey (pe, patch);
90 
91  int val = htable.get (pkey);
92  CkAssert (val > 0);
93  val --;
94 
95  if (val == 0)
96  htable.remove (pkey);
97  else
98  htable.put (pkey) = val;
99  }
100 
101  int getVal (int pe, int patch) {
102  ProxyUsageKey pkey (pe, patch);
103  return htable.get (pkey);
104  }
105 };
106 
107 class CollectLoadsMsg;
108 
109 class Rebalancer {
110 public:
111  struct pcpair {
114  pcpair() : p(0),c(0) {;}
115  void reset () { p = 0; c = 0; }
116  };
117 
118  Rebalancer(computeInfo *computeArray, patchInfo *patchArray,
119  processorInfo *processorArray,
120  int nComps, int nPatches, int nPes);
121  ~Rebalancer();
122 
123 protected:
125  typedef pcpair pcgrid[3][3][2];
127  const char *strategyName;
136  int P;
141  double averageLoad;
142  double origMaxLoad;
144 #if USE_TOPOMAP
145  TopoManager tmgr;
146 #endif
147 
148  int isAvailableOn(patchInfo *patch, processorInfo *p);
150  int *nPatches, int *nProxies, int *isBadForCommunication);
151  void refine_togrid(pcgrid &grid, double thresholdLoad,
152  processorInfo *p, computeInfo *c);
153  void strategy();
154  void makeHeaps();
155  void makeTwoHeaps();
156  void assign(computeInfo *c, processorInfo *pRec);
157  void assign(computeInfo *c, int p);
158  void deAssign(computeInfo *c, processorInfo *pRec);
159  int refine();
160  void multirefine(double overload_start=1.02);
161  void printSummary();
162  void printResults();
163  void printLoads(int phase=0);
165  double computeAverage();
167  double computeMax();
168  double overLoad;
169  void createSpanningTree();
170  void decrSTLoad();
171  void incrSTLoad();
172  void InitProxyUsage();
173 
179  inline void brickDim(int a, int b, int dim, int &min, int &max) {
180  int x1, x2, x3, x4, temp, i;
181  if(a < b)
182  { x1 = a; x2 = b; }
183  else
184  { x1 = b; x2 = a; }
185 
186  x3 = x2 - x1;
187  x4 = dim - x3;
188  if(x3 < x4) {
189  min = x1; max = x2;
190  } else {
191  min = x2; max = x1 + dim;
192  }
193  }
194 
199  inline int withinBrick(int x, int y, int z, int xm, int xM, int dimX,
200  int ym, int yM, int dimY, int zm, int zM, int dimZ) {
201  int wbX, wbY, wbZ;
202  if( ((x >= xm) && (x <= xM)) || ((x < xm) && (x+dimX <= xM)) ) wbX = 1; else return 0;
203  if( ((y >= ym) && (y <= yM)) || ((y < ym) && (y+dimY <= yM)) ) wbY = 1; else return 0;
204  if( ((z >= zm) && (z <= zM)) || ((z < zm) && (z+dimZ <= zM)) ) wbZ = 1; else return 0;
205 
206  //if( wbX && wbY && wbZ)
207  return 1;
208  }
209 
210 };
211 
212 #endif
Definition: heap.h:20
int numComputes
Definition: Rebalancer.h:138
static CkHashCode staticHash(const void *x, size_t size)
Definition: Rebalancer.h:56
computeInfo * computes
Definition: Rebalancer.h:128
computeInfo * c
Definition: Rebalancer.h:113
int numPatches
Definition: Rebalancer.h:137
CkHashtableT< ProxyUsageKey, int > htable
Definition: Rebalancer.h:74
CollectLoadsMsg * collMsg
Definition: Rebalancer.h:164
void createSpanningTree()
Definition: Rebalancer.C:1154
void assign(computeInfo *c, processorInfo *pRec)
Definition: Rebalancer.C:402
minHeap * pes
Definition: Rebalancer.h:131
double averageLoad
Definition: Rebalancer.h:141
ProxyUsageKey(int pe, int patch)
Definition: Rebalancer.h:47
int numProxies
Definition: Rebalancer.h:139
void incrSTLoad()
Definition: Rebalancer.C:1210
void makeTwoHeaps()
Definition: Rebalancer.C:356
void refine_togrid(pcgrid &grid, double thresholdLoad, processorInfo *p, computeInfo *c)
Definition: Rebalancer.C:544
processorInfo * processors
Definition: Rebalancer.h:130
int firstAssignInRefine
Definition: Rebalancer.h:143
void printLoads(int phase=0)
Definition: Rebalancer.C:874
void numAvailable(computeInfo *c, processorInfo *p, int *nPatches, int *nProxies, int *isBadForCommunication)
Definition: Rebalancer.C:1074
void deAssign(computeInfo *c, processorInfo *pRec)
Definition: Rebalancer.C:466
ProxyUsage proxyUsage
Definition: Rebalancer.h:126
void multirefine(double overload_start=1.02)
Definition: Rebalancer.C:784
Definition: heap.h:43
maxHeap * computeBgSelfHeap
Definition: Rebalancer.h:135
maxHeap * computeSelfHeap
Definition: Rebalancer.h:133
void printSummary()
Definition: Rebalancer.C:975
gridSize z
maxHeap * computePairHeap
Definition: Rebalancer.h:132
int withinBrick(int x, int y, int z, int xm, int xM, int dimX, int ym, int yM, int dimY, int zm, int zM, int dimZ)
Definition: Rebalancer.h:199
void increment(int pe, int patch)
Definition: Rebalancer.h:81
void strategy()
Definition: Rebalancer.C:247
static int staticCompare(const void *a, const void *b, size_t size)
Definition: Rebalancer.h:67
double computeAverage()
Definition: Rebalancer.C:1001
void brickDim(int a, int b, int dim, int &min, int &max)
Definition: Rebalancer.h:179
void adjustBackgroundLoadAndComputeAverage()
Definition: Rebalancer.C:1023
void InitProxyUsage()
Definition: Rebalancer.C:195
double overLoad
Definition: Rebalancer.h:168
int numPesAvailable
Definition: Rebalancer.h:140
void decrement(int pe, int patch)
Definition: Rebalancer.h:88
int compare(const ProxyUsageKey &in) const
Definition: Rebalancer.h:60
maxHeap * computeBgPairHeap
Definition: Rebalancer.h:134
void makeHeaps()
Definition: Rebalancer.C:252
processorInfo * p
Definition: Rebalancer.h:112
pcpair pcgrid[3][3][2]
Definition: Rebalancer.h:125
void printResults()
Definition: Rebalancer.C:868
patchInfo * patches
Definition: Rebalancer.h:129
int bytesPerAtom
Definition: Rebalancer.h:124
double origMaxLoad
Definition: Rebalancer.h:142
int isAvailableOn(patchInfo *patch, processorInfo *p)
Definition: Rebalancer.C:1069
double computeMax()
Definition: Rebalancer.C:1057
gridSize y
int getVal(int pe, int patch)
Definition: Rebalancer.h:101
int refine()
Definition: Rebalancer.C:577
gridSize x
Rebalancer(computeInfo *computeArray, patchInfo *patchArray, processorInfo *processorArray, int nComps, int nPatches, int nPes)
Definition: Rebalancer.C:27
const char * strategyName
Definition: Rebalancer.h:127
CkHashCode hash(void) const
Definition: Rebalancer.h:52
void decrSTLoad()
Definition: Rebalancer.C:1195