1 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "simdag/simdag.h"
13 XBT_LOG_NEW_DEFAULT_CATEGORY(sd_test,
14 "Logging specific to this SimDag example");
16 int main(int argc, char **argv)
19 const char *platform_file;
21 const SD_workstation_t *workstations;
26 const double computation_amount1 = 2000000;
27 const double computation_amount2 = 1000000;
28 const double communication_amount12 = 2000000;
29 const double communication_amount21 = 3000000;
30 const SD_link_t *route;
38 /* initialisation of SD */
42 INFO1("Usage: %s platform_file", argv[0]);
43 INFO1("example: %s sd_platform.xml", argv[0]);
47 /* creation of the environment */
49 platform_file = argv[1];
51 SD_create_environment(platform_file);
53 /* test the estimation functions (use small_platform.xml) */
54 workstations = SD_workstation_get_list();
57 name1 = SD_workstation_get_name(w1);
58 name2 = SD_workstation_get_name(w2);
59 route = SD_route_get_list(w1, w2);
60 route_size = SD_route_get_size(w1, w2);
61 taskA = SD_task_create("Task A", NULL, 10.0);
62 taskB = SD_task_create("Task B", NULL, 40.0);
63 taskC = SD_task_create("Task C", NULL, 30.0);
64 taskD = SD_task_create("Task D", NULL, 60.0);
66 INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
67 SD_workstation_get_computation_time(w1, computation_amount1));
68 INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
69 SD_workstation_get_computation_time(w2, computation_amount2));
71 INFO2("Route between %s and %s:", name1, name2);
72 for (i = 0; i < route_size; i++) {
73 INFO3("\tLink %s: latency = %f, bandwidth = %f",
74 SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]),
75 SD_link_get_current_bandwidth(route[i]));
77 INFO2("Route latency = %f, route bandwidth = %f",
78 SD_route_get_current_latency(w1, w2),
79 SD_route_get_current_bandwidth(w1, w2));
80 INFO4("Communication time for %f bytes between %s and %s: %f",
81 communication_amount12, name1, name2,
82 SD_route_get_communication_time(w1, w2, communication_amount12));
83 INFO4("Communication time for %f bytes between %s and %s: %f",
84 communication_amount21, name2, name1,
85 SD_route_get_communication_time(w2, w1, communication_amount21));
87 /* creation of the tasks and their dependencies */
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 */
96 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
97 xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
103 SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
104 xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
109 SD_task_dependency_remove(taskA, taskB);
112 SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
113 xbt_assert0(0, "Dude, I can remove an unknown dependency!");
119 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
121 "Wow, I can remove a dependency between Task C and itself!");
127 /* if everything is ok, no exception is forwarded or rethrown by main() */
130 SD_task_watch(taskD, SD_DONE);
131 SD_task_watch(taskB, SD_DONE);
132 SD_task_unwatch(taskD, SD_DONE);
135 /* scheduling parameters */
137 const int workstation_number = 2;
138 const SD_workstation_t workstation_list[] = { w1, w2 };
139 double computation_amount[] =
140 { computation_amount1, computation_amount2 };
141 double communication_amount[] = {
142 0, communication_amount12,
143 communication_amount21, 0
145 SD_task_t *changed_tasks;
149 SD_task_t task = taskD;
150 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
151 SD_task_get_execution_time(task, workstation_number,
152 workstation_list, computation_amount,
153 communication_amount));
155 /* let's launch the simulation! */
157 SD_task_schedule(taskA, workstation_number, workstation_list,
158 computation_amount, communication_amount, rate);
159 SD_task_schedule(taskB, workstation_number, workstation_list,
160 computation_amount, communication_amount, rate);
161 SD_task_schedule(taskC, workstation_number, workstation_list,
162 computation_amount, communication_amount, rate);
163 SD_task_schedule(taskD, workstation_number, workstation_list,
164 computation_amount, communication_amount, rate);
166 changed_tasks = SD_simulate(-1.0);
167 xbt_assert0(changed_tasks[0] == taskD &&
168 changed_tasks[1] == taskC &&
169 changed_tasks[2] == taskB &&
170 changed_tasks[3] == NULL, "Unexpected simulation results");
172 xbt_free(changed_tasks);
174 DEBUG0("Destroying tasks...");
176 SD_task_destroy(taskA);
177 SD_task_destroy(taskB);
178 SD_task_destroy(taskC);
179 SD_task_destroy(taskD);
181 DEBUG0("Tasks destroyed. Exiting SimDag...");