00001
00016 #ifndef _CRAY_TORUS_H_
00017 #define _CRAY_TORUS_H_
00018
00019 #include "converse.h"
00020
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023
00024 #if XT3_TOPOLOGY
00025
00026 #define CPU_FACTOR 1
00027
00028
00029
00030
00031
00032
00033
00034 extern "C" int *pid2nid;
00035 extern "C" int pidtonid(int numpes);
00036 extern "C" int getMeshCoord(int nid, int *x, int *y, int *z);
00037 extern "C" void getDimension(int *,int *, int *, int *);
00038
00039 struct loc {
00040 int x;
00041 int y;
00042 int z;
00043 int t;
00044 };
00045
00046 class XT3TorusManager {
00047 private:
00048 int dimX;
00049 int dimY;
00050 int dimZ;
00051 int dimNX;
00052 int dimNY;
00053 int dimNZ;
00054 int dimNT;
00055 int xDIM, yDIM, ZDIM, maxNID;
00056
00057 int torus[4];
00058 int procsPerNode;
00059 char mapping[10];
00060
00061 int ****coords2pid;
00062 struct loc *pid2coords;
00063 struct loc origin;
00064
00065 public:
00066 XT3TorusManager() {
00067 int nid = 0, oldnid = -1, lx, ly, lz;
00068 int numCores;
00069 int minX, minY, minZ, minT=0, maxX=0, maxY=0, maxZ=0;
00070
00071 int numPes = CmiNumPes();
00072 pid2coords = (struct loc*)malloc(sizeof(struct loc) * numPes);
00073
00074
00075 pidtonid(numPes);
00076 getDimension(&maxNID,&xDIM,&yDIM,&zDIM);
00077 minX=xDIM, minY=yDIM, minZ=zDIM;
00078 numCores = CmiNumCores()*CPU_FACTOR;
00079
00080 coords2pid = (int ****)malloc(xDIM*sizeof(int***));
00081 for(i=0; i<xDIM; i++) {
00082 coords2pid[i] = (int ***)malloc(yDIM*sizeof(int**));
00083 for(j=0; j<yDIM; j++) {
00084 coords2pid[i][j] = (int **)malloc(zDIM*sizeof(int*));
00085 for(k=0; k<zDIM; k++) {
00086 coords2pid[i][j][k] = (int *)malloc(numCores*sizeof(int*));
00087 }
00088 }
00089 }
00090
00091 for(i=0; i<xDIM; i++)
00092 for(j=0; j<yDIM; j++)
00093 for(k=0; k<zDIM; k++)
00094 for(l=0; l<numCores; l++)
00095 coords2pid[i][j][k][l] = -1;
00096
00097 dimNT = 1;
00098
00099 for(int i=0; i<numPes; i++)
00100 {
00101 nid = pid2nid[i];
00102 if (nid != oldnid)
00103 getMeshCoord(nid, &lx, &ly, &lz);
00104 oldnid = nid;
00105
00106 pid2coords[i].x = lx;
00107 pid2coords[i].y = ly;
00108 pid2coords[i].z = lz;
00109
00110 if(lx >= XDIM) printf("ERROR in X %d lx %d ly %d lz %d\n", i, lx, ly, lz);
00111 if(ly >= YDIM) printf("ERROR in Y %d lx %d ly %d lz %d\n", i, lx, ly, lz);
00112 if(lz >= ZDIM) printf("ERROR in Z %d lx %d ly %d lz %d\n", i, lx, ly, lz);
00113
00114 if (coords2pid[lx][ly][lz][0] == -1) {
00115 coords2pid[lx][ly][lz][0] = i;
00116 pid2coords[i].t = 0;
00117 } else {
00118 dimNT = 2;
00119 coords2pid[lx][ly][lz][1] = i;
00120 pid2coords[i].t = 1;
00121 }
00122
00123 if (lx<minX) minX = lx; if (lx>maxX) maxX = lx;
00124 if (ly<minY) minY = ly; if (ly>maxY) maxY = ly;
00125 if (lz<minZ) minZ = lz; if (lz>maxZ) maxZ = lz;
00126 }
00127
00128
00129
00130 origin.x = minX;
00131 origin.y = minY;
00132 origin.z = minZ;
00133 origin.t = minT;
00134
00135
00136
00137 dimNX = maxX - minX + 1;
00138 dimNY = maxY - minY + 1;
00139 dimNZ = maxZ - minZ + 1;
00140 procsPerNode = dimNT;
00141 dimX = dimNX * dimNT;
00142 dimY = dimNY;
00143 dimZ = dimNZ;
00144
00145
00146 torus[0] = (dimNX == xDIM) ? 1 : 0;
00147 torus[1] = (dimNY == yDIM) ? 1 : 0;
00148 torus[2] = (dimNZ == zDIM) ? 1 : 0;
00149 torus[3] = 0;
00150
00151 if(dimNT == 2) {
00152 int pe1 = coordinatesToRank(0, 0, 0, 0);
00153 int pe2 = coordinatesToRank(0, 0, 0, 1);
00154 if(pe2 == pe1 +1)
00155 sprintf(mapping, "%s", "TXYZ");
00156 else
00157 sprintf(mapping, "%s", "XYZT");
00158 }
00159 }
00160
00161 ~XT3TorusManager() {
00162 int i,j,k;
00163 free(pid2coords);
00164 for(i=0; i<xDIM; i++) {
00165 for(j=0; j<yDIM; j++) {
00166 for(k=0; k<zDIM; k++) {
00167 free(coords2pid[i][j][k]);
00168 }
00169 free(coords2pid[i][j]);
00170 }
00171 free(coords2pid[i]);
00172 }
00173 }
00174
00175 inline int getDimX() { return dimX; }
00176 inline int getDimY() { return dimY; }
00177 inline int getDimZ() { return dimZ; }
00178
00179 inline int getDimNX() { return dimNX; }
00180 inline int getDimNY() { return dimNY; }
00181 inline int getDimNZ() { return dimNZ; }
00182 inline int getDimNT() { return dimNT; }
00183
00184 inline int getProcsPerNode() { return procsPerNode; }
00185
00186 inline int* isTorus() { return torus; }
00187
00188 inline void rankToCoordinates(int pe, int &x, int &y, int &z, int &t) {
00189 x = pid2coords[pe].x - origin.x;
00190 y = pid2coords[pe].y - origin.y;
00191 z = pid2coords[pe].z - origin.z;
00192 t = pid2coords[pe].t - origin.t;
00193 }
00194
00195 inline void realRankToCoordinates(int pe, int &x, int &y, int &z, int &t) {
00196 x = pid2coords[pe].x;
00197 y = pid2coords[pe].y;
00198 z = pid2coords[pe].z;
00199 t = pid2coords[pe].t;
00200 }
00201
00202 inline int coordinatesToRank(int x, int y, int z, int t) {
00203 return coords2pid[x+origin.x][y+origin.y][z+origin.z][t+origin.t];
00204 }
00205 };
00206
00207 #endif // XT3_TOPOLOGY
00208 #endif //_CRAY_TORUS_H_