00001
00011 #include "TopoManager.h"
00012 #ifndef __TPM_STANDALONE__
00013 #include "partitioning_strategies.h"
00014 #endif
00015 #include <algorithm>
00016
00017 struct CompareRankDist {
00018 std::vector<int> peDist;
00019
00020 CompareRankDist(int *root, int *pes, int n, const TopoManager *tmgr) : peDist(n) {
00021 for(int p = 0; p < n; p++) {
00022 peDist[p] = tmgr->getHopsBetweenRanks(root, pes[p]);
00023 }
00024 }
00025
00026 bool operator() (int i, int j) {
00027 return (peDist[i] < peDist[j]);
00028 }
00029 };
00030
00031
00032 TopoManager::TopoManager() {
00033 #if CMK_BLUEGENEQ
00034 dimX = bgqtm.getDimX();
00035 dimY = bgqtm.getDimY();
00036 dimZ = bgqtm.getDimZ();
00037
00038 dimNX = bgqtm.getDimNX();
00039 dimNY = bgqtm.getDimNY();
00040 dimNZ = bgqtm.getDimNZ();
00041 dimNT = bgqtm.getDimNT();
00042
00043 dimNA = bgqtm.getDimNA();
00044 dimNB = bgqtm.getDimNB();
00045 dimNC = bgqtm.getDimNC();
00046 dimND = bgqtm.getDimND();
00047 dimNE = bgqtm.getDimNE();
00048
00049 procsPerNode = bgqtm.getProcsPerNode();
00050 int *torus;
00051 torus = bgqtm.isTorus();
00052 torusA = torus[0];
00053 torusB = torus[1];
00054 torusC = torus[2];
00055 torusD = torus[3];
00056 torusE = torus[4];
00057
00058 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00059 dimX = xttm.getDimX();
00060 dimY = xttm.getDimY();
00061 dimZ = xttm.getDimZ();
00062
00063 dimNX = xttm.getDimNX();
00064 dimNY = xttm.getDimNY();
00065 dimNZ = xttm.getDimNZ();
00066 dimNT = xttm.getDimNT();
00067
00068 procsPerNode = xttm.getProcsPerNode();
00069 int *torus;
00070 torus = xttm.isTorus();
00071 torusX = torus[0];
00072 torusY = torus[1];
00073 torusZ = torus[2];
00074 torusT = torus[3];
00075
00076 #else
00077 dimX = CmiNumPes();
00078 dimY = 1;
00079 dimZ = 1;
00080
00081 dimNX = CmiNumPhysicalNodes();
00082 dimNY = 1;
00083 dimNZ = 1;
00084
00085 dimNT = 0;
00086 for (int i=0; i < dimNX; i++) {
00087 int n = CmiNumPesOnPhysicalNode(i);
00088 if (n > dimNT) dimNT = n;
00089 }
00090 procsPerNode = dimNT;
00091 torusX = true;
00092 torusY = true;
00093 torusZ = true;
00094 torusT = false;
00095 #endif
00096
00097 #if CMK_BIGSIM_CHARM
00098 BgGetSize(&dimNX, &dimNY, &dimNZ);
00099
00100 dimNT = procsPerNode = BgGetNumWorkThread();
00101 dimX = dimNX * procsPerNode;
00102 dimY = dimNY;
00103 dimZ = dimNZ;
00104
00105 torusX = true;
00106 torusY = true;
00107 torusZ = true;
00108 torusT = false;
00109 #endif
00110
00111 numPes = CmiNumPes();
00112 }
00113
00114 TopoManager::TopoManager(int NX, int NY, int NZ, int NT) : dimNX(NX), dimNY(NY), dimNZ(NZ), dimNT(NT) {
00115
00116 procsPerNode = dimNT;
00117 dimX = dimNX * dimNT;
00118 dimY = dimNY;
00119 dimZ = dimNZ;
00120 torusX = true;
00121 torusY = true;
00122 torusZ = true;
00123 #if CMK_BLUEGENEQ
00124 torusA = true;
00125 torusB = true;
00126 torusC = true;
00127 torusD = true;
00128 torusE = true;
00129 #endif
00130 numPes = dimNX * dimNY * dimNZ * dimNT;
00131 }
00132
00133 void TopoManager::rankToCoordinates(int pe, std::vector<int> &coords) const {
00134 coords.resize(getNumDims()+1);
00135 #if CMK_BLUEGENEQ
00136 rankToCoordinates(pe,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5]);
00137 #else
00138 rankToCoordinates(pe,coords[0],coords[1],coords[2],coords[3]);
00139 #endif
00140 }
00141
00142 void TopoManager::rankToCoordinates(int pe, int &x, int &y, int &z) const {
00143 CmiAssert( pe >= 0 && pe < numPes );
00144 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00145 int t;
00146 xttm.rankToCoordinates(pe, x, y, z, t);
00147 #else
00148 if(dimY > 1){
00149
00150 x = pe % dimX;
00151 y = (pe % (dimX * dimY)) / dimX;
00152 z = pe / (dimX * dimY);
00153 }
00154 else {
00155 x = CmiPhysicalNodeID(pe);
00156 y = 0;
00157 z = 0;
00158 }
00159 #endif
00160
00161 #if CMK_BIGSIM_CHARM
00162 if(dimY > 1){
00163
00164 x = pe % dimX;
00165 y = (pe % (dimX * dimY)) / dimX;
00166 z = pe / (dimX * dimY);
00167 }
00168 else {
00169 x = pe;
00170 y = 0;
00171 z = 0;
00172 }
00173 #endif
00174 }
00175
00176 void TopoManager::rankToCoordinates(int pe, int &x, int &y, int &z, int &t) const {
00177 CmiAssert( pe >= 0 && pe < numPes );
00178 #if CMK_BLUEGENEQ
00179 bgqtm.rankToCoordinates(pe, x, y, z, t);
00180 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00181 xttm.rankToCoordinates(pe, x, y, z, t);
00182 #else
00183 if(dimNY > 1) {
00184 t = pe % dimNT;
00185 x = (pe % (dimNT*dimNX)) / dimNT;
00186 y = (pe % (dimNT*dimNX*dimNY)) / (dimNT*dimNX);
00187 z = pe / (dimNT*dimNX*dimNY);
00188 } else {
00189 t = CmiPhysicalRank(pe);
00190 x = CmiPhysicalNodeID(pe);
00191 y = 0;
00192 z = 0;
00193 }
00194 #endif
00195
00196 #if CMK_BIGSIM_CHARM
00197 if(dimNY > 1) {
00198 t = pe % dimNT;
00199 x = (pe % (dimNT*dimNX)) / dimNT;
00200 y = (pe % (dimNT*dimNX*dimNY)) / (dimNT*dimNX);
00201 z = pe / (dimNT*dimNX*dimNY);
00202 } else {
00203 t = pe % dimNT;
00204 x = (pe % (dimNT*dimNX)) / dimNT;
00205 y = 0;
00206 z = 0;
00207 }
00208 #endif
00209 }
00210
00211 #if CMK_BLUEGENEQ
00212 void TopoManager::rankToCoordinates(int pe, int &a, int &b, int &c, int &d, int &e, int &t) const {
00213 CmiAssert( pe >= 0 && pe < numPes );
00214 bgqtm.rankToCoordinates(pe, a, b, c, d, e, t);
00215 }
00216 #endif
00217
00218 int TopoManager::coordinatesToRank(int x, int y, int z) const {
00219 if(!( x>=0 && x<dimX && y>=0 && y<dimY && z>=0 && z<dimZ ))
00220 return -1;
00221 #if CMK_BIGSIM_CHARM
00222 if(dimY > 1)
00223 return x + y*dimX + z*dimX*dimY;
00224 else
00225 return x;
00226 #endif
00227
00228
00229 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00230 return xttm.coordinatesToRank(x, y, z, 0);
00231 #else
00232 if(dimY > 1)
00233 return x + y*dimX + z*dimX*dimY;
00234 else
00235 return CmiGetFirstPeOnPhysicalNode(x);
00236 #endif
00237 }
00238
00239 int TopoManager::coordinatesToRank(int x, int y, int z, int t) const {
00240 if(!( x>=0 && x<dimNX && y>=0 && y<dimNY && z>=0 && z<dimNZ && t>=0 && t<dimNT ))
00241 return -1;
00242 #if CMK_BIGSIM_CHARM
00243 if(dimNY > 1)
00244 return t + (x + (y + z*dimNY) * dimNX) * dimNT;
00245 else
00246 return t + x * dimNT;
00247 #endif
00248
00249 #if CMK_BLUEGENEQ
00250 return bgqtm.coordinatesToRank(x, y, z, t);
00251 #elif XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00252 return xttm.coordinatesToRank(x, y, z, t);
00253 #else
00254 if(dimNY > 1)
00255 return t + (x + (y + z*dimNY) * dimNX) * dimNT;
00256 else {
00257 if (t >= CmiNumPesOnPhysicalNode(x)) return -1;
00258 else return CmiGetFirstPeOnPhysicalNode(x)+t;
00259 }
00260 #endif
00261 }
00262
00263 #if CMK_BLUEGENEQ
00264 int TopoManager::coordinatesToRank(int a, int b, int c, int d, int e, int t) const {
00265 if(!( a>=0 && a<dimNA && b>=0 && b<dimNB && c>=0 && c<dimNC && d>=0 && d<dimND && e>=0 && e<dimNE && t>=0 && t<dimNT ))
00266 return -1;
00267 return bgqtm.coordinatesToRank(a, b, c, d, e, t);
00268 }
00269 #endif
00270
00271 int TopoManager::getHopsBetweenRanks(int pe1, int pe2) const {
00272 CmiAssert( pe1 >= 0 && pe1 < numPes );
00273 CmiAssert( pe2 >= 0 && pe2 < numPes );
00274 #if CMK_BLUEGENEQ
00275 int a1, b1, c1, d1, e1, t1, a2, b2, c2, d2, e2, t2;
00276 rankToCoordinates(pe1, a1, b1, c1, d1, e1, t1);
00277 rankToCoordinates(pe2, a2, b2, c2, d2, e2, t2);
00278 return (absA(a2-a1)+absB(b2-b1)+absC(c2-c1)+absD(d2-d1)+absE(e2-e1));
00279 #else
00280 int x1, y1, z1, x2, y2, z2, t1, t2;
00281 rankToCoordinates(pe1, x1, y1, z1, t1);
00282 rankToCoordinates(pe2, x2, y2, z2, t2);
00283 return (absX(x2-x1)+absY(y2-y1)+absZ(z2-z1));
00284 #endif
00285 }
00286
00287 int TopoManager::getHopsBetweenRanks(int *pe1, int pe2) const {
00288 CmiAssert( pe2 >= 0 && pe2 < numPes );
00289 #if CMK_BLUEGENEQ
00290 int a2, b2, c2, d2, e2, t2;
00291 rankToCoordinates(pe2, a2, b2, c2, d2, e2, t2);
00292 return (absA(a2-pe1[0])+absB(b2-pe1[1])+absC(c2-pe1[2]) +
00293 absD(d2-pe1[3])+absE(e2-pe1[4]));
00294 #else
00295 int x2, y2, z2, t2;
00296 rankToCoordinates(pe2, x2, y2, z2, t2);
00297 return (absX(x2-pe1[0])+absY(y2-pe1[1])+absZ(z2-pe1[2]));
00298 #endif
00299 }
00300
00301 void TopoManager::sortRanksByHops(int pe, int *pes, int *idx, int n) const {
00302 #if CMK_BLUEGENEQ
00303 int root_coords[6];
00304 rankToCoordinates(pe, root_coords[0], root_coords[1], root_coords[2],
00305 root_coords[3], root_coords[4], root_coords[5]);
00306 #else
00307 int root_coords[4];
00308 rankToCoordinates(pe, root_coords[0], root_coords[1], root_coords[2],
00309 root_coords[3]);
00310 #endif
00311 sortRanksByHops(root_coords, pes, idx, n);
00312 }
00313
00314 void TopoManager::sortRanksByHops(int* root_coords, int *pes, int *idx, int n) const {
00315 for(int i=0;i<n;i++)
00316 idx[i] = i;
00317 CompareRankDist comparator(root_coords, pes, n, this);
00318 std::sort(&idx[0], idx + n, comparator);
00319 }
00320
00321 int TopoManager::pickClosestRank(int mype, int *pes, int n) const {
00322 int minHops = getHopsBetweenRanks(mype, pes[0]);
00323 int minIdx=0;
00324 int nowHops;
00325 for(int i=1; i<n; i++) {
00326 nowHops = getHopsBetweenRanks(mype, pes[i]);
00327 if(nowHops < minHops) {
00328 minHops = nowHops;
00329 minIdx=i;
00330 }
00331 }
00332 return minIdx;
00333 }
00334
00335 int TopoManager::areNeighbors(int pe1, int pe2, int pe3, int distance) const {
00336 #if CMK_BLUEGENEQ
00337 int pe1_a, pe1_b, pe1_c, pe1_d, pe1_e, pe1_t;
00338 int pe2_a, pe2_b, pe2_c, pe2_d, pe2_e, pe2_t;
00339 int pe3_a, pe3_b, pe3_c, pe3_d, pe3_e, pe3_t;
00340 rankToCoordinates(pe1, pe1_a, pe1_b, pe1_c, pe1_d, pe1_e, pe1_t);
00341 rankToCoordinates(pe2, pe2_a, pe2_b, pe2_c, pe2_d, pe2_e, pe2_t);
00342 rankToCoordinates(pe3, pe3_a, pe3_b, pe3_c, pe3_d, pe3_e, pe3_t);
00343
00344 if ( (absA(pe1_a - (pe2_a+pe3_a)/2) + absB(pe1_b - (pe2_b+pe3_b)/2)+absC(pe1_c - (pe2_c+pe3_c)/2)+absD(pe1_d - (pe2_d+pe3_d)/2)+absE(pe1_e - (pe2_e+pe3_e)/2)) <= distance )
00345 return 1;
00346 else
00347 return 0;
00348 #else
00349 int pe1_x, pe1_y, pe1_z, pe1_t;
00350 int pe2_x, pe2_y, pe2_z, pe2_t;
00351 int pe3_x, pe3_y, pe3_z, pe3_t;
00352
00353 rankToCoordinates(pe1, pe1_x, pe1_y, pe1_z, pe1_t);
00354 rankToCoordinates(pe2, pe2_x, pe2_y, pe2_z, pe2_t);
00355 rankToCoordinates(pe3, pe3_x, pe3_y, pe3_z, pe3_t);
00356
00357 if ( (absX(pe1_x - (pe2_x+pe3_x)/2) + absY(pe1_y - (pe2_y+pe3_y)/2) + absZ(pe1_z - (pe2_z+pe3_z)/2)) <= distance )
00358 return 1;
00359 else
00360 return 0;
00361 #endif
00362 }
00363
00364 #if CMK_BLUEGENEQ
00365 void TopoManager::printAllocation(FILE *fp) const
00366 {
00367 int i,a,b,c,d,e,t;
00368 fprintf(fp, "Topology Info-\n");
00369 fprintf(fp, "NumPes - %d\n", numPes);
00370 fprintf(fp, "Dims - %d %d %d %d %d\n",dimNA,dimNB,dimNC,dimND,dimNE);
00371 fprintf(fp, "Rank - a b c d e t\n");
00372 for(i=0; i<numPes; i++) {
00373 rankToCoordinates(i,a,b,c,d,e,t);
00374 fprintf(fp, "%d/%d - %d/%d - %d %d %d %d %d %d\n",CmiGetPeGlobal(i,CmiMyPartition()),CmiGetNodeGlobal(CmiNodeOf(i),CmiMyPartition()),i,CmiNodeOf(i),a,b,c,d,e,t);
00375 }
00376 }
00377 #else
00378 void TopoManager::printAllocation(FILE *fp) const
00379 {
00380 int i,x,y,z,t;
00381 fprintf(fp, "Topology Info-\n");
00382 fprintf(fp, "NumPes - %d\n", numPes);
00383 fprintf(fp, "Dims - %d %d %d\n",dimNX,dimNY,dimNZ);
00384 fprintf(fp, "GlobalPe/GlobalNode - LocalPe/LocalNode - x y z t\n");
00385 for(i=0; i<numPes; i++) {
00386 rankToCoordinates(i,x,y,z,t);
00387 fprintf(fp, "%d/%d - %d/%d - %d %d %d %d\n",CmiGetPeGlobal(i,CmiMyPartition()),CmiGetNodeGlobal(CmiNodeOf(i),CmiMyPartition()),i,CmiNodeOf(i),x,y,z,t);
00388 }
00389 }
00390 #endif
00391
00392 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00393 extern "C" void craynid_init();
00394 extern "C" void craynid_reset();
00395 extern "C" void craynid_free();
00396 #elif CMK_BLUEGENEQ
00397 extern void bgq_topo_init();
00398 extern void bgq_topo_reset();
00399 extern void bgq_topo_free();
00400 #endif
00401
00402 static bool _topoInitialized = false;
00403 CmiNodeLock _topoLock = 0;
00404 TopoManager *_tmgr = NULL;
00405 #ifdef __TPM_STANDALONE__
00406 int _tpm_numpes = 0;
00407 int _tpm_numthreads = 1;
00408 #endif
00409
00410 TopoManager *TopoManager::getTopoManager() {
00411 CmiAssert(_topoInitialized);
00412 CmiAssert(_tmgr != NULL);
00413 return _tmgr;
00414 }
00415
00416 #ifndef __TPM_STANDALONE__
00417
00418 extern "C" void TopoManager_init() {
00419 #else
00420 extern "C" void TopoManager_init(int numpes) {
00421 _tpm_numpes = numpes;
00422 #endif
00423 if(!_topoInitialized) {
00424 _topoLock = CmiCreateLock();
00425 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00426 craynid_init();
00427 #elif CMK_BLUEGENEQ
00428 bgq_topo_init();
00429 #endif
00430 _topoInitialized = true;
00431 }
00432 #ifdef __TPM_STANDALONE__
00433 if(_tmgr) delete _tmgr;
00434 _tmgr = new TopoManager;
00435 #endif
00436 }
00437
00438 #ifdef __TPM_STANDALONE__
00439 extern "C" void TopoManager_setNumThreads(int t) {
00440 _tpm_numthreads = t;
00441 }
00442 #endif
00443
00444 extern "C" void TopoManager_reset() {
00445 CmiLock(_topoLock);
00446 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00447 craynid_reset();
00448 #elif CMK_BLUEGENEQ
00449 bgq_topo_reset();
00450 #endif
00451 if(_tmgr) delete _tmgr;
00452 _tmgr = new TopoManager;
00453 CmiUnlock(_topoLock);
00454 }
00455
00456 extern "C" void TopoManager_free() {
00457 CmiLock(_topoLock);
00458 if(_tmgr) delete _tmgr;
00459 _tmgr = NULL;
00460 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00461 craynid_free();
00462 #elif CMK_BLUEGENEQ
00463 bgq_topo_free();
00464 #endif
00465 CmiUnlock(_topoLock);
00466 }
00467
00468 extern "C" void TopoManager_printAllocation(FILE *fp) {
00469 #ifndef __TPM_STANDALONE__
00470 if(_tmgr == NULL) { TopoManager_reset(); }
00471 #else
00472 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00473 #endif
00474
00475 _tmgr->printAllocation(fp);
00476 }
00477
00478 extern "C" void TopoManager_getDimCount(int *ndims) {
00479 #if CMK_BLUEGENEQ
00480 *ndims = 5;
00481 #else
00482 *ndims = 3;
00483 #endif
00484 }
00485
00486 extern "C" void TopoManager_getDims(int *dims) {
00487 #ifndef __TPM_STANDALONE__
00488 if(_tmgr == NULL) { TopoManager_reset(); }
00489 #else
00490 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00491 #endif
00492
00493 #if CMK_BLUEGENEQ
00494 dims[0] = _tmgr->getDimNA();
00495 dims[1] = _tmgr->getDimNB();
00496 dims[2] = _tmgr->getDimNC();
00497 dims[3] = _tmgr->getDimND();
00498 dims[4] = _tmgr->getDimNE();
00499 dims[5] = _tmgr->getDimNT()/CmiMyNodeSize();
00500 #else
00501 dims[0] = _tmgr->getDimNX();
00502 dims[1] = _tmgr->getDimNY();
00503 dims[2] = _tmgr->getDimNZ();
00504 dims[3] = _tmgr->getDimNT()/CmiMyNodeSize();
00505 #endif
00506 }
00507
00508 extern "C" void TopoManager_getCoordinates(int rank, int *coords) {
00509 #ifndef __TPM_STANDALONE__
00510 if(_tmgr == NULL) { TopoManager_reset(); }
00511 #else
00512 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00513 #endif
00514
00515 int t;
00516 #if CMK_BLUEGENEQ
00517 _tmgr->rankToCoordinates(CmiNodeFirst(rank),coords[0],coords[1],coords[2],coords[3],coords[4],t);
00518 #else
00519 _tmgr->rankToCoordinates(CmiNodeFirst(rank),coords[0],coords[1],coords[2],t);
00520 #endif
00521 }
00522
00523 extern "C" void TopoManager_getPeCoordinates(int rank, int *coords) {
00524 #ifndef __TPM_STANDALONE__
00525 if(_tmgr == NULL) { TopoManager_reset(); }
00526 #else
00527 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00528 #endif
00529
00530 #if CMK_BLUEGENEQ
00531 _tmgr->rankToCoordinates(rank,coords[0],coords[1],coords[2],coords[3],coords[4],coords[5]);
00532 #else
00533 _tmgr->rankToCoordinates(rank,coords[0],coords[1],coords[2],coords[3]);
00534 #endif
00535 }
00536
00537 void TopoManager_getRanks(int *rank_cnt, int *ranks, int *coords) {
00538 #ifndef __TPM_STANDALONE__
00539 if(_tmgr == NULL) { TopoManager_reset(); }
00540 #else
00541 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00542 #endif
00543
00544 *rank_cnt = 0;
00545 for(int t = 0; t < _tmgr->getDimNT(); t += CmiMyNodeSize()) {
00546 #if CMK_BLUEGENEQ
00547 int rank = _tmgr->coordinatesToRank(coords[0],coords[1],coords[2],coords[3],coords[4],t);
00548 #else
00549 int rank = _tmgr->coordinatesToRank(coords[0],coords[1],coords[2],t);
00550 #endif
00551 if(rank != -1) {
00552 ranks[*rank_cnt] = CmiNodeOf(rank);
00553 *rank_cnt = *rank_cnt + 1;
00554 }
00555 }
00556 }
00557
00558 extern "C" void TopoManager_getPeRank(int *rank, int *coords) {
00559 #ifndef __TPM_STANDALONE__
00560 if(_tmgr == NULL) { TopoManager_reset(); }
00561 #else
00562 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00563 #endif
00564
00565 #if CMK_BLUEGENEQ
00566 *rank = _tmgr->coordinatesToRank(coords[0],coords[1],coords[2],coords[3],coords[4],coords[5]);
00567 #else
00568 *rank = _tmgr->coordinatesToRank(coords[0],coords[1],coords[2],coords[3]);
00569 #endif
00570 }
00571
00572 extern "C" void TopoManager_getHopsBetweenPeRanks(int pe1, int pe2, int *hops) {
00573 #ifndef __TPM_STANDALONE__
00574 if(_tmgr == NULL) { TopoManager_reset(); }
00575 #else
00576 if(_tmgr == NULL) { printf("ERROR: TopoManager NOT initialized. Aborting...\n"); exit(1); }
00577 #endif
00578
00579 *hops = _tmgr->getHopsBetweenRanks(pe1, pe2);
00580 }
00581
00582 #ifndef __TPM_STANDALONE__
00583 extern "C" void TopoManager_createPartitions(int scheme, int numparts, int *nodeMap) {
00584 if(scheme == 0) {
00585 if(!CmiMyNodeGlobal()) {
00586 printf("Charm++> Using rank ordered division (scheme 0) for topology aware partitions\n");
00587 }
00588 int i;
00589 for(i = 0; i < CmiNumNodes(); i++) {
00590 nodeMap[i] = i;
00591 }
00592 } else if(scheme == 1) {
00593 if(!CmiMyNodeGlobal()) {
00594 printf("Charm++> Using planar division (scheme 1) for topology aware partitions\n");
00595 }
00596 getPlanarList(nodeMap);
00597 } else if(scheme == 2) {
00598 if(!CmiMyNodeGlobal()) {
00599 printf("Charm++> Using hilber curve (scheme 2) for topology aware partitions\n");
00600 }
00601 getHilbertList(nodeMap);
00602 } else if(scheme == 3) {
00603 if(!CmiMyNodeGlobal()) {
00604 printf("Charm++> Using recursive bisection (scheme 3) for topology aware partitions\n");
00605 }
00606 getRecursiveBisectionList(numparts,nodeMap);
00607 } else {
00608 CmiAbort("Specified value for topology scheme is not supported\n");
00609 }
00610 }
00611 #endif