3 #include "simdag/simdag.h"
7 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
8 "Logging specific to this SimDag example");
10 int main(int argc, char **argv)
13 const char *platform_file;
14 const SD_workstation_t *workstations;
17 double computation_amount1;
18 double computation_amount2;
19 double communication_amount12;
20 double communication_amount21;
21 const SD_link_t *route;
23 SD_task_t task, taskA, taskB, taskC, taskD;
24 SD_task_t *changed_tasks;
26 const int workstation_number = 2;
27 SD_workstation_t workstation_list[2];
28 double computation_amount[2];
29 double communication_amount[4] = { 0 };
31 SD_workstation_t w1, w2;
33 /* initialisation of SD */
36 /* xbt_log_control_set("sd.thres=debug"); */
39 INFO1("Usage: %s platform_file", argv[0]);
40 INFO1("example: %s sd_platform.xml", argv[0]);
44 /* creation of the environment */
45 platform_file = argv[1];
46 SD_create_environment(platform_file);
48 /* test the estimation functions */
49 workstations = SD_workstation_get_list();
52 SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
53 name1 = SD_workstation_get_name(w1);
54 name2 = SD_workstation_get_name(w2);
55 computation_amount1 = 2000000;
56 computation_amount2 = 1000000;
57 communication_amount12 = 2000000;
58 communication_amount21 = 3000000;
59 INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
60 SD_workstation_get_computation_time(w1, computation_amount1));
61 INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
62 SD_workstation_get_computation_time(w2, computation_amount2));
64 INFO2("Route between %s and %s:", name1, name2);
65 route = SD_route_get_list(w1, w2);
66 route_size = SD_route_get_size(w1, w2);
67 for (i = 0; i < route_size; i++) {
68 INFO3(" Link %s: latency = %f, bandwidth = %f",
69 SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]),
70 SD_link_get_current_bandwidth(route[i]));
72 INFO2("Route latency = %f, route bandwidth = %f",
73 SD_route_get_current_latency(w1, w2),
74 SD_route_get_current_bandwidth(w1, w2));
75 INFO4("Communication time for %f bytes between %s and %s: %f",
76 communication_amount12, name1, name2,
77 SD_route_get_communication_time(w1, w2, communication_amount12));
78 INFO4("Communication time for %f bytes between %s and %s: %f",
79 communication_amount21, name2, name1,
80 SD_route_get_communication_time(w2, w1, communication_amount21));
82 /* creation of the tasks and their dependencies */
83 taskA = SD_task_create("Task A", NULL, 10.0);
84 taskB = SD_task_create("Task B", NULL, 40.0);
85 taskC = SD_task_create("Task C", NULL, 30.0);
86 taskD = SD_task_create("Task D", NULL, 60.0);
89 SD_task_dependency_add(NULL, NULL, taskB, taskA);
90 SD_task_dependency_add(NULL, NULL, taskC, taskA);
91 SD_task_dependency_add(NULL, NULL, taskD, taskB);
92 SD_task_dependency_add(NULL, NULL, taskD, taskC);
93 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
98 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
99 xbt_die("Hey, I can add a dependency between Task A and Task A!");
102 if (ex.category != arg_error)
103 RETHROW; /* this is a serious error */
108 SD_task_dependency_add(NULL, NULL, taskB, taskA); /* shouldn't work and must raise an exception */
109 xbt_die("Oh oh, I can add an already existing dependency!");
112 if (ex.category != arg_error)
118 SD_task_dependency_remove(taskA, taskC); /* shouldn't work and must raise an exception */
119 xbt_die("Dude, I can remove an unknown dependency!");
122 if (ex.category != arg_error)
128 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
129 xbt_die("Wow, I can remove a dependency between Task C and itself!");
132 if (ex.category != arg_error)
138 /* if everything is ok, no exception is forwarded or rethrown by main() */
141 SD_task_watch(taskD, SD_DONE);
142 SD_task_watch(taskB, SD_DONE);
143 SD_task_unwatch(taskD, SD_DONE);
146 /* scheduling parameters */
147 workstation_list[0] = w1;
148 workstation_list[1] = w2;
149 computation_amount[0] = computation_amount1;
150 computation_amount[1] = computation_amount2;
152 communication_amount[1] = communication_amount12;
153 communication_amount[2] = communication_amount21;
157 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
158 SD_task_get_execution_time(task, workstation_number, workstation_list,
159 computation_amount, communication_amount,
162 /* let's launch the simulation! */
164 SD_task_schedule(taskA, workstation_number, workstation_list,
165 computation_amount, communication_amount, rate);
166 SD_task_schedule(taskB, workstation_number, workstation_list,
167 computation_amount, communication_amount, rate);
168 SD_task_schedule(taskC, workstation_number, workstation_list,
169 computation_amount, communication_amount, rate);
170 SD_task_schedule(taskD, workstation_number, workstation_list,
171 computation_amount, communication_amount, rate);
173 changed_tasks = SD_simulate(-1.0);
174 for (i = 0; changed_tasks[i] != NULL; i++) {
175 INFO3("Task '%s' start time: %f, finish time: %f",
176 SD_task_get_name(changed_tasks[i]),
177 SD_task_get_start_time(changed_tasks[i]),
178 SD_task_get_finish_time(changed_tasks[i]));
181 xbt_assert0(changed_tasks[0] == taskD &&
182 changed_tasks[1] == taskB &&
183 changed_tasks[2] == NULL, "Unexpected simulation results");
185 xbt_free(changed_tasks);
187 DEBUG0("Destroying tasks...");
189 SD_task_destroy(taskA);
190 SD_task_destroy(taskB);
191 SD_task_destroy(taskC);
192 SD_task_destroy(taskD);
194 DEBUG0("Tasks destroyed. Exiting SimDag...");