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) {
12 const char* platform_file;
14 const SD_workstation_t *workstations;
19 const double computation_amount1 = 2000000;
20 const double computation_amount2 = 1000000;
21 const double communication_amount12 = 2000000;
22 const double communication_amount21 = 3000000;
23 const SD_link_t *route;
31 /* initialisation of SD */
35 INFO1("Usage: %s platform_file", argv[0]);
36 INFO1("example: %s sd_platform.xml", argv[0]);
40 /* creation of the environment */
42 platform_file = argv[1];
44 SD_create_environment(platform_file);
46 /* test the estimation functions (use small_platform.xml) */
47 workstations = SD_workstation_get_list();
50 name1 = SD_workstation_get_name(w1);
51 name2 = SD_workstation_get_name(w2);
52 route = SD_route_get_list(w1, w2);
53 route_size = SD_route_get_size(w1, w2);
54 taskA = SD_task_create("Task A", NULL, 10.0);
55 taskB = SD_task_create("Task B", NULL, 40.0);
56 taskC = SD_task_create("Task C", NULL, 30.0);
57 taskD = SD_task_create("Task D", NULL, 60.0);
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 for (i = 0; i < route_size; i++) {
66 INFO3("\tLink %s: latency = %f, bandwidth = %f", SD_link_get_name(route[i]),
67 SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i]));
69 INFO2("Route latency = %f, route bandwidth = %f", SD_route_get_current_latency(w1, w2),
70 SD_route_get_current_bandwidth(w1, w2));
71 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount12, name1, name2,
72 SD_route_get_communication_time(w1, w2, communication_amount12));
73 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount21, name2, name1,
74 SD_route_get_communication_time(w2, w1, communication_amount21));
76 /* creation of the tasks and their dependencies */
78 SD_task_dependency_add(NULL, NULL, taskB, taskA);
79 SD_task_dependency_add(NULL, NULL, taskC, taskA);
80 SD_task_dependency_add(NULL, NULL, taskD, taskB);
81 SD_task_dependency_add(NULL, NULL, taskD, taskC);
82 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
85 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
86 xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
92 SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
93 xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
98 SD_task_dependency_remove(taskA, taskB);
101 SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
102 xbt_assert0(0, "Dude, I can remove an unknown dependency!");
108 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
109 xbt_assert0(0, "Wow, I can remove a dependency between Task C and itself!");
115 /* if everything is ok, no exception is forwarded or rethrown by main() */
118 SD_task_watch(taskD, SD_DONE);
119 SD_task_watch(taskB, SD_DONE);
120 SD_task_unwatch(taskD, SD_DONE);
123 /* scheduling parameters */
125 const int workstation_number = 2;
126 const SD_workstation_t workstation_list[] = {w1, w2};
127 double computation_amount[] = {computation_amount1, computation_amount2};
128 double communication_amount[] =
130 0, communication_amount12,
131 communication_amount21, 0
133 SD_task_t *changed_tasks;
137 SD_task_t task = taskD;
138 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
139 SD_task_get_execution_time(task, workstation_number, workstation_list,
140 computation_amount, communication_amount, rate));
142 /* let's launch the simulation! */
144 SD_task_schedule(taskA, workstation_number, workstation_list,
145 computation_amount, communication_amount, rate);
146 SD_task_schedule(taskB, workstation_number, workstation_list,
147 computation_amount, communication_amount, rate);
148 SD_task_schedule(taskC, workstation_number, workstation_list,
149 computation_amount, communication_amount, rate);
150 SD_task_schedule(taskD, workstation_number, workstation_list,
151 computation_amount, communication_amount, rate);
153 changed_tasks = SD_simulate(-1.0);
154 xbt_assert0(changed_tasks[0] == taskD &&
155 changed_tasks[1] == taskB &&
156 changed_tasks[2] == taskC &&
157 changed_tasks[3] == NULL,
158 "Unexpected simulation results");
160 xbt_free(changed_tasks);
162 DEBUG0("Destroying tasks...");
164 SD_task_destroy(taskA);
165 SD_task_destroy(taskB);
166 SD_task_destroy(taskC);
167 SD_task_destroy(taskD);
169 DEBUG0("Tasks destroyed. Exiting SimDag...");