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++)
59 INFO1("name : %s",SD_workstation_get_name(workstations[i]) );
64 name1 = SD_workstation_get_name(w1);
65 name2 = SD_workstation_get_name(w2);
67 route = SD_route_get_list(w1, w2);
69 route_size = SD_route_get_size(w1, w2);
71 taskA = SD_task_create("Task A", NULL, 10.0);
72 taskB = SD_task_create("Task B", NULL, 40.0);
73 taskC = SD_task_create("Task C", NULL, 30.0);
74 taskD = SD_task_create("Task D", NULL, 60.0);
76 INFO3("Computation time for %f flops on %s: %f", computation_amount1, name1,
77 SD_workstation_get_computation_time(w1, computation_amount1));
78 INFO3("Computation time for %f flops on %s: %f", computation_amount2, name2,
79 SD_workstation_get_computation_time(w2, computation_amount2));
81 INFO2("Route between %s and %s:", name1, name2);
82 for (i = 0; i < route_size; i++) {
83 INFO3("\tLink %s: latency = %f, bandwidth = %f",
84 SD_link_get_name(route[i]), SD_link_get_current_latency(route[i]),
85 SD_link_get_current_bandwidth(route[i]));
87 INFO2("Route latency = %f, route bandwidth = %f",
88 SD_route_get_current_latency(w1, w2),
89 SD_route_get_current_bandwidth(w1, w2));
90 INFO4("Communication time for %f bytes between %s and %s: %f",
91 communication_amount12, name1, name2,
92 SD_route_get_communication_time(w1, w2, communication_amount12));
93 INFO4("Communication time for %f bytes between %s and %s: %f",
94 communication_amount21, name2, name1,
95 SD_route_get_communication_time(w2, w1, communication_amount21));
97 /* creation of the tasks and their dependencies */
99 SD_task_dependency_add(NULL, NULL, taskB, taskA);
100 SD_task_dependency_add(NULL, NULL, taskC, taskA);
101 SD_task_dependency_add(NULL, NULL, taskD, taskB);
102 SD_task_dependency_add(NULL, NULL, taskD, taskC);
103 /* SD_task_dependency_add(NULL, NULL, taskA, taskD); /\* deadlock */
106 SD_task_dependency_add(NULL, NULL, taskA, taskA); /* shouldn't work and must raise an exception */
107 xbt_assert0(0, "Hey, I can add a dependency between Task A and Task A!");
113 SD_task_dependency_add(NULL, NULL, taskA, taskB); /* shouldn't work and must raise an exception */
114 xbt_assert0(0, "Oh oh, I can add an already existing dependency!");
119 SD_task_dependency_remove(taskA, taskB);
122 SD_task_dependency_remove(taskC, taskA); /* shouldn't work and must raise an exception */
123 xbt_assert0(0, "Dude, I can remove an unknown dependency!");
129 SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */
131 "Wow, I can remove a dependency between Task C and itself!");
137 /* if everything is ok, no exception is forwarded or rethrown by main() */
140 SD_task_watch(taskD, SD_DONE);
141 SD_task_watch(taskB, SD_DONE);
142 SD_task_unwatch(taskD, SD_DONE);
145 /* scheduling parameters */
147 const int workstation_number = 2;
148 const SD_workstation_t workstation_list[] = { w1, w2 };
149 double computation_amount[] =
150 { computation_amount1, computation_amount2 };
151 double communication_amount[] = {
152 0, communication_amount12,
153 communication_amount21, 0
155 xbt_dynar_t changed_tasks;
159 SD_task_t task = taskD;
160 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
161 SD_task_get_execution_time(task, workstation_number,
162 workstation_list, computation_amount,
163 communication_amount));
165 /* let's launch the simulation! */
167 SD_task_schedule(taskA, workstation_number, workstation_list,
168 computation_amount, communication_amount, rate);
169 SD_task_schedule(taskB, workstation_number, workstation_list,
170 computation_amount, communication_amount, rate);
171 SD_task_schedule(taskC, workstation_number, workstation_list,
172 computation_amount, communication_amount, rate);
173 SD_task_schedule(taskD, workstation_number, workstation_list,
174 computation_amount, communication_amount, rate);
176 changed_tasks = SD_simulate(-1.0);
178 xbt_dynar_get_cpy(changed_tasks, 0, &checkD);
179 xbt_dynar_get_cpy(changed_tasks, 1, &checkC);
180 xbt_dynar_get_cpy(changed_tasks, 2, &checkB);
182 xbt_assert0(checkD == taskD &&
184 checkB == taskB, "Unexpected simulation results");
186 xbt_dynar_free_container(&changed_tasks);
188 DEBUG0("Destroying tasks...");
190 SD_task_destroy(taskA);
191 SD_task_destroy(taskB);
192 SD_task_destroy(taskC);
193 SD_task_destroy(taskD);
195 DEBUG0("Tasks destroyed. Exiting SimDag...");