Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove arg Rate.
[simgrid.git] / testsuite / simdag / sd_test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "simdag/simdag.h"
4 #include "xbt/ex.h"
5 #include "xbt/log.h"
6
7 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
8                              "Logging specific to this SimDag example");
9
10 int main(int argc, char **argv)
11 {
12   int i;
13   const char *platform_file;
14
15   const SD_workstation_t *workstations;
16   SD_workstation_t w1;
17   SD_workstation_t w2;
18   const char *name1;
19   const char *name2;
20   const double computation_amount1 = 2000000;
21   const double computation_amount2 = 1000000;
22   const double communication_amount12 = 2000000;
23   const double communication_amount21 = 3000000;
24   const SD_link_t *route;
25   int route_size;
26   SD_task_t taskA;
27   SD_task_t taskB;
28   SD_task_t taskC;
29   SD_task_t taskD;
30   xbt_ex_t ex;
31
32   /* initialisation of SD */
33   SD_init(&argc, argv);
34
35   if (argc < 2) {
36     INFO1("Usage: %s platform_file", argv[0]);
37     INFO1("example: %s sd_platform.xml", argv[0]);
38     exit(1);
39   }
40
41   /* creation of the environment */
42
43   platform_file = argv[1];
44
45   SD_create_environment(platform_file);
46
47   /* test the estimation functions (use small_platform.xml) */
48   workstations = SD_workstation_get_list();
49   w1 = workstations[0];
50   w2 = workstations[1];
51   name1 = SD_workstation_get_name(w1);
52   name2 = SD_workstation_get_name(w2);
53   route = SD_route_get_list(w1, w2);
54   route_size = SD_route_get_size(w1, w2);
55   taskA = SD_task_create("Task A", NULL, 10.0);
56   taskB = SD_task_create("Task B", NULL, 40.0);
57   taskC = SD_task_create("Task C", NULL, 30.0);
58   taskD = SD_task_create("Task D", NULL, 60.0);
59
60   INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
61         SD_workstation_get_computation_time(w1, computation_amount1));
62   INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
63         SD_workstation_get_computation_time(w2, computation_amount2));
64
65   INFO2("Route between %s and %s:", name1, name2);
66   for (i = 0; i < route_size; i++) {
67     INFO3("\tLink %s: latency = %f, bandwidth = %f",
68           SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]),
69           SD_link_get_current_bandwidth(route[i]));
70   }
71   INFO2("Route latency = %f, route bandwidth = %f",
72         SD_route_get_current_latency(w1, w2),
73         SD_route_get_current_bandwidth(w1, w2));
74   INFO4("Communication time for %f bytes between %s and %s: %f",
75         communication_amount12, name1, name2,
76         SD_route_get_communication_time(w1, w2, communication_amount12));
77   INFO4("Communication time for %f bytes between %s and %s: %f",
78         communication_amount21, name2, name1,
79         SD_route_get_communication_time(w2, w1, communication_amount21));
80
81   /* creation of the tasks and their dependencies */
82
83   SD_task_dependency_add(NULL, NULL, taskB, taskA);
84   SD_task_dependency_add(NULL, NULL, taskC, taskA);
85   SD_task_dependency_add(NULL, NULL, taskD, taskB);
86   SD_task_dependency_add(NULL, NULL, taskD, taskC);
87   /*  SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
88
89   TRY {
90     SD_task_dependency_add(NULL, NULL, taskA, taskA);   /* shouldn't work and must raise an exception */
91     xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
92   }
93   CATCH(ex) {
94   }
95
96   TRY {
97     SD_task_dependency_add(NULL, NULL, taskA, taskB);   /* shouldn't work and must raise an exception */
98     xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
99   }
100   CATCH(ex) {
101   }
102
103   SD_task_dependency_remove(taskA, taskB);
104
105   TRY {
106     SD_task_dependency_remove(taskC, taskA);    /* shouldn't work and must raise an exception */
107     xbt_assert0(0, "Dude, I can remove an unknown dependency!");
108   }
109   CATCH(ex) {
110   }
111
112   TRY {
113     SD_task_dependency_remove(taskC, taskC);    /* shouldn't work and must raise an exception */
114     xbt_assert0(0,
115                 "Wow, I can remove a dependency between Task C and itself!");
116   }
117   CATCH(ex) {
118   }
119
120
121   /* if everything is ok, no exception is forwarded or rethrown by main() */
122
123   /* watch points */
124   SD_task_watch(taskD, SD_DONE);
125   SD_task_watch(taskB, SD_DONE);
126   SD_task_unwatch(taskD, SD_DONE);
127
128
129   /* scheduling parameters */
130   {
131     const int workstation_number = 2;
132     const SD_workstation_t workstation_list[] = { w1, w2 };
133     double computation_amount[] =
134       { computation_amount1, computation_amount2 };
135     double communication_amount[] = {
136       0, communication_amount12,
137       communication_amount21, 0
138     };
139     SD_task_t *changed_tasks;
140     double rate = -1.0;
141
142     /* estimated time */
143     SD_task_t task = taskD;
144     INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
145           SD_task_get_execution_time(task, workstation_number,
146                                      workstation_list, computation_amount,
147                                      communication_amount));
148
149     /* let's launch the simulation! */
150
151     SD_task_schedule(taskA, workstation_number, workstation_list,
152                      computation_amount, communication_amount, rate);
153     SD_task_schedule(taskB, workstation_number, workstation_list,
154                      computation_amount, communication_amount, rate);
155     SD_task_schedule(taskC, workstation_number, workstation_list,
156                      computation_amount, communication_amount, rate);
157     SD_task_schedule(taskD, workstation_number, workstation_list,
158                      computation_amount, communication_amount, rate);
159
160     changed_tasks = SD_simulate(-1.0);
161     xbt_assert0(changed_tasks[0] == taskD &&
162                 changed_tasks[1] == taskC &&
163                 changed_tasks[2] == taskB &&
164                 changed_tasks[3] == NULL, "Unexpected simulation results");
165
166     xbt_free(changed_tasks);
167   }
168   DEBUG0("Destroying tasks...");
169
170   SD_task_destroy(taskA);
171   SD_task_destroy(taskB);
172   SD_task_destroy(taskC);
173   SD_task_destroy(taskD);
174
175   DEBUG0("Tasks destroyed. Exiting SimDag...");
176
177   SD_exit();
178   return 0;
179 }