5 #include "simdag/simdag.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
14 int main(int argc, char **argv) {
17 /* initialisation of SD */
20 /* xbt_log_control_set("sd.thres=debug"); */
23 INFO1("Usage: %s platform_file", argv[0]);
24 INFO1("example: %s sd_platform.xml", argv[0]);
28 /* creation of the environment */
29 const char * platform_file = argv[1];
30 SD_create_environment(platform_file);
32 /* test the estimation functions */
33 const SD_workstation_t *workstations = SD_workstation_get_list();
34 SD_workstation_t w1 = workstations[0];
35 SD_workstation_t w2 = workstations[1];
36 SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
37 const char *name1 = SD_workstation_get_name(w1);
38 const char *name2 = SD_workstation_get_name(w2);
40 /* The host properties can be retrived from all interfaces */
42 INFO1("Property list for workstation %s", name1);
43 /* Get the property list of the workstation 1 */
44 props = SD_workstation_get_properties(w1);
45 xbt_dict_cursor_t cursor = NULL;
48 /* Trying to set a new property */
49 xbt_dict_set(props, xbt_strdup("NewProp"), strdup("newValue"), free);
51 /* Print the properties of the workstation 1 */
52 xbt_dict_foreach(props,cursor,key,data) {
53 INFO2("\tProperty: %s has value: %s",key,data);
56 /* Try to get a property that does not exist */
57 char noexist[]="NoProp";
58 const char *value = SD_workstation_get_property_value(w1,noexist);
60 INFO1("\tProperty: %s is undefined", noexist);
62 INFO2("\tProperty: %s has value: %s", noexist, value);
65 INFO1("Property list for workstation %s", name2);
66 /* Get the property list of the workstation 2 */
67 props = SD_workstation_get_properties(w2);
70 /* Print the properties of the workstation 2 */
71 xbt_dict_foreach(props,cursor,key,data) {
72 INFO2("\tProperty: %s on host: %s",key,data);
75 /* Modify an existing property test. First check it exists */\
76 INFO0("Modify an existing property");
78 value = SD_workstation_get_property_value(w2,exist);
80 INFO1("\tProperty: %s is undefined", exist);
82 INFO2("\tProperty: %s old value: %s", exist, value);
83 xbt_dict_set(props, exist, strdup("250"), free);
86 /* Test if we have changed the value */
87 value = SD_workstation_get_property_value(w2,exist);
89 INFO1("\tProperty: %s is undefined", exist);
91 INFO2("\tProperty: %s new value: %s", exist, value);
95 const double computation_amount1 = 2000000;
96 const double computation_amount2 = 1000000;
97 const double communication_amount12 = 2000000;
98 const double communication_amount21 = 3000000;
100 /* NOTE: The link properties can be retrieved only from the SimDag interface */
101 const SD_link_t *route = SD_route_get_list(w1, w2);
102 int route_size = SD_route_get_size(w1, w2);
103 for (i = 0; i < route_size; i++) {
105 props = SD_link_get_properties(route[i]);
106 xbt_dict_cursor_t cursor = NULL;
109 /* Print the properties of the current link */
110 xbt_dict_foreach(props,cursor,key,data) {
111 INFO3("\tLink %s property: %s has value: %s",SD_link_get_name(route[i]),key,data);
113 /* Try to get a property that does not exist */
114 char noexist1[]="Other";
115 value = SD_link_get_property_value(route[i], noexist1);
117 INFO2("\tProperty: %s for link %s is undefined", noexist, SD_link_get_name(route[i]));
119 INFO3("\tLink %s property: %s has value: %s",SD_link_get_name(route[i]),noexist,value);
123 /* creation of the tasks and their dependencies */
124 SD_task_t taskA = SD_task_create("Task A", NULL, 10.0);
125 SD_task_t taskB = SD_task_create("Task B", NULL, 40.0);
126 SD_task_t taskC = SD_task_create("Task C", NULL, 30.0);
127 SD_task_t taskD = SD_task_create("Task D", NULL, 60.0);
130 SD_task_dependency_add(NULL, NULL, taskB, taskA);
131 SD_task_dependency_add(NULL, NULL, taskC, taskA);
132 SD_task_dependency_add(NULL, NULL, taskD, taskB);
133 SD_task_dependency_add(NULL, NULL, taskD, taskC);
136 SD_task_watch(taskD, SD_DONE);
137 SD_task_watch(taskB, SD_DONE);
138 SD_task_unwatch(taskD, SD_DONE);
141 /* scheduling parameters */
143 const int workstation_number = 2;
144 const SD_workstation_t workstation_list[] = {w1, w2};
145 double computation_amount[] = {computation_amount1, computation_amount2};
146 double communication_amount[] =
148 0, communication_amount12,
149 communication_amount21, 0
154 SD_task_t task = taskD;
155 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
156 SD_task_get_execution_time(task, workstation_number, workstation_list,
157 computation_amount, communication_amount, rate));
159 /* let's launch the simulation! */
161 SD_task_schedule(taskA, workstation_number, workstation_list,
162 computation_amount, communication_amount, rate);
163 SD_task_schedule(taskB, workstation_number, workstation_list,
164 computation_amount, communication_amount, rate);
165 SD_task_schedule(taskC, workstation_number, workstation_list,
166 computation_amount, communication_amount, rate);
167 SD_task_schedule(taskD, workstation_number, workstation_list,
168 computation_amount, communication_amount, rate);
170 SD_task_t *changed_tasks;
172 changed_tasks = SD_simulate(-1.0);
173 for (i = 0; changed_tasks[i] != NULL; i++) {
174 INFO3("Task '%s' start time: %f, finish time: %f",
175 SD_task_get_name(changed_tasks[i]),
176 SD_task_get_start_time(changed_tasks[i]),
177 SD_task_get_finish_time(changed_tasks[i]));
180 xbt_assert0(changed_tasks[0] == taskD &&
181 changed_tasks[1] == taskB &&
182 changed_tasks[2] == NULL,
183 "Unexpected simulation results");
185 xbt_free(changed_tasks);
187 DEBUG0("Destroying tasks...");
189 SD_task_destroy(taskA);
190 SD_task_destroy(taskB);
191 SD_task_destroy(taskC);
192 SD_task_destroy(taskD);
194 DEBUG0("Tasks destroyed. Exiting SimDag...");