Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a SimDag example (mixtesim) created from an old SG 2.18 example
[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   printDAG(dag);
60
61   changed_tasks = SD_simulate(-1.0);
62
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
90   /* clear some memory */
91   freeNodeAttributes(dag);
92   freeHostAttributes();
93   
94   /* reset SimDag */
95   SD_exit();
96
97   return 0;
98 }
99
100 /*
101  * createSimgridObjects()
102  */
103 int createSimgridObjects()
104 {
105   /* Create resources */
106 /*   if (createSimgridResources() == -1) */
107 /*     return -1; */
108
109   /* Create tasks */
110   if (createSimgridTasks() == -1)
111     return -1;
112
113   return 0;
114 }
115
116 /*
117  * createSimgridResources()
118  */
119 /* static int createSimgridResources() */
120 /* { */
121 /*   int i,j; */
122 /*   char buffer[32]; */
123 /*   SG_Resource *sg_TCPlinks; */
124 /*   SG_Resource fast_link; */
125   
126 /*   /\* The almost infinetely fast TCP link *\/  */
127 /*   fast_link = SG_newTCPLink("infinetly_fast_TCPlink",  */
128 /*                          NULL, */
129 /*                          0.0, EPSILON, NULL,  */
130 /*                          0.0, 1000.0, */
131 /*                          SG_TCP_SHARED,NULL); */
132
133 /*   sg_TCPlinks = (SG_Resource*) calloc (2, sizeof(SG_Resource)); */
134 /*   sg_TCPlinks[0] = fast_link; */
135 /*   sg_TCPlinks[1] = NULL; */
136
137 /*   /\* And the almost infinetely fast TCP route *\/  */
138 /*   local_link = newLink(); */
139 /*   local_link->sg_link =  */
140 /*     SG_newTCPRoute ("infinitely_fast_route", sg_TCPlinks, NULL);  */
141 /*   free(sg_TCPlinks); */
142
143 /*   /\* Create hosts *\/ */
144 /*   for (i=0;i<grid->nb_hosts;i++) { */
145 /*     if (createSimgridHost(grid->hosts[i]) == -1) */
146 /*       return -1; */
147 /*   } */
148   
149 /*   /\* Create TCP links *\/ */
150 /*   for (i=0;i<grid->nb_links;i++) { */
151 /*     if (createSimgridLink(grid->links[i]) == -1) */
152 /*       return -1; */
153 /*   } */
154
155 /*   /\* Create TCP routes *\/ */
156 /*   grid->routes=(SG_Resource**)calloc(grid->nb_hosts,sizeof(SG_Resource*)); */
157
158 /*   for (i=0;i<grid->nb_hosts;i++) { */
159 /*     grid->routes[i]=(SG_Resource *)calloc(grid->nb_hosts,sizeof(SG_Resource)); */
160 /*     for (j=0;j<grid->nb_hosts;j++) { */
161 /*       sprintf(buffer,"route#%d-%d",i,j); */
162 /*       if (i!=j) { */
163 /*      if (grid->hosts[i]->cluster == grid->hosts[j]->cluster) { */
164 /*        /\* Intra cluster route *\/ */
165 /*        /\* src - switch - dest*\/ */
166 /*        sg_TCPlinks = (SG_Resource*) calloc (4, sizeof(SG_Resource)); */
167 /*        sg_TCPlinks[0] = grid->connections[i][j][0]->sg_link; */
168 /*        sg_TCPlinks[1] = grid->connections[i][j][1]->sg_link; */
169 /*        sg_TCPlinks[2] = grid->connections[i][j][2]->sg_link; */
170 /*        sg_TCPlinks[3] = NULL; */
171 /*      } else { */
172 /*        /\* Inter cluster route *\/ */
173 /*        /\* src - switch - gateway - backbone - gateway - switch - dest*\/ */
174 /*        sg_TCPlinks = (SG_Resource*) calloc (8, sizeof(SG_Resource)); */
175 /*        sg_TCPlinks[0] = grid->connections[i][j][0]->sg_link; */
176 /*        sg_TCPlinks[1] = grid->connections[i][j][1]->sg_link; */
177 /*        sg_TCPlinks[2] = grid->connections[i][j][2]->sg_link; */
178 /*        sg_TCPlinks[3] = grid->connections[i][j][3]->sg_link; */
179 /*        sg_TCPlinks[4] = grid->connections[i][j][4]->sg_link; */
180 /*        sg_TCPlinks[5] = grid->connections[i][j][5]->sg_link; */
181 /*        sg_TCPlinks[6] = grid->connections[i][j][6]->sg_link; */
182 /*        sg_TCPlinks[7] = NULL; */
183 /*      } */
184 /*      grid->routes[i][j] = SG_newTCPRoute (buffer, sg_TCPlinks, NULL);  */
185 /*      free(sg_TCPlinks); */
186 /*       } else { */
187 /*      /\*Self communication => no route *\/ */
188 /*      grid->routes[i][j] = NULL; */
189 /*       } */
190 /*     } */
191 /*   } */
192 /*   return 0; */
193 /* } */
194
195 /* static int createSimgridHost(Host h) */
196 /* { */
197 /*   char buffer[32]; */
198 /*   char *filename; */
199 /*   double offset; */
200 /*   double value; */
201
202 /*   sprintf(buffer,"host#%d",h->global_index); */
203
204 /*   if (parseTraceSpec(h->cpu_trace,&filename,&offset,&value) == -1) { */
205 /*     fprintf(stderr,"Syntax error: host#%d\n",h->global_index); */
206 /*     return -1; */
207 /*   } */
208           
209 /*   h->sg_host = SG_newHost(buffer,h->rel_speed,  */
210 /*                        h->mode, filename,offset,value, */
211 /*                        NULL, NULL, 0, h); */
212 /*   free(filename); */
213
214 /*   return 0; */
215 /* } */
216
217 /* /\* */
218 /*  * createSimgridLink() */
219 /*  * */
220 /*  *\/ */
221 /* static int createSimgridLink(Link l) */
222 /* { */
223 /*   char buffer[32]; */
224 /*   char *filename1,*filename2; */
225 /*   double offset1,offset2; */
226 /*   double value1,value2; */
227
228 /*   sprintf(buffer,"link#%d",l->global_index); */
229
230 /*   if ((parseTraceSpec(l->latency_trace,&filename1,&offset1,&value1) == -1) || */
231 /*       (parseTraceSpec(l->bandwidth_trace,&filename2,&offset2,&value2) == -1)) { */
232 /*     fprintf(stderr,"Syntax error: link#%d\n",l->global_index); */
233 /*     return -1; */
234 /*   } */
235
236
237 /*   if (l->mode == SG_TIME_SLICED) { */
238 /*     l->sg_link=SG_newTCPLink (buffer, */
239 /*                            filename1, offset1, value1, */
240 /*                            filename2, offset2, value2, */
241 /*                            SG_TCP_SHARED,NULL); */
242 /*   } */
243
244 /*   if (l->mode == SG_FAT_PIPE) { */
245 /*     l->sg_link=SG_newTCPLink (buffer, */
246 /*                            filename1, offset1, value1, */
247 /*                            filename2, offset2, value2, */
248 /*                            SG_TCP_BACKBONE,NULL); */
249 /*   } */
250
251 /*   free(filename1); */
252 /*   free(filename2); */
253
254 /*   return 0; */
255 /* } */
256
257 /*
258  * createSimgridTasks()
259  *
260  */
261 static int createSimgridTasks()
262 {
263   Node node;
264   char buffer[32];
265   int i,j;
266
267   /* Creating the tasks */
268   for (i=0;i<dag->nb_nodes;i++) {
269     node = dag->nodes[i];
270     sprintf(buffer,"node#%d",node->global_index);
271     node->sd_task = SD_task_create(buffer, node, 1.0);
272   }
273
274   /* Set the dependencies */
275   for (i=0;i<dag->nb_nodes;i++) {
276     node = dag->nodes[i];
277     for (j=0;j<node->nb_parents;j++) {
278       SD_task_dependency_add(NULL, NULL, node->parents[j]->sd_task, node->sd_task);
279     }
280   }
281   return 0;
282 }
283
284
285 /*
286  * parseTraceSpec()
287  */
288 /* static int parseTraceSpec(char* spec,char**filename, */
289 /*              double *offset, double *value) */
290 /* { */
291 /*   char *tmp; */
292
293 /*   tmp = strchr(spec,':'); */
294 /*   if (!tmp) { */
295 /*     fprintf(stderr,"Parse error: missing ':' in trace specification\n"); */
296 /*     return -1; */
297 /*   } */
298
299 /*   *filename=NULL; */
300 /*   *offset=0.0; */
301 /*   *value=0.0; */
302   
303 /*   if (tmp == spec) { /\* FIXED *\/ */
304 /*     if (!*(tmp+1)) { */
305 /*       fprintf(stderr,"Parse error: invalid value specification\n"); */
306 /*       return -1; */
307 /*     } */
308 /*     *value = atof(tmp+1); */
309 /*     if (*value < 0.0) { */
310 /*       fprintf(stderr,"Error: invalid value\n"); */
311 /*       return -1; */
312 /*     } */
313 /*     return 0; */
314 /*   } */
315
316 /*   /\* TRACE *\/ */
317 /*   *tmp='\0'; */
318 /*   *filename=strdup(spec); */
319 /*   if (!*(tmp+1)) { */
320 /*     fprintf(stderr,"Parse error: invalid offset specification\n"); */
321 /*     return -1; */
322 /*   } */
323 /*   *offset = atof(tmp+1); */
324 /*   if (*offset < 0.0) { */
325 /*     fprintf(stderr,"Error: invalid offset\n"); */
326 /*     return -1; */
327 /*   } */
328
329 /*   return 0; */
330 /* } */