7 #include "mixtesim_prototypes.h"
18 return (Host)calloc(1,sizeof(struct _Host));
37 return (Link)calloc(1,sizeof(struct _Link));
46 free(l->latency_trace);
47 if (l->bandwidth_trace)
48 free(l->bandwidth_trace);
58 return (Grid)calloc(1,sizeof(struct _Grid));
67 for (i=0;i<g->nb_hosts;i++)
68 freeHost(g->hosts[i]);
71 for (i=0;i<g->nb_links;i++)
72 freeLink(g->links[i]);
76 for (i=0;i<g->nb_hosts;i++) {
77 if (g->connections[i]) {
78 free(g->connections[i]);
92 static int createConnectionMatrix(Grid grid);
93 static int parseLine(Grid,char*);
94 static int parseLinkCountLine(Grid,char*);
95 static int parseHostCountLine(Grid,char*);
96 static int parseLinkLine(Grid,char*);
97 static int parseHostLine(Grid,char*);
102 Grid parseGridFile(char *filename)
109 new->nb_host = SD_workstation_get_number();
112 new->nb_link = SD_link_get_number();
121 /* open Grid description file */
122 if (!(f=fopen(filename,"r"))) {
123 fprintf(stderr,"Impossible to open file '%s'\n",filename);
127 /* Allocate memory for the Grid */
130 /* go through the lines in the files */
131 while(fgets(line,4084,f)) {
133 if (line[0]=='#') /* comment line */
135 if (line[0]=='\n') /* empty line */
137 tmp=strdup(line); /* strdupoing seesm to make it work */
138 if (parseLine(new,tmp) == -1) {
139 fprintf(stderr,"Error in Grid description file at line %d\n",count);
147 /* Create the connection matrix */
148 createConnectionMatrix(new);
156 static int parseLine(Grid grid, char *line)
159 /* does the line start with a keyword ? */
160 ptr=strchr(line,' ');
162 fprintf(stderr,"Syntax error\n");
167 /* process the different key words */
168 if (!strncmp(line,"LINK_COUNT",strlen("LINK_COUNT")))
169 return parseLinkCountLine(grid,ptr+1);
170 if (!strncmp(line,"LINK",strlen("LINK")))
171 return parseLinkLine(grid,ptr+1);
172 if (!strncmp(line,"HOST_COUNT",strlen("HOST_COUNT")))
173 return parseHostCountLine(grid,ptr+1);
174 if (!strncmp(line,"HOST",strlen("HOST")))
175 return parseHostLine(grid,ptr+1);
177 fprintf(stderr,"Unknown keyword %s\n",line);
182 * parseHostCountLine()
184 * HOST_COUNT <number>
186 int parseHostCountLine(Grid grid, char *line)
190 /* HOST_COUNT should be called only once */
191 if (grid->nb_hosts != 0) {
192 fprintf(stderr,"Error: Only one Host Count specification allowed\n");
198 /* check that count >0 */
200 fprintf(stderr,"Error: invalid Host count\n");
203 /* allocate the grid->hosts array */
204 grid->nb_hosts=count;
205 grid->hosts=(Host *)calloc(grid->nb_hosts,sizeof(Host));
207 /* allocate the connection matrix */
208 grid->connections=(Link ***)calloc(grid->nb_hosts,sizeof(Link**));
209 for (i=0;i<grid->nb_hosts;i++) {
210 grid->connections[i]=(Link **)calloc(grid->nb_hosts,sizeof(Link*));
216 * parseLinkCountLine()
218 * LINK_COUNT <number>
220 int parseLinkCountLine(Grid grid, char *line)
224 /* LINK_COUNT should be called only once */
225 if (grid->nb_links != 0) {
226 fprintf(stderr,"Error: Only one Link Count specification allowed\n");
233 fprintf(stderr,"Error: invalid Link count\n");
236 /* allocate the grid->links array */
237 grid->nb_links=count;
238 grid->links=(Link *)calloc(grid->nb_links,sizeof(Link));
246 * HOST <index> <rel_speed> <cpu_file>
248 int parseHostLine(Grid grid, char *line)
252 char *s_indexlist,*s_cpu_file,*s_rel_speed,*s_mode;
253 int *hostIndexList=NULL;
254 int nb_hostOnLine, i, min,max;
257 /* HOST_COUNT must be called before HOST */
258 if (grid->nb_hosts == 0) {
259 fprintf(stderr,"Error: Host Count must be specified before Hosts\n");
264 ptr=strchr(line,' ');
266 fprintf(stderr,"Syntax error\n");
274 ptr=strchr(line,' ');
276 fprintf(stderr,"Syntax error\n");
284 ptr=strchr(line,' ');
286 fprintf(stderr,"Syntax error\n");
294 ptr=strchr(line,'\n');
296 fprintf(stderr,"Syntax error\n");
302 /* Process strings */
303 ptr = strchr(s_indexlist,'-');
304 min = atoi(s_indexlist);
306 nb_hostOnLine = max-min+1;
307 hostIndexList=(int*)calloc(max-min+1,sizeof(int));
308 for (i=0;i<max-min+1;i++){
309 hostIndexList[i]=min+i;
312 rel_speed=atof(s_rel_speed);
314 /* Creating the hosts */
315 for (i=0;i<nb_hostOnLine;i++){
317 host->global_index = min+i;
318 host->rel_speed = rel_speed;
319 if (!host->global_index) {
321 } else if (host->rel_speed !=
322 grid->hosts[host->global_index-1]->rel_speed) {
323 host->cluster = grid->hosts[host->global_index-1]->cluster +1;
325 host->cluster = grid->hosts[host->global_index-1]->cluster;
328 host->cpu_trace = strdup(s_cpu_file);
329 if (!strcmp(s_mode,"IN_ORDER")) {
330 host->mode = SG_SEQUENTIAL_IN_ORDER;
331 } else if (!strcmp(s_mode,"OUT_OF_ORDER")) {
332 host->mode = SG_SEQUENTIAL_OUT_OF_ORDER;
333 } else if (!strcmp(s_mode,"TIME_SLICED")) {
334 host->mode = SG_TIME_SLICED;
336 fprintf(stderr,"Error: invalid mode specification '%s'\n",s_mode);
339 /* Is the host beyond the index */
340 if (host->global_index >= grid->nb_hosts) {
341 fprintf(stderr,"Error: More hosts than the host count\n");
345 /* Have we seen that host before ? */
346 if (grid->hosts[host->global_index] != NULL) {
347 fprintf(stderr,"Error: Two hosts share index %d\n",
351 /* Add the host to the grid->hosts array */
352 grid->hosts[host->global_index]=host;
360 * LINK <index> <lat_file> <band_file>
362 int parseLinkLine(Grid grid, char *line)
368 char *s_indexlist,*s_lat_file,*s_band_file,*s_mode;
369 int *linkIndexList=NULL;
370 int nb_linkOnLine, i, min,max;
372 /* LINK_COUNT must be called before LINK */
373 if (grid->nb_links == 0) {
374 fprintf(stderr,"Error: Link Count must be specified before Links\n");
379 ptr=strchr(line,' ');
381 fprintf(stderr,"Syntax error\n");
390 ptr=strchr(line,' ');
392 fprintf(stderr,"Syntax error\n");
400 ptr=strchr(line,' ');
402 fprintf(stderr,"Syntax error\n");
410 ptr=strchr(line,'\n');
412 fprintf(stderr,"Syntax error\n");
418 /* Process strings */
419 ptr = strchr(s_indexlist,'-');
420 min = atoi(s_indexlist);
426 nb_linkOnLine = max-min+1;
427 linkIndexList=(int*)calloc(max-min+1,sizeof(int));
428 for (i=0;i<max-min+1;i++){
429 linkIndexList[i]=min+i;
432 /* Creating the link */
433 for (i=0;i<nb_linkOnLine;i++){
435 link->global_index = min+i;
436 link->latency_trace=strdup(s_lat_file);
437 link->bandwidth_trace=strdup(s_band_file);
438 if (!strcmp(s_mode,"IN_ORDER")) {
439 link->mode = SG_SEQUENTIAL_IN_ORDER;
440 } else if (!strcmp(s_mode,"OUT_OF_ORDER")) {
441 link->mode = SG_SEQUENTIAL_OUT_OF_ORDER;
442 } else if (!strcmp(s_mode,"TIME_SLICED")) {
443 link->mode = SG_TIME_SLICED;
444 } else if (!strcmp(s_mode,"FAT_PIPE")){
445 link->mode = SG_FAT_PIPE;
447 fprintf(stderr,"Error: invalid mode specification '%s'\n",s_mode);
450 sprintf(buffer,"link%d",min+i);
452 /* Is the node beyond the index */
453 if (link->global_index >= grid->nb_links) {
454 fprintf(stderr,"Error: More links than the link count\n");
459 /* Have we seen that link before ? */
460 if (grid->links[link->global_index] != NULL) {
461 fprintf(stderr,"Error: Two links share index %d\n",
465 /* Add the link to the grid->links array */
466 grid->links[link->global_index]=link;
471 static int createConnectionMatrix(Grid grid){
473 for (i=0;i<grid->nb_hosts;i++){
474 for(j=0;j<grid->nb_hosts;j++){
476 grid->connections[i][j]=(Link*)calloc(1, sizeof(Link));
477 grid->connections[i][j][0]=newLink();
478 (grid->connections[i][j][0])->global_index=-1;
480 /* Intra cluster connection */
481 if (grid->hosts[i]->cluster == grid->hosts[j]->cluster) {
482 grid->connections[i][j]=(Link*)calloc(3, sizeof(Link));
483 grid->connections[i][j][0]= grid->links[i];
484 grid->connections[i][j][1]=
485 grid->links[grid->nb_hosts+grid->hosts[i]->cluster];
486 grid->connections[i][j][2]= grid->links[j];
487 } else { /* Inter cluster connection */
488 grid->connections[i][j]=(Link*)calloc(7, sizeof(Link));
490 nb_clusters = grid->hosts[grid->nb_hosts-1]->cluster+1;
493 grid->connections[i][j][0]= grid->links[i];
495 grid->connections[i][j][1]=
496 grid->links[grid->nb_hosts+grid->hosts[i]->cluster];
498 grid->connections[i][j][2]=
499 grid->links[grid->nb_hosts+grid->hosts[i]->cluster+nb_clusters];
501 grid->connections[i][j][3]=
502 grid->links[grid->nb_links-1];
504 grid->connections[i][j][4]=
505 grid->links[grid->nb_hosts+grid->hosts[j]->cluster+nb_clusters];
507 grid->connections[i][j][5]=
508 grid->links[grid->nb_hosts+grid->hosts[j]->cluster];
510 grid->connections[i][j][6]= grid->links[j];