00001
00012 #ifndef _TOPO_MANAGER_H_
00013 #define _TOPO_MANAGER_H_
00014
00015 #include "topomanager_config.h"
00016
00017 #ifndef __TPM_STANDALONE__
00018 #include "converse.h"
00019 #else
00020 #include "tpm_standalone.h"
00021 #include <string.h>
00022 #endif
00023
00024 #if defined(__cplusplus)
00025 extern "C" {
00026 #endif
00027
00029 #ifndef __TPM_STANDALONE__
00030 void TopoManager_init();
00031 #else
00032 void TopoManager_init(int numpes);
00033 void TopoManager_setNumThreads(int t);
00034 #endif
00035
00036 void TopoManager_reset();
00038 void TopoManager_free();
00040 void TopoManager_printAllocation(FILE *fp);
00042 void TopoManager_getDimCount(int *ndims);
00044 void TopoManager_getDims(int *dims);
00046 void TopoManager_getCoordinates(int rank, int *coords);
00048 void TopoManager_getPeCoordinates(int rank, int *coords);
00050 void TopoManager_getRanks(int *rank_cnt, int *ranks, int *coords);
00052 void TopoManager_getPeRank(int *rank, int *coords);
00054 void TopoManager_getHopsBetweenPeRanks(int pe1, int pe2, int *hops);
00055 #ifndef __TPM_STANDALONE__
00056
00057 void TopoManager_createPartitions(int scheme, int numparts, int *nodeMap);
00058 #endif
00059
00060 #if defined(__cplusplus)
00061 }
00062
00063 #if CMK_BLUEGENEQ
00064 #include "BGQTorus.h"
00065 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00066 #include "XTTorus.h"
00067 #endif
00068
00069 #if CMK_BIGSIM_CHARM
00070 #include "blue.h"
00071 #endif
00072
00073 #include <vector>
00074
00075 class TopoManager {
00076 public:
00077 TopoManager();
00078 TopoManager(int NX, int NY, int NZ, int NT);
00079 ~TopoManager() { }
00080
00081
00082
00083
00084
00085
00086 static TopoManager *getTopoManager();
00087
00088 inline int getDimNX() const { return dimNX; }
00089 inline int getDimNY() const { return dimNY; }
00090 inline int getDimNZ() const { return dimNZ; }
00091 #if CMK_BLUEGENEQ
00092 inline int getDimNA() const { return dimNA; }
00093 inline int getDimNB() const { return dimNB; }
00094 inline int getDimNC() const { return dimNC; }
00095 inline int getDimND() const { return dimND; }
00096 inline int getDimNE() const { return dimNE; }
00097 #endif
00098 inline int getDimNT() const { return dimNT; }
00099 inline int getNumDims() const {
00100 #if CMK_BLUEGENEQ
00101 return 5;
00102 #else
00103 return 3;
00104 #endif
00105 }
00106 inline int getDimSize(unsigned int i) const {
00107 #if CMK_BLUEGENEQ
00108 CmiAssert(i < 5);
00109 switch (i) {
00110 case 0: return getDimNA();
00111 case 1: return getDimNB();
00112 case 2: return getDimNC();
00113 case 3: return getDimND();
00114 case 4: return getDimNE();
00115 default: return -1;
00116 }
00117 #else
00118 CmiAssert(i < 3);
00119 switch (i) {
00120 case 0: return getDimNX();
00121 case 1: return getDimNY();
00122 case 2: return getDimNZ();
00123 default: return -1;
00124 }
00125 #endif
00126 }
00127 inline bool haveTopologyInfo() const {
00128 #if CMK_BLUEGENEQ || XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00129 return true;
00130 #else
00131 return false;
00132 #endif
00133 }
00134
00135 inline int getProcsPerNode() const { return procsPerNode; }
00136
00137 inline bool hasMultipleProcsPerNode() const { return (procsPerNode > 1); }
00138 void rankToCoordinates(int pe, std::vector<int> &coords) const;
00139 void rankToCoordinates(int pe, int &x, int &y, int &z, int &t) const;
00140 void rankToCoordinates(int pe, int &a, int &b, int &c, int &d, int &e, int &t) const;
00144 int coordinatesToRank(int x, int y, int z, int t) const;
00148 int coordinatesToRank(int a, int b, int c, int d, int e, int t) const;
00149 int getHopsBetweenRanks(int pe1, int pe2) const;
00150 int getHopsBetweenRanks(int *pe1, int pe2) const;
00151 void sortRanksByHops(int pe, int *pes, int *idx, int n) const;
00152 void sortRanksByHops(int *pe, int *pes, int *idx, int n) const;
00153 int pickClosestRank(int mype, int *pes, int n) const;
00154 int areNeighbors(int pe1, int pe2, int pe3, int distance) const;
00155 void printAllocation(FILE *fp) const;
00156
00159 inline int getDimX() const { return dimX; }
00160 inline int getDimY() const { return dimY; }
00161 inline int getDimZ() const { return dimZ; }
00162 void rankToCoordinates(int pe, int &x, int &y, int &z) const;
00163 int coordinatesToRank(int x, int y, int z) const;
00164
00165 inline int absX(int x) const {
00166 int px = abs(x);
00167 int sx = dimNX - px;
00168 CmiAssert(sx>=0);
00169 if(torusX)
00170 return ((px>sx) ? sx : px);
00171 else
00172 return px;
00173 }
00174
00175 inline int absY(int y) const {
00176 int py = abs(y);
00177 int sy = dimNY - py;
00178 CmiAssert(sy>=0);
00179 if(torusY)
00180 return ((py>sy) ? sy : py);
00181 else
00182 return py;
00183 }
00184
00185 inline int absZ(int z) const {
00186 int pz = abs(z);
00187 int sz = dimNZ - pz;
00188 CmiAssert(sz>=0);
00189 if(torusZ)
00190 return ((pz>sz) ? sz : pz);
00191 else
00192 return pz;
00193 }
00194 #if CMK_BLUEGENEQ
00195 inline int absA(int a) const {
00196 int pa = abs(a);
00197 int sa = dimNA - pa;
00198 CmiAssert(sa>=0);
00199 if(torusA)
00200 return ((pa>sa) ? sa : pa);
00201 else
00202 return pa;
00203 }
00204
00205 inline int absB(int b) const {
00206 int pb = abs(b);
00207 int sb = dimNB - pb;
00208 CmiAssert(sb>=0);
00209 if(torusB)
00210 return ((pb>sb) ? sb : pb);
00211 else
00212 return pb;
00213 }
00214
00215 inline int absC(int c) const {
00216 int pc = abs(c);
00217 int sc = dimNC - pc;
00218 CmiAssert(sc>=0);
00219 if(torusC)
00220 return ((pc>sc) ? sc : pc);
00221 else
00222 return pc;
00223 }
00224
00225 inline int absD(int d) const {
00226 int pd = abs(d);
00227 int sd = dimND - pd;
00228 CmiAssert(sd>=0);
00229 if(torusD)
00230 return ((pd>sd) ? sd : pd);
00231 else
00232 return pd;
00233 }
00234
00235 inline int absE(int e) const {
00236 int pe = abs(e);
00237 int se = dimNE - pe;
00238 CmiAssert(se>=0);
00239 return ((pe>se) ? se : pe);
00240 }
00241 #endif
00242 private:
00243 int dimX;
00244 int dimY;
00245 int dimZ;
00246 int dimNX;
00247 int dimNY;
00248 int dimNZ;
00249 int dimNT;
00250 int numPes;
00251 int torusX, torusY, torusZ, torusT;
00252 #if CMK_BLUEGENEQ
00253 int dimNA, dimNB, dimNC, dimND, dimNE;
00254 int torusA, torusB, torusC, torusD, torusE;
00255 #endif
00256 int procsPerNode;
00257 #if CMK_BLUEGENEQ
00258 BGQTorusManager bgqtm;
00259 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00260 XTTorusManager xttm;
00261 #endif
00262 };
00263 #endif
00264 #endif //_TOPO_MANAGER_H_