Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
write the produced trace into an external file; schedule on every machine provided
[simgrid.git] / examples / simdag / dax / dax_test.c
1 /* simple test trying to load a DAX file.                                   */
2
3 /* Copyright (c) 2009 Da SimGrid Team. All rights reserved.                 */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include "simdag/simdag.h"
11 #include "xbt/log.h"
12 #include "xbt/ex.h"
13 #include <string.h>
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
16                              "Logging specific to this SimDag example");
17
18
19 int main(int argc, char **argv) {
20   xbt_dynar_t dax;
21   unsigned int cursor;
22   SD_task_t task;
23
24   /* initialisation of SD */
25   SD_init(&argc, argv);
26
27   /* Check our arguments */
28   if (argc < 3) {
29     INFO1("Usage: %s platform_file dax_file", argv[0]);
30     INFO1("example: %s ../sd_platform.xml Montage_50.xml", argv[0]);
31     exit(1);
32   }
33
34   /* creation of the environment */
35   SD_create_environment(argv[1]);
36
37   /* load the DAX file */
38   dax=SD_daxload(argv[2]);
39
40   /* Display all the tasks */
41   INFO0("------------------- Display all tasks of the loaded DAG ---------------------------");
42   xbt_dynar_foreach(dax,cursor,task) {
43     SD_task_dump(task);
44   }
45
46   FILE *dotout = fopen("dax.dot","w");
47   fprintf(dotout,"digraph A {\n");
48   xbt_dynar_foreach(dax,cursor,task) {
49     SD_task_dotty(task,dotout);
50   }
51   fprintf(dotout,"}\n");
52   fclose(dotout);
53
54   /* Schedule them all on the first workstation */
55   INFO0("------------------- Schedule tasks ---------------------------");
56   const SD_workstation_t *ws_list =  SD_workstation_get_list();
57   int count = SD_workstation_get_number();
58   xbt_dynar_foreach(dax,cursor,task) {
59     if (SD_task_get_kind(task) == SD_TASK_COMP_SEQ) {
60       if (!strcmp(SD_task_get_name(task),"end"))
61         SD_task_schedulel(task,1,ws_list[0]);
62       else
63         SD_task_schedulel(task,1,ws_list[cursor%count]);
64     }
65   }
66
67   INFO0("------------------- Run the schedule ---------------------------");
68   SD_simulate(-1);
69   INFO0("------------------- Produce the trace file---------------------------");
70   char *last=strrchr(argv[2],'.');
71
72   char *filename=bprintf("%.*s.trace",last==NULL?strlen(argv[2]):last-argv[2],argv[2]);
73   INFO1("Producing the trace of the run into %s",filename);
74   FILE*out = fopen(filename,"w");
75   xbt_assert1(out,"Cannot write to %s",filename);
76   free(filename);
77
78   xbt_dynar_foreach(dax,cursor,task) {
79     int kind = SD_task_get_kind(task);
80     SD_workstation_t *wsl = SD_task_get_workstation_list(task);
81     switch (kind) {
82     case SD_TASK_COMP_SEQ:
83       fprintf(out,"[%f] %s compute %f # %s\n",SD_task_get_start_time(task),
84           SD_workstation_get_name(wsl[0]),SD_task_get_amount(task),
85           SD_task_get_name(task));
86       break;
87     case SD_TASK_COMM_E2E:
88       fprintf(out,"[%f] %s send %s %f # %s\n",SD_task_get_start_time(task),
89           SD_workstation_get_name(wsl[0]),SD_workstation_get_name(wsl[1]),
90           SD_task_get_amount(task), SD_task_get_name(task));
91       fprintf(out,"[%f] %s recv %s %f # %s\n",SD_task_get_start_time(task),
92           SD_workstation_get_name(wsl[1]),SD_workstation_get_name(wsl[0]),
93           SD_task_get_amount(task), SD_task_get_name(task));
94       break;
95     default:
96       xbt_die(bprintf("Task %s is of unknown kind %d",SD_task_get_name(task),SD_task_get_kind(task)));
97     }
98   }
99   fclose(out);
100
101   /* exit */
102   SD_exit();
103   return 1;
104 }