Logo AND Algorithmique Numérique Distribuée

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