00001
00007 #ifndef _XT_TORUS_H_
00008 #define _XT_TORUS_H_
00009
00010 #include "topomanager_config.h"
00011 #ifndef __TPM_STANDALONE__
00012 #include "converse.h"
00013 #else
00014 #include "tpm_standalone.h"
00015 #endif
00016
00017 #include <stdlib.h>
00018 #include <stdio.h>
00019
00020 #if XE6_TOPOLOGY
00021 #define CPU_FACTOR 2
00022 #else
00023 #define CPU_FACTOR 1
00024 #endif
00025
00026 #if CMK_HAS_RCALIB
00027 #include <rca_lib.h>
00028 #endif
00029
00030 #if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
00031
00032 extern "C" int *pid2nid;
00033 extern "C" int pidtonid(int numpes);
00034 extern "C" int getMeshCoord(int nid, int *x, int *y, int *z);
00035 extern "C" void getDimension(int *,int *, int *, int *);
00036 #if CMK_HAS_RCALIB
00037 extern "C" rca_mesh_coord_t *rca_coords;
00038 #endif
00039
00040 struct loc {
00041 int x;
00042 int y;
00043 int z;
00044 int t;
00045 };
00046
00047 class XTTorusManager {
00048 private:
00049 int dimX;
00050 int dimY;
00051 int dimZ;
00052 int dimNX;
00053 int dimNY;
00054 int dimNZ;
00055 int dimNT;
00056 int xDIM, yDIM, zDIM, maxNID;
00057
00058 int torus[4];
00059 int procsPerNode;
00060
00061 int ****coords2pid;
00062 struct loc *pid2coords;
00063
00064 public:
00065 XTTorusManager() {
00066 int nid = 0, oldnid = -1, lx, ly, lz;
00067 int i, j, k, l;
00068 int numCores;
00069
00070 int numPes = CmiNumPes();
00071 pid2coords = (struct loc*)malloc(sizeof(struct loc) * numPes);
00072 _MEMCHECK(pid2coords);
00073
00074
00075 pidtonid(numPes);
00076 getDimension(&maxNID,&xDIM,&yDIM,&zDIM);
00077 numCores = CmiNumCores()*CPU_FACTOR;
00078
00079 coords2pid = (int ****)malloc(xDIM*sizeof(int***));
00080 _MEMCHECK(coords2pid);
00081 for(i=0; i<xDIM; i++) {
00082 coords2pid[i] = (int ***)malloc(yDIM*sizeof(int**));
00083 _MEMCHECK(coords2pid[i]);
00084 for(j=0; j<yDIM; j++) {
00085 coords2pid[i][j] = (int **)malloc(zDIM*sizeof(int*));
00086 _MEMCHECK(coords2pid[i][j]);
00087 for(k=0; k<zDIM; k++) {
00088 coords2pid[i][j][k] = (int *)malloc(numCores*sizeof(int*));
00089 _MEMCHECK(coords2pid[i][j][k]);
00090 }
00091 }
00092 }
00093
00094 for(i=0; i<xDIM; i++)
00095 for(j=0; j<yDIM; j++)
00096 for(k=0; k<zDIM; k++)
00097 for(l=0; l<numCores; l++)
00098 coords2pid[i][j][k][l] = -1;
00099
00100 dimNT = 1;
00101
00102 for(i=0; i<numPes; i++)
00103 {
00104 nid = pid2nid[i];
00105 if (nid != oldnid) {
00106 int ret = getMeshCoord(nid, &lx, &ly, &lz);
00107 CmiAssert(ret != -1);
00108 }
00109 oldnid = nid;
00110
00111 pid2coords[i].x = lx;
00112 pid2coords[i].y = ly;
00113 pid2coords[i].z = lz;
00114
00115 l = 0;
00116 while(coords2pid[lx][ly][lz][l] != -1)
00117 l++;
00118 CmiAssert(l<numCores);
00119 coords2pid[lx][ly][lz][l] = i;
00120 pid2coords[i].t = l;
00121 if((l+1) > dimNT)
00122 dimNT = l+1;
00123 }
00124
00125
00126
00127 dimNX = xDIM;
00128 dimNY = yDIM;
00129 dimNZ = zDIM;
00130 procsPerNode = dimNT;
00131 dimX = dimNX * dimNT;
00132 dimY = dimNY;
00133 dimZ = dimNZ;
00134
00135
00136 torus[0] = 1;
00137 torus[1] = 1;
00138 torus[2] = 1;
00139 torus[3] = 1;
00140 }
00141
00142 ~XTTorusManager() {
00143 int i,j,k;
00144 free(pid2coords);
00145 for(i=0; i<xDIM; i++) {
00146 for(j=0; j<yDIM; j++) {
00147 for(k=0; k<zDIM; k++) {
00148 free(coords2pid[i][j][k]);
00149 }
00150 free(coords2pid[i][j]);
00151 }
00152 free(coords2pid[i]);
00153 }
00154 free(coords2pid);
00155 }
00156
00157 inline int getDimX() { return dimX; }
00158 inline int getDimY() { return dimY; }
00159 inline int getDimZ() { return dimZ; }
00160
00161 inline int getDimNX() { return dimNX; }
00162 inline int getDimNY() { return dimNY; }
00163 inline int getDimNZ() { return dimNZ; }
00164 inline int getDimNT() { return dimNT; }
00165
00166 inline int getProcsPerNode() { return procsPerNode; }
00167
00168 inline int* isTorus() { return torus; }
00169
00170 inline void rankToCoordinates(int pe, int &x, int &y, int &z, int &t) const {
00171 x = pid2coords[pe].x;
00172 y = pid2coords[pe].y;
00173 z = pid2coords[pe].z;
00174 t = pid2coords[pe].t;
00175 }
00176
00177 inline int coordinatesToRank(int x, int y, int z, int t) const {
00178 return coords2pid[x][y][z][t];
00179 }
00180 };
00181
00182 #endif // XT4_TOPOLOGY || XT5_TOPOLOGY ||XE6_TOPOLOGY
00183 #endif //_XT_TORUS_H_