Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
20230dfb2bffdb28d9b4d8dddf135d0dd928cf3c
[simgrid.git] / examples / simdag / mixtesim / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <time.h>
5 #include <string.h>
6
7 #include "mixtesim_prototypes.h"
8 #include "list_scheduling.h"
9
10 #include "simdag/simdag.h"
11 #include "xbt/log.h"
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(mixtesim,
14                              "Logging specific to this SimDag example");
15
16 /* static int createSimgridResources(); */
17 static int createSimgridTasks();
18
19 DAG dag;
20 /*extern Link local_link;*/
21
22 int main(int argc, char **argv) {
23  
24   char *platform_file;
25   SD_task_t *changed_tasks;
26   int i;
27
28 /*   xbt_log_control_set("sd.thres=debug"); */
29 /*   xbt_log_control_set("sd_kernel.thres=debug"); */
30 /*   xbt_log_control_set("surf_kernel.thres=debug"); */
31 /*   xbt_log_control_set("mixtesim.thres=debug"); */
32
33   
34   if (argc < 1) {
35      printf("Usage: %s xml_platform_file dagfile ", argv[0]);
36      printf("example: %s gridfile.xml dagfile", argv[0]);
37      exit(1);
38   }
39
40   /* initialisation of SD */
41   SD_init(&argc, argv);
42
43   /* creation of the environment */
44   platform_file = argv[1];
45   SD_create_environment(platform_file);
46
47   /*Parse DAG file */
48   dag = parseDAGFile(argv[2]); 
49
50
51   allocateNodeAttributes(dag);
52   allocateHostAttributes();
53
54   /* create Simgrid objects */
55   createSimgridObjects();
56   
57   HEFT(dag);
58   
59   /* not recommanded with big DAGs! */
60   /* printDAG(dag); */
61
62   changed_tasks = SD_simulate(-1.0);
63   INFO0("Tasks whose state has changed:");
64   i = 0;
65   while(changed_tasks[i] != NULL) {
66     switch (SD_task_get_state(changed_tasks[i])) {
67     case SD_SCHEDULED:
68       INFO1("%s is scheduled.", SD_task_get_name(changed_tasks[i]));
69       break;
70     case SD_READY:
71       INFO1("%s is ready.", SD_task_get_name(changed_tasks[i]));
72       break;
73     case SD_RUNNING:
74       INFO1("%s is running.", SD_task_get_name(changed_tasks[i]));
75       break;
76     case SD_DONE:
77       INFO1("%s is done.", SD_task_get_name(changed_tasks[i]));
78       break;
79     case SD_FAILED:
80       INFO1("%s is failed.", SD_task_get_name(changed_tasks[i]));
81       break;
82     default:
83       INFO1("Unknown status for %s", SD_task_get_name(changed_tasks[i]));
84       break;
85       }
86     i++;
87   }
88   free(changed_tasks);
89   INFO1("Total: %d", i);
90
91   /* clear some memory */
92   freeNodeAttributes(dag);
93   freeHostAttributes();
94   
95   /* reset SimDag */
96   SD_exit();
97
98   return 0;
99 }
100
101 /*
102  * createSimgridObjects()
103  */
104 int createSimgridObjects()
105 {
106   /* Create resources */
107 /*   if (createSimgridResources() == -1) */
108 /*     return -1; */
109
110   /* Create tasks */
111   if (createSimgridTasks() == -1)
112     return -1;
113
114   return 0;
115 }
116
117 /*
118  * createSimgridResources()
119  */
120 /* static int createSimgridResources() */
121 /* { */
122 /*   int i,j; */
123 /*   char buffer[32]; */
124 /*   SG_Resource *sg_TCPlinks; */
125 /*   SG_Resource fast_link; */
126   
127 /*   /\* The almost infinetely fast TCP link *\/  */
128 /*   fast_link = SG_newTCPLink("infinetly_fast_TCPlink",  */
129 /*                          NULL, */
130 /*                          0.0, EPSILON, NULL,  */
131 /*                          0.0, 1000.0, */
132 /*                          SG_TCP_SHARED,NULL); */
133
134 /*   sg_TCPlinks = (SG_Resource*) calloc (2, sizeof(SG_Resource)); */
135 /*   sg_TCPlinks[0] = fast_link; */
136 /*   sg_TCPlinks[1] = NULL; */
137
138 /*   /\* And the almost infinetely fast TCP route *\/  */
139 /*   local_link = newLink(); */
140 /*   local_link->sg_link =  */
141 /*     SG_newTCPRoute ("infinitely_fast_route", sg_TCPlinks, NULL);  */
142 /*   free(sg_TCPlinks); */
143
144 /*   /\* Create hosts *\/ */
145 /*   for (i=0;i<grid->nb_hosts;i++) { */
146 /*     if (createSimgridHost(grid->hosts[i]) == -1) */
147 /*       return -1; */
148 /*   } */
149   
150 /*   /\* Create TCP links *\/ */
151 /*   for (i=0;i<grid->nb_links;i++) { */
152 /*     if (createSimgridLink(grid->links[i]) == -1) */
153 /*       return -1; */
154 /*   } */
155
156 /*   /\* Create TCP routes *\/ */
157 /*   grid->routes=(SG_Resource**)calloc(grid->nb_hosts,sizeof(SG_Resource*)); */
158
159 /*   for (i=0;i<grid->nb_hosts;i++) { */
160 /*     grid->routes[i]=(SG_Resource *)calloc(grid->nb_hosts,sizeof(SG_Resource)); */
161 /*     for (j=0;j<grid->nb_hosts;j++) { */
162 /*       sprintf(buffer,"route#%d-%d",i,j); */
163 /*       if (i!=j) { */
164 /*      if (grid->hosts[i]->cluster == grid->hosts[j]->cluster) { */
165 /*        /\* Intra cluster route *\/ */
166 /*        /\* src - switch - dest*\/ */
167 /*        sg_TCPlinks = (SG_Resource*) calloc (4, sizeof(SG_Resource)); */
168 /*        sg_TCPlinks[0] = grid->connections[i][j][0]->sg_link; */
169 /*        sg_TCPlinks[1] = grid->connections[i][j][1]->sg_link; */
170 /*        sg_TCPlinks[2] = grid->connections[i][j][2]->sg_link; */
171 /*        sg_TCPlinks[3] = NULL; */
172 /*      } else { */
173 /*        /\* Inter cluster route *\/ */
174 /*        /\* src - switch - gateway - backbone - gateway - switch - dest*\/ */
175 /*        sg_TCPlinks = (SG_Resource*) calloc (8, sizeof(SG_Resource)); */
176 /*        sg_TCPlinks[0] = grid->connections[i][j][0]->sg_link; */
177 /*        sg_TCPlinks[1] = grid->connections[i][j][1]->sg_link; */
178 /*        sg_TCPlinks[2] = grid->connections[i][j][2]->sg_link; */
179 /*        sg_TCPlinks[3] = grid->connections[i][j][3]->sg_link; */
180 /*        sg_TCPlinks[4] = grid->connections[i][j][4]->sg_link; */
181 /*        sg_TCPlinks[5] = grid->connections[i][j][5]->sg_link; */
182 /*        sg_TCPlinks[6] = grid->connections[i][j][6]->sg_link; */
183 /*        sg_TCPlinks[7] = NULL; */
184 /*      } */
185 /*      grid->routes[i][j] = SG_newTCPRoute (buffer, sg_TCPlinks, NULL);  */
186 /*      free(sg_TCPlinks); */
187 /*       } else { */
188 /*      /\*Self communication => no route *\/ */
189 /*      grid->routes[i][j] = NULL; */
190 /*       } */
191 /*     } */
192 /*   } */
193 /*   return 0; */
194 /* } */
195
196 /* static int createSimgridHost(Host h) */
197 /* { */
198 /*   char buffer[32]; */
199 /*   char *filename; */
200 /*   double offset; */
201 /*   double value; */
202
203 /*   sprintf(buffer,"host#%d",h->global_index); */
204
205 /*   if (parseTraceSpec(h->cpu_trace,&filename,&offset,&value) == -1) { */
206 /*     fprintf(stderr,"Syntax error: host#%d\n",h->global_index); */
207 /*     return -1; */
208 /*   } */
209           
210 /*   h->sg_host = SG_newHost(buffer,h->rel_speed,  */
211 /*                        h->mode, filename,offset,value, */
212 /*                        NULL, NULL, 0, h); */
213 /*   free(filename); */
214
215 /*   return 0; */
216 /* } */
217
218 /* /\* */
219 /*  * createSimgridLink() */
220 /*  * */
221 /*  *\/ */
222 /* static int createSimgridLink(Link l) */
223 /* { */
224 /*   char buffer[32]; */
225 /*   char *filename1,*filename2; */
226 /*   double offset1,offset2; */
227 /*   double value1,value2; */
228
229 /*   sprintf(buffer,"link#%d",l->global_index); */
230
231 /*   if ((parseTraceSpec(l->latency_trace,&filename1,&offset1,&value1) == -1) || */
232 /*       (parseTraceSpec(l->bandwidth_trace,&filename2,&offset2,&value2) == -1)) { */
233 /*     fprintf(stderr,"Syntax error: link#%d\n",l->global_index); */
234 /*     return -1; */
235 /*   } */
236
237
238 /*   if (l->mode == SG_TIME_SLICED) { */
239 /*     l->sg_link=SG_newTCPLink (buffer, */
240 /*                            filename1, offset1, value1, */
241 /*                            filename2, offset2, value2, */
242 /*                            SG_TCP_SHARED,NULL); */
243 /*   } */
244
245 /*   if (l->mode == SG_FAT_PIPE) { */
246 /*     l->sg_link=SG_newTCPLink (buffer, */
247 /*                            filename1, offset1, value1, */
248 /*                            filename2, offset2, value2, */
249 /*                            SG_TCP_BACKBONE,NULL); */
250 /*   } */
251
252 /*   free(filename1); */
253 /*   free(filename2); */
254
255 /*   return 0; */
256 /* } */
257
258 /*
259  * createSimgridTasks()
260  *
261  */
262 static int createSimgridTasks()
263 {
264   Node node;
265   char buffer[32];
266   int i,j;
267
268   /* Creating the tasks */
269   for (i=0;i<dag->nb_nodes;i++) {
270     node = dag->nodes[i];
271     sprintf(buffer,"node#%d",node->global_index);
272     node->sd_task = SD_task_create(buffer, node, 1.0);
273   }
274
275   /* Set the dependencies */
276   for (i=0;i<dag->nb_nodes;i++) {
277     node = dag->nodes[i];
278     for (j=0;j<node->nb_parents;j++) {
279       SD_task_dependency_add(NULL, NULL, node->parents[j]->sd_task, node->sd_task);
280     }
281   }
282   return 0;
283 }
284
285
286 /*
287  * parseTraceSpec()
288  */
289 /* static int parseTraceSpec(char* spec,char**filename, */
290 /*              double *offset, double *value) */
291 /* { */
292 /*   char *tmp; */
293
294 /*   tmp = strchr(spec,':'); */
295 /*   if (!tmp) { */
296 /*     fprintf(stderr,"Parse error: missing ':' in trace specification\n"); */
297 /*     return -1; */
298 /*   } */
299
300 /*   *filename=NULL; */
301 /*   *offset=0.0; */
302 /*   *value=0.0; */
303   
304 /*   if (tmp == spec) { /\* FIXED *\/ */
305 /*     if (!*(tmp+1)) { */
306 /*       fprintf(stderr,"Parse error: invalid value specification\n"); */
307 /*       return -1; */
308 /*     } */
309 /*     *value = atof(tmp+1); */
310 /*     if (*value < 0.0) { */
311 /*       fprintf(stderr,"Error: invalid value\n"); */
312 /*       return -1; */
313 /*     } */
314 /*     return 0; */
315 /*   } */
316
317 /*   /\* TRACE *\/ */
318 /*   *tmp='\0'; */
319 /*   *filename=strdup(spec); */
320 /*   if (!*(tmp+1)) { */
321 /*     fprintf(stderr,"Parse error: invalid offset specification\n"); */
322 /*     return -1; */
323 /*   } */
324 /*   *offset = atof(tmp+1); */
325 /*   if (*offset < 0.0) { */
326 /*     fprintf(stderr,"Error: invalid offset\n"); */
327 /*     return -1; */
328 /*   } */
329
330 /*   return 0; */
331 /* } */