5 #include "TopoManager.h"
12 extern TopoManager *topoMgr;
23 MapFile::MapFile(
const char* name,
int numpes)
26 topoMgr=
new TopoManager();
27 mapName = (
char *)malloc(
sizeof(
char)*15);
28 strcpy(mapName, name);
33 MapFile::MapFile(
const char* name,
int num,
int* size,
int numpes,
const char *order,
int x,
int y,
int z,
int t,
int _stride)
36 topoMgr=
new TopoManager();
37 mapName = (
char *)malloc(
sizeof(
char)*15);
38 strcpy(mapName, name);
40 sizeDim = (
int *)malloc(
sizeof(
int)*numDim);
41 for(
int i=0; i<numDim; i++)
44 mapOrder = (
char *)malloc(
sizeof(
char)*5);
45 strcpy(mapOrder, (
const char*)order);
54 void MapFile::setSize(
int num,
int* size)
58 sizeDim = (
int *)malloc(
sizeof(
int)*numDim);
59 for(
int i=0; i<numDim; i++)
64 void MapFile::setAttributes(
int num,
int* size,
char *order,
int x,
int y,
int z,
int t,
int _stride)
68 sizeDim = (
int *)malloc(
sizeof(
int)*numDim);
69 for(
int i=0; i<numDim; i++)
72 mapOrder = (
char *)malloc(
sizeof(
char)*5);
73 strcpy(mapOrder, (
const char*)order);
82 void MapFile::dumpMapCoords(
MapType2 *map,
char c)
85 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
86 FILE *fp = fopen(name,
"w");
87 fprintf(fp,
"%s %d ", mapName, numDim);
88 for(
int i=0; i<numDim; i++)
89 fprintf(fp,
"%d ", sizeDim[i]);
90 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
91 for(
int i=0; i<sizeDim[0]; i++)
92 for(
int j=0; j<sizeDim[1]; j++)
94 int proc=map->get(i, j);
96 topoMgr->rankToCoordinates(proc, X, Y, Z, T);
97 fprintf(fp,
"%d %d %d %d %d %d %d\n", i, j, proc,X,Y,Z,T);
103 void MapFile::dumpMapCoords(
MapType4 *map,
char c)
106 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
107 FILE *fp = fopen(name,
"w");
108 fprintf(fp,
"%s %d ", mapName, numDim);
109 for(
int i=0; i<numDim; i++)
110 fprintf(fp,
"%d ", sizeDim[i]);
111 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
112 for(
int i=0; i<sizeDim[0]; i++)
113 for(
int j=0; j<sizeDim[1]*stride; j+=stride)
114 for(
int k=0; k<sizeDim[2]*stride; k+=stride)
115 for(
int l=0; l<sizeDim[3]; l++)
117 int proc=map->get(i, j, k, l);
119 topoMgr->rankToCoordinates(proc, X, Y, Z, T);
121 fprintf(fp,
"%d %d %d %d %d %d %d %d %d\n", i, j, k, l, proc, X, Y, Z, T);
127 void MapFile::dumpMapCoords(
MapType3 *map,
char c)
130 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
131 FILE *fp = fopen(name,
"w");
132 fprintf(fp,
"%s %d ", mapName, numDim);
133 for(
int i=0; i<numDim; i++)
134 fprintf(fp,
"%d ", sizeDim[i]);
135 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
136 for(
int i=0; i<sizeDim[0]; i++)
137 for(
int j=0; j<sizeDim[1]; j++)
138 for(
int k=0; k<sizeDim[2]; k++)
140 int proc=map->get(i, j, k);
142 topoMgr->rankToCoordinates(proc, X, Y, Z, T);
144 fprintf(fp,
"%d %d %d %d %d %d %d %d\n", i, j, k, proc, X, Y ,Z, T);
150 void MapFile::dumpMap(
MapType2 *map,
char c)
153 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
154 FILE *fp = fopen(name,
"w");
155 fprintf(fp,
"%s %d ", mapName, numDim);
156 for(
int i=0; i<numDim; i++)
157 fprintf(fp,
"%d ", sizeDim[i]);
158 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
159 for(
int i=0; i<sizeDim[0]; i++)
160 for(
int j=0; j<sizeDim[1]; j++)
161 fprintf(fp,
"%d %d %d\n", i, j, map->get(i, j));
166 void MapFile::dumpMap(
MapType4 *map,
char c)
169 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
170 FILE *fp = fopen(name,
"w");
171 fprintf(fp,
"%s %d ", mapName, numDim);
172 for(
int i=0; i<numDim; i++)
173 fprintf(fp,
"%d ", sizeDim[i]);
174 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
175 for(
int i=0; i<sizeDim[0]; i++)
176 for(
int j=0; j<sizeDim[1]*stride; j+=stride)
177 for(
int k=0; k<sizeDim[2]*stride; k+=stride)
178 for(
int l=0; l<sizeDim[3]; l++)
179 fprintf(fp,
"%d %d %d %d %d\n", i, j, k, l, map->get(i, j, k, l));
184 void MapFile::dumpMap(
MapType3 *map,
char c)
187 sprintf(name,
"%s_inst_%d", mapName, (
int)c);
188 FILE *fp = fopen(name,
"w");
189 fprintf(fp,
"%s %d ", mapName, numDim);
190 for(
int i=0; i<numDim; i++)
191 fprintf(fp,
"%d ", sizeDim[i]);
192 fprintf(fp,
"\n%d %d %d %d %d\n", numProcs, topoMgr->getDimNX(), topoMgr->getDimNY(), topoMgr->getDimNZ(), topoMgr->getDimNT());
193 for(
int i=0; i<sizeDim[0]; i++)
194 for(
int j=0; j<sizeDim[1]; j++)
195 for(
int k=0; k<sizeDim[2]; k++)
196 fprintf(fp,
"%d %d %d %d\n", i, j, k, map->get(i, j, k));
201 int MapFile::loadMap(
const char *filename,
MapType2 *map)
204 FILE *fp = fopen(filename,
"r");
207 assert(fscanf(fp,
"%s%d%d%d%d", mapName, &numDim, &sizeDim[0], &sizeDim[1], &numProcs));
208 for(
int i=0; i<sizeDim[0]; i++)
209 for(
int j=0; j<sizeDim[1]; j++)
211 assert(fscanf(fp,
"%d%d%d\n", &x, &y, &pe));
215 CkPrintf(
"%s loaded from file ----\n", filename);
219 int MapFile::loadMap(
const char *filename,
MapType3 *map)
222 FILE *fp = fopen(filename,
"r");
225 assert(fscanf(fp,
"%s%d%d%d%d%d", mapName, &numDim, &sizeDim[0], &sizeDim[1], &sizeDim[2], &sizeDim[3], &numProcs));
226 for(
int i=0; i<sizeDim[0]; i++)
227 for(
int j=0; j<sizeDim[1]; j++)
228 for(
int k=0; k<sizeDim[2]; k++)
230 assert(fscanf(fp,
"%d%d%d%d", &x, &y, &z, &pe));
231 map->set(x, y, z, pe);
234 CkPrintf(
"%s loaded from file ----\n", filename);
239 int MapFile::loadMap(
const char *filename,
MapType4 *map)
242 FILE *fp = fopen(filename,
"r");
245 assert(fscanf(fp,
"%s%d%d%d%d%d%d", mapName, &numDim, &sizeDim[0], &sizeDim[1], &sizeDim[2], &sizeDim[3], &numProcs));
246 for(
int i=0; i<sizeDim[0]; i++)
247 for(
int j=0; j<sizeDim[1]*stride; j+=stride)
248 for(
int k=0; k<sizeDim[2]*stride; k+=stride)
249 for(
int l=0; l<sizeDim[3]; l++)
251 assert(fscanf(fp,
"%d%d%d%d%d", &x, &y, &z, &w, &pe));
252 map->set(x, y, z, w, pe);
255 CkPrintf(
"%s loaded from file ----\n", filename);
Author: Abhinav S Bhatele Date Created: December 28th, 2006.