3 #include "simdag/simdag.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
10 "Logging specific to this SimDag example");
12 int main(int argc, char **argv) {
15 /* initialisation of SD */
18 /* xbt_log_control_set("sd.thres=debug"); */
21 INFO1("Usage: %s platform_file", argv[0]);
22 INFO1("example: %s sd_platform.xml", argv[0]);
26 /* creation of the environment */
27 const char * platform_file = argv[1];
28 SD_create_environment(platform_file);
30 /* test the estimation functions */
31 const SD_workstation_t *workstations = SD_workstation_get_list();
32 SD_workstation_t w1 = workstations[0];
33 SD_workstation_t w2 = workstations[1];
34 SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
35 const char *name1 = SD_workstation_get_name(w1);
36 const char *name2 = SD_workstation_get_name(w2);
39 INFO1("Property list for workstation %s", name1);
40 /* Get the property list of the workstation 1 */
41 props = SD_workstation_get_properties(w1);
42 xbt_dict_cursor_t cursor = NULL;
45 /* Print the properties of the workstation 1 */
46 xbt_dict_foreach(props,cursor,key,data) {
47 INFO2("Property: %s has value: %s",key,data);
50 /* Try to get a property that does not exist */
51 char *noexist=xbt_strdup("Memory");
52 const char *value = SD_workstation_get_property_value(w1,noexist);
54 INFO1("Property: %s is undefined", noexist);
56 INFO2("Property: %s has value: %s", noexist, value);
58 INFO1("Property list for workstation %s", name2);
59 /* Get the property list of the workstation 2 */
60 props = SD_workstation_get_properties(w2);
63 /* Print the properties of the workstation 2 */
64 xbt_dict_foreach(props,cursor,key,data) {
65 INFO2("Property: %s on host: %s",key,data);
68 const double computation_amount1 = 2000000;
69 const double computation_amount2 = 1000000;
70 const double communication_amount12 = 2000000;
71 const double communication_amount21 = 3000000;
72 INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
73 SD_workstation_get_computation_time(w1, computation_amount1));
74 INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
75 SD_workstation_get_computation_time(w2, computation_amount2));
77 INFO2("Route between %s and %s:", name1, name2);
78 const SD_link_t *route = SD_route_get_list(w1, w2);
79 int route_size = SD_route_get_size(w1, w2);
80 for (i = 0; i < route_size; i++) {
81 INFO3("\tLink %s: latency = %f, bandwidth = %f", SD_link_get_name(route[i]),
82 SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i]));
84 props = SD_link_get_properties(route[i]);
85 xbt_dict_cursor_t cursor = NULL;
88 /* Print the properties of the current link */
89 xbt_dict_foreach(props,cursor,key,data) {
90 INFO3("Link %s property: %s has value: %s",SD_link_get_name(route[i]),key,data);
92 /* Try to get a property that does not exist */
93 noexist=xbt_strdup("Other");
94 value = SD_link_get_property_value(route[i], noexist);
96 INFO2("Property: %s for link %s is undefined", noexist, SD_link_get_name(route[i]));
98 INFO3("Link %s property: %s has value: %s",SD_link_get_name(route[i]),noexist,value);
102 INFO2("Route latency = %f, route bandwidth = %f", SD_route_get_current_latency(w1, w2),
103 SD_route_get_current_bandwidth(w1, w2));
104 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount12, name1, name2,
105 SD_route_get_communication_time(w1, w2, communication_amount12));
106 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount21, name2, name1,
107 SD_route_get_communication_time(w2, w1, communication_amount21));
109 /* creation of the tasks and their dependencies */
110 SD_task_t taskA = SD_task_create("Task A", NULL, 10.0);
111 SD_task_t taskB = SD_task_create("Task B", NULL, 40.0);
112 SD_task_t taskC = SD_task_create("Task C", NULL, 30.0);
113 SD_task_t taskD = SD_task_create("Task D", NULL, 60.0);
116 SD_task_dependency_add(NULL, NULL, taskB, taskA);
117 SD_task_dependency_add(NULL, NULL, taskC, taskA);
118 SD_task_dependency_add(NULL, NULL, taskD, taskB);
119 SD_task_dependency_add(NULL, NULL, taskD, taskC);
120 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
125 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
126 xbt_die("Hey, I can add a dependency between Task A and Task A!");
129 if (ex.category != arg_error)
131 RETHROW; /* this is a serious error */
136 SD_task_dependency_add(NULL, NULL, taskB, taskA); /* shouldn't work and must raise an exception */
137 xbt_die("Oh oh, I can add an already existing dependency!");
140 if (ex.category != arg_error)
146 SD_task_dependency_remove(taskA, taskC); /* shouldn't work and must raise an exception */
147 xbt_die("Dude, I can remove an unknown dependency!");
150 if (ex.category != arg_error)
156 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
157 xbt_die("Wow, I can remove a dependency between Task C and itself!");
160 if (ex.category != arg_error)
166 /* if everything is ok, no exception is forwarded or rethrown by main() */
169 SD_task_watch(taskD, SD_DONE);
170 SD_task_watch(taskB, SD_DONE);
171 SD_task_unwatch(taskD, SD_DONE);
174 /* scheduling parameters */
176 const int workstation_number = 2;
177 const SD_workstation_t workstation_list[] = {w1, w2};
178 double computation_amount[] = {computation_amount1, computation_amount2};
179 double communication_amount[] =
181 0, communication_amount12,
182 communication_amount21, 0
187 SD_task_t task = taskD;
188 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
189 SD_task_get_execution_time(task, workstation_number, workstation_list,
190 computation_amount, communication_amount, rate));
192 /* let's launch the simulation! */
194 SD_task_schedule(taskA, workstation_number, workstation_list,
195 computation_amount, communication_amount, rate);
196 SD_task_schedule(taskB, workstation_number, workstation_list,
197 computation_amount, communication_amount, rate);
198 SD_task_schedule(taskC, workstation_number, workstation_list,
199 computation_amount, communication_amount, rate);
200 SD_task_schedule(taskD, workstation_number, workstation_list,
201 computation_amount, communication_amount, rate);
203 SD_task_t *changed_tasks;
205 changed_tasks = SD_simulate(-1.0);
206 for (i = 0; changed_tasks[i] != NULL; i++) {
207 INFO3("Task '%s' start time: %f, finish time: %f",
208 SD_task_get_name(changed_tasks[i]),
209 SD_task_get_start_time(changed_tasks[i]),
210 SD_task_get_finish_time(changed_tasks[i]));
213 xbt_assert0(changed_tasks[0] == taskD &&
214 changed_tasks[1] == taskB &&
215 changed_tasks[2] == NULL,
216 "Unexpected simulation results");
218 xbt_free(changed_tasks);
220 DEBUG0("Destroying tasks...");
222 SD_task_destroy(taskA);
223 SD_task_destroy(taskB);
224 SD_task_destroy(taskC);
225 SD_task_destroy(taskD);
227 DEBUG0("Tasks destroyed. Exiting SimDag...");