00001
00012 #ifndef _TOPO_MANAGER_H_
00013 #define _TOPO_MANAGER_H_
00014
00015 #include "converse.h"
00016
00017 #if CMK_BLUEGENEL
00018 #include "BGLTorus.h"
00019 #elif CMK_BLUEGENEP
00020 #include "BGPTorus.h"
00021 #elif CMK_BLUEGENEQ
00022 #include "BGQTorus.h"
00023 #elif XT3_TOPOLOGY
00024 #include "XT3Torus.h"
00025 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00026 #include "XTTorus.h"
00027 #endif
00028
00029 #if CMK_BIGSIM_CHARM
00030 #include "blue.h"
00031 #endif
00032
00033 class TopoManager {
00034 public:
00035 TopoManager();
00036 TopoManager(int NX, int NY, int NZ, int NT);
00037 ~TopoManager() { }
00038
00039 inline int getDimNX() const { return dimNX; }
00040 inline int getDimNY() const { return dimNY; }
00041 inline int getDimNZ() const { return dimNZ; }
00042 #if CMK_BLUEGENEQ
00043 inline int getDimNA() const { return dimNA; }
00044 inline int getDimNB() const { return dimNB; }
00045 inline int getDimNC() const { return dimNC; }
00046 inline int getDimND() const { return dimND; }
00047 inline int getDimNE() const { return dimNE; }
00048 #endif
00049 inline int getDimNT() const { return dimNT; }
00050
00051 inline int getProcsPerNode() const { return procsPerNode; }
00052
00053 int hasMultipleProcsPerNode() const;
00054 void rankToCoordinates(int pe, int &x, int &y, int &z, int &t);
00055 void rankToCoordinates(int pe, int &a, int &b, int &c, int &d, int &e, int &t);
00056 int coordinatesToRank(int x, int y, int z, int t);
00057 int coordinatesToRank(int a, int b, int c, int d, int e, int t);
00058 int getHopsBetweenRanks(int pe1, int pe2);
00059 void sortRanksByHops(int pe, int *pes, int *idx, int n);
00060 int pickClosestRank(int mype, int *pes, int n);
00061 int areNeighbors(int pe1, int pe2, int pe3, int distance);
00062 void printAllocation(FILE *fp);
00063
00066 inline int getDimX() { return dimX; }
00067 inline int getDimY() { return dimY; }
00068 inline int getDimZ() { return dimZ; }
00069 void rankToCoordinates(int pe, int &x, int &y, int &z);
00070 int coordinatesToRank(int x, int y, int z);
00071
00072 inline int absX(int x) {
00073 int px = abs(x);
00074 int sx = dimNX - px;
00075 CmiAssert(sx>=0);
00076 if(torusX)
00077 return ((px>sx) ? sx : px);
00078 else
00079 return px;
00080 }
00081
00082 inline int absY(int y) {
00083 int py = abs(y);
00084 int sy = dimNY - py;
00085 CmiAssert(sy>=0);
00086 if(torusY)
00087 return ((py>sy) ? sy : py);
00088 else
00089 return py;
00090 }
00091
00092 inline int absZ(int z) {
00093 int pz = abs(z);
00094 int sz = dimNZ - pz;
00095 CmiAssert(sz>=0);
00096 if(torusZ)
00097 return ((pz>sz) ? sz : pz);
00098 else
00099 return pz;
00100 }
00101 #if CMK_BLUEGENEQ
00102 inline int absA(int a) {
00103 int pa = abs(a);
00104 int sa = dimNA - pa;
00105 CmiAssert(sa>=0);
00106 if(torusA)
00107 return ((pa>sa) ? sa : pa);
00108 else
00109 return pa;
00110 }
00111
00112 inline int absB(int b) {
00113 int pb = abs(b);
00114 int sb = dimNB - pb;
00115 CmiAssert(sb>=0);
00116 if(torusB)
00117 return ((pb>sb) ? sb : pb);
00118 else
00119 return pb;
00120 }
00121
00122 inline int absC(int c) {
00123 int pc = abs(c);
00124 int sc = dimNC - pc;
00125 CmiAssert(sc>=0);
00126 if(torusC)
00127 return ((pc>sc) ? sc : pc);
00128 else
00129 return pc;
00130 }
00131
00132 inline int absD(int d) {
00133 int pd = abs(d);
00134 int sd = dimND - pd;
00135 CmiAssert(sd>=0);
00136 if(torusD)
00137 return ((pd>sd) ? sd : pd);
00138 else
00139 return pd;
00140 }
00141
00142 inline int absE(int e) {
00143 int pe = abs(e);
00144 int se = dimNE - pe;
00145 CmiAssert(se>=0);
00146 return ((pe>se) ? se : pe);
00147 }
00148 #endif
00149 private:
00150 int dimX;
00151 int dimY;
00152 int dimZ;
00153 int dimNX;
00154 int dimNY;
00155 int dimNZ;
00156 int dimNT;
00157 int numPes;
00158 int torusX, torusY, torusZ, torusT;
00159 #if CMK_BLUEGENEQ
00160 int dimNA, dimNB, dimNC, dimND, dimNE;
00161 int torusA, torusB, torusC, torusD, torusE;
00162 #endif
00163 int procsPerNode;
00164 #if CMK_BLUEGENEL
00165 BGLTorusManager bgltm;
00166 #elif CMK_BLUEGENEP
00167 BGPTorusManager bgptm;
00168 #elif CMK_BLUEGENEQ
00169 BGQTorusManager bgqtm;
00170 #elif XT3_TOPOLOGY
00171 XT3TorusManager xt3tm;
00172 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00173 XTTorusManager xttm;
00174 #endif
00175
00176 void quicksort(int pe, int *pes, int *arr, int left, int right);
00177 int partition(int pe, int *pes, int *idx, int left, int right);
00178 };
00179
00180 #endif //_TOPO_MANAGER_H_