Rebalancer.h

Go to the documentation of this file.
00001 
00007 /*****************************************************************************
00008  * $Source: /home/cvs/namd/cvsroot/namd2/src/Rebalancer.h,v $
00009  * $Author: jim $
00010  * $Date: 2013/08/30 18:18:20 $
00011  * $Revision: 1.35 $
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) {}   //pass in a large prime close to 
00079                                           //1k processors
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 class CollectLoadsMsg;
00108 
00109 class Rebalancer {
00110 public:
00111   struct pcpair {
00112     processorInfo *p;
00113     computeInfo *c;
00114     pcpair() : p(0),c(0) {;}
00115     void reset () { p = 0; c = 0; }
00116   };
00117 
00118   Rebalancer(computeInfo *computeArray, patchInfo *patchArray,
00119              processorInfo *processorArray,
00120              int nComps, int nPatches, int nPes);
00121   ~Rebalancer();
00122 
00123 protected: 
00124   int bytesPerAtom;
00125   typedef pcpair pcgrid[3][3][2];
00126   ProxyUsage  proxyUsage;
00127   const char *strategyName;
00128   computeInfo *computes;
00129   patchInfo *patches;
00130   processorInfo *processors;
00131   minHeap *pes;
00132   maxHeap *computePairHeap;
00133   maxHeap *computeSelfHeap;
00134   maxHeap *computeBgPairHeap;
00135   maxHeap *computeBgSelfHeap;
00136   int P;
00137   int numPatches;
00138   int numComputes;
00139   int numProxies;
00140   int numPesAvailable;
00141   double averageLoad;
00142   double origMaxLoad;
00143   int firstAssignInRefine;
00144 #if USE_TOPOMAP
00145   TopoManager tmgr;
00146 #endif
00147 
00148   int isAvailableOn(patchInfo *patch, processorInfo *p);
00149   void numAvailable(computeInfo *c, processorInfo *p,
00150               int *nPatches, int *nProxies, int *isBadForCommunication);
00151   void refine_togrid(pcgrid &grid, double thresholdLoad,
00152               processorInfo *p, computeInfo *c);
00153   void strategy();
00154   void makeHeaps();
00155   void makeTwoHeaps();
00156   void assign(computeInfo *c, processorInfo *pRec);
00157   void assign(computeInfo *c, int p);
00158   void deAssign(computeInfo *c, processorInfo *pRec);
00159   int refine();
00160   void multirefine(double overload_start=1.02);
00161   void printSummary();
00162   void printResults();
00163   void printLoads(int phase=0);
00164   CollectLoadsMsg *collMsg;
00165   double computeAverage();
00166   void adjustBackgroundLoadAndComputeAverage();
00167   double computeMax();
00168   double overLoad;
00169   void createSpanningTree();
00170   void decrSTLoad();
00171   void incrSTLoad();
00172   void InitProxyUsage();
00173 
00179   inline void brickDim(int a, int b, int dim, int &min, int &max) {
00180     int x1, x2, x3, x4, temp, i;
00181     if(a < b)
00182       { x1 = a; x2 = b; } 
00183     else
00184       { x1 = b; x2 = a; }
00185 
00186     x3 = x2 - x1;
00187     x4 = dim - x3;
00188     if(x3 < x4) {
00189       min = x1; max = x2;
00190     } else {
00191       min = x2; max = x1 + dim;
00192     }
00193   }
00194 
00199   inline int withinBrick(int x, int y, int z, int xm, int xM, int dimX,
00200                          int ym, int yM, int dimY, int zm, int zM, int dimZ) {
00201     int wbX, wbY, wbZ;
00202     if( ((x >= xm) && (x <= xM)) || ((x < xm) && (x+dimX <= xM)) ) wbX = 1; else return 0;
00203     if( ((y >= ym) && (y <= yM)) || ((y < ym) && (y+dimY <= yM)) ) wbY = 1; else return 0;
00204     if( ((z >= zm) && (z <= zM)) || ((z < zm) && (z+dimZ <= zM)) ) wbZ = 1; else return 0;
00205 
00206     //if( wbX && wbY && wbZ)
00207       return 1;
00208   }
00209 
00210 };
00211 
00212 #endif

Generated on Mon Nov 20 01:17:14 2017 for NAMD by  doxygen 1.4.7