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;
24 const char *name1 = NULL;
25 const char *name2 = NULL;
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;
33 SD_task_t taskB, checkB;
34 SD_task_t taskC, checkC;
35 SD_task_t taskD, checkD;
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 for (i = 0; i < SD_workstation_get_number(); i++) {
58 INFO1("name : %s", SD_workstation_get_name(workstations[i]));
63 name1 = SD_workstation_get_name(w1);
64 name2 = SD_workstation_get_name(w2);
66 route = SD_route_get_list(w1, w2);
68 route_size = SD_route_get_size(w1, w2);
70 taskA = SD_task_create("Task A", NULL, 10.0);
71 taskB = SD_task_create("Task B", NULL, 40.0);
72 taskC = SD_task_create("Task C", NULL, 30.0);
73 taskD = SD_task_create("Task D", NULL, 60.0);
75 INFO3("Computation time for %f flops on %s: %f", computation_amount1,
76 name1, SD_workstation_get_computation_time(w1,
77 computation_amount1));
78 INFO3("Computation time for %f flops on %s: %f", computation_amount2,
79 name2, SD_workstation_get_computation_time(w2,
80 computation_amount2));
82 INFO2("Route between %s and %s:", name1, name2);
83 for (i = 0; i < route_size; i++) {
84 INFO3("\tLink %s: latency = %f, bandwidth = %f",
85 SD_link_get_name(route[i]),
86 SD_link_get_current_latency(route[i]),
87 SD_link_get_current_bandwidth(route[i]));
89 INFO2("Route latency = %f, route bandwidth = %f",
90 SD_route_get_current_latency(w1, w2),
91 SD_route_get_current_bandwidth(w1, w2));
92 INFO4("Communication time for %f bytes between %s and %s: %f",
93 communication_amount12, name1, name2,
94 SD_route_get_communication_time(w1, w2, communication_amount12));
95 INFO4("Communication time for %f bytes between %s and %s: %f",
96 communication_amount21, name2, name1,
97 SD_route_get_communication_time(w2, w1, communication_amount21));
99 /* creation of the tasks and their dependencies */
101 SD_task_dependency_add(NULL, NULL, taskB, taskA);
102 SD_task_dependency_add(NULL, NULL, taskC, taskA);
103 SD_task_dependency_add(NULL, NULL, taskD, taskB);
104 SD_task_dependency_add(NULL, NULL, taskD, taskC);
105 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
108 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
110 "Hey, I can add a dependency between Task A and Task A!");
116 SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
117 xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
122 SD_task_dependency_remove(taskA, taskB);
125 SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
126 xbt_assert0(0, "Dude, I can remove an unknown dependency!");
132 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
134 "Wow, I can remove a dependency between Task C and itself!");
140 /* if everything is ok, no exception is forwarded or rethrown by main() */
143 SD_task_watch(taskD, SD_DONE);
144 SD_task_watch(taskB, SD_DONE);
145 SD_task_unwatch(taskD, SD_DONE);
148 /* scheduling parameters */
150 const int workstation_number = 2;
151 const SD_workstation_t workstation_list[] = { w1, w2 };
152 double computation_amount[] =
153 { computation_amount1, computation_amount2 };
154 double communication_amount[] = {
155 0, communication_amount12,
156 communication_amount21, 0
158 xbt_dynar_t changed_tasks;
162 SD_task_t task = taskD;
163 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
164 SD_task_get_execution_time(task, workstation_number,
165 workstation_list, computation_amount,
166 communication_amount));
168 /* let's launch the simulation! */
170 SD_task_schedule(taskA, workstation_number, workstation_list,
171 computation_amount, communication_amount, rate);
172 SD_task_schedule(taskB, workstation_number, workstation_list,
173 computation_amount, communication_amount, rate);
174 SD_task_schedule(taskC, workstation_number, workstation_list,
175 computation_amount, communication_amount, rate);
176 SD_task_schedule(taskD, workstation_number, workstation_list,
177 computation_amount, communication_amount, rate);
179 changed_tasks = SD_simulate(-1.0);
181 xbt_dynar_get_cpy(changed_tasks, 0, &checkD);
182 xbt_dynar_get_cpy(changed_tasks, 1, &checkC);
183 xbt_dynar_get_cpy(changed_tasks, 2, &checkB);
185 xbt_assert0(checkD == taskD &&
187 checkB == taskB, "Unexpected simulation results");
189 xbt_dynar_free_container(&changed_tasks);
191 DEBUG0("Destroying tasks...");
193 SD_task_destroy(taskA);
194 SD_task_destroy(taskB);
195 SD_task_destroy(taskC);
196 SD_task_destroy(taskD);
198 DEBUG0("Tasks destroyed. Exiting SimDag...");