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 /* initialisation of SD */
16 /* xbt_log_control_set("sd_test.thres=debug"); */
17 /* xbt_log_control_set("sd.thres=debug"); */
20 INFO1("Usage: %s platform_file", argv[0]);
21 INFO1("example: %s sd_platform.xml", argv[0]);
25 /* creation of the environment */
26 char * platform_file = argv[1];
27 SD_create_environment(platform_file);
29 /* test the estimation functions (use small_platform.xml) */
30 const SD_workstation_t *workstations = SD_workstation_get_list();
31 SD_workstation_t w1 = workstations[0];
32 SD_workstation_t w2 = workstations[1];
33 const char *name1 = SD_workstation_get_name(w1);
34 const char *name2 = SD_workstation_get_name(w2);
35 const double computation_amount1 = 2000000;
36 const double computation_amount2 = 1000000;
37 const double communication_amount12 = 2000000;
38 const double communication_amount21 = 3000000;
39 INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
40 SD_workstation_get_computation_time(w1, computation_amount1));
41 INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
42 SD_workstation_get_computation_time(w2, computation_amount2));
44 INFO2("Route between %s and %s:", name1, name2);
45 SD_link_t *route = SD_route_get_list(w1, w2);
46 int route_size = SD_route_get_size(w1, w2);
47 for (i = 0; i < route_size; i++) {
48 INFO3("\tLink %s: latency = %f, bandwidth = %f", SD_link_get_name(route[i]),
49 SD_link_get_current_latency(route[i]), SD_link_get_current_bandwidth(route[i]));
51 INFO2("Route latency = %f, route bandwidth = %f", SD_route_get_current_latency(w1, w2),
52 SD_route_get_current_bandwidth(w1, w2));
53 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount12, name1, name2,
54 SD_route_get_communication_time(w1, w2, communication_amount12));
55 INFO4("Communication time for %f bytes between %s and %s: %f", communication_amount21, name2, name1,
56 SD_route_get_communication_time(w2, w1, communication_amount21));
59 /* creation of the tasks and their dependencies */
60 SD_task_t taskA = SD_task_create("Task A", NULL, 10.0);
61 SD_task_t taskB = SD_task_create("Task B", NULL, 40.0);
62 SD_task_t taskC = SD_task_create("Task C", NULL, 30.0);
63 SD_task_t taskD = SD_task_create("Task D", NULL, 60.0);
65 SD_task_dependency_add(NULL, NULL, taskB, taskA);
66 SD_task_dependency_add(NULL, NULL, taskC, taskA);
67 SD_task_dependency_add(NULL, NULL, taskD, taskB);
68 SD_task_dependency_add(NULL, NULL, taskD, taskC);
69 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock *\/ */
71 /* scheduling parameters */
73 const int workstation_number = 2;
74 /* const SD_workstation_t *workstation_list = SD_workstation_get_list();*/
75 const SD_workstation_t workstation_list[] = {w1, w2};
76 double computation_amount[] = {computation_amount1, computation_amount2};
77 double communication_amount[] =
79 0, communication_amount12,
80 communication_amount21, 0
85 SD_task_t task = taskD;
86 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
87 SD_task_get_execution_time(task, workstation_number, workstation_list,
88 computation_amount, communication_amount, rate));
90 /* let's launch the simulation! */
92 SD_task_schedule(taskA, workstation_number, workstation_list,
93 computation_amount, communication_amount, rate);
94 SD_task_schedule(taskB, workstation_number, workstation_list,
95 computation_amount, communication_amount, rate);
96 SD_task_schedule(taskC, workstation_number, workstation_list,
97 computation_amount, communication_amount, rate);
98 SD_task_schedule(taskD, workstation_number, workstation_list,
99 computation_amount, communication_amount, rate);
101 SD_task_watch(taskC, SD_DONE);
103 SD_task_t *changed_tasks;
105 changed_tasks = SD_simulate(0.001);
107 while (changed_tasks[0] != NULL) {
108 INFO0("Tasks whose state has changed:");
110 while(changed_tasks[i] != NULL) {
111 switch (SD_task_get_state(changed_tasks[i])) {
113 INFO1("%s is scheduled.", SD_task_get_name(changed_tasks[i]));
116 INFO1("%s is ready.", SD_task_get_name(changed_tasks[i]));
119 INFO1("%s is running.", SD_task_get_name(changed_tasks[i]));
122 INFO1("%s is done.", SD_task_get_name(changed_tasks[i]));
125 INFO1("%s is failed.", SD_task_get_name(changed_tasks[i]));
128 INFO1("Unknown status for %s", SD_task_get_name(changed_tasks[i]));
133 xbt_free(changed_tasks);
134 changed_tasks = SD_simulate(100);
137 xbt_free(changed_tasks);
139 DEBUG0("Destroying tasks...");
141 SD_task_destroy(taskA);
142 SD_task_destroy(taskB);
143 SD_task_destroy(taskC);
144 SD_task_destroy(taskD);
146 DEBUG0("Tasks destroyed. Exiting SimDag...");