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;
15 const SD_workstation_t *workstations;
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;
32 /* initialisation of SD */
36 INFO1("Usage: %s platform_file", argv[0]);
37 INFO1("example: %s sd_platform.xml", argv[0]);
41 /* creation of the environment */
43 platform_file = argv[1];
45 SD_create_environment(platform_file);
47 /* test the estimation functions (use small_platform.xml) */
48 workstations = SD_workstation_get_list();
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);
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));
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]));
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));
81 /* creation of the tasks and their dependencies */
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 */
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!");
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!");
103 SD_task_dependency_remove(taskA, taskB);
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!");
113 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
115 "Wow, I can remove a dependency between Task C and itself!");
121 /* if everything is ok, no exception is forwarded or rethrown by main() */
124 SD_task_watch(taskD, SD_DONE);
125 SD_task_watch(taskB, SD_DONE);
126 SD_task_unwatch(taskD, SD_DONE);
129 /* scheduling parameters */
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
139 SD_task_t *changed_tasks;
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, rate));
149 /* let's launch the simulation! */
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);
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");
166 xbt_free(changed_tasks);
168 DEBUG0("Destroying tasks...");
170 SD_task_destroy(taskA);
171 SD_task_destroy(taskB);
172 SD_task_destroy(taskC);
173 SD_task_destroy(taskD);
175 DEBUG0("Tasks destroyed. Exiting SimDag...");