5 #include "simdag/simdag.h"
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test,
14 int main(int argc, char **argv) {
16 const char * platform_file;
17 const SD_workstation_t *workstations;
23 xbt_dict_cursor_t cursor = NULL;
25 char noexist[]="NoProp";
28 const double computation_amount1 = 2000000;
29 const double computation_amount2 = 1000000;
30 const double communication_amount12 = 2000000;
31 const double communication_amount21 = 3000000;
32 const SD_link_t *route;
34 SD_task_t taskA, taskB, taskC, taskD, task;
35 const int workstation_number = 2;
36 SD_workstation_t workstation_list[2];
37 double computation_amount[2];
38 double communication_amount[4] = {0};
40 SD_task_t *changed_tasks;
42 /* initialisation of SD */
45 platform_file = argv[1];
47 /* xbt_log_control_set("sd.thres=debug"); */
50 INFO1("Usage: %s platform_file", argv[0]);
51 INFO1("example: %s sd_platform.xml", argv[0]);
55 /* creation of the environment */
56 SD_create_environment(platform_file);
58 /* test the estimation functions */
59 workstations = SD_workstation_get_list();
62 SD_workstation_set_access_mode(w2, SD_WORKSTATION_SEQUENTIAL_ACCESS);
63 name1 = SD_workstation_get_name(w1);
64 name2 = SD_workstation_get_name(w2);
67 /* The host properties can be retrived from all interfaces */
69 INFO1("Property list for workstation %s", name1);
70 /* Get the property list of the workstation 1 */
71 props = SD_workstation_get_properties(w1);
74 /* Trying to set a new property */
75 xbt_dict_set(props, xbt_strdup("NewProp"), strdup("newValue"), free);
77 /* Print the properties of the workstation 1 */
78 xbt_dict_foreach(props,cursor,key,data) {
79 INFO2("\tProperty: %s has value: %s",key,data);
82 /* Try to get a property that does not exist */
84 value = SD_workstation_get_property_value(w1,noexist);
86 INFO1("\tProperty: %s is undefined", noexist);
88 INFO2("\tProperty: %s has value: %s", noexist, value);
91 INFO1("Property list for workstation %s", name2);
92 /* Get the property list of the workstation 2 */
93 props = SD_workstation_get_properties(w2);
96 /* Print the properties of the workstation 2 */
97 xbt_dict_foreach(props,cursor,key,data) {
98 INFO2("\tProperty: %s on host: %s",key,data);
101 /* Modify an existing property test. First check it exists */\
102 INFO0("Modify an existing property");
104 value = SD_workstation_get_property_value(w2,exist);
106 INFO1("\tProperty: %s is undefined", exist);
108 INFO2("\tProperty: %s old value: %s", exist, value);
109 xbt_dict_set(props, exist, strdup("250"), free);
112 /* Test if we have changed the value */
113 value = SD_workstation_get_property_value(w2,exist);
115 INFO1("\tProperty: %s is undefined", exist);
117 INFO2("\tProperty: %s new value: %s", exist, value);
119 /* NOTE: The link properties can be retrieved only from the SimDag interface */
120 route = SD_route_get_list(w1, w2);
121 route_size = SD_route_get_size(w1, w2);
122 for (i = 0; i < route_size; i++) {
123 xbt_dict_cursor_t cursor = NULL;
125 char noexist1[]="Other";
126 props = SD_link_get_properties(route[i]);
129 /* Print the properties of the current link */
130 xbt_dict_foreach(props,cursor,key,data) {
131 INFO3("\tLink %s property: %s has value: %s",SD_link_get_name(route[i]),key,data);
133 /* Try to get a property that does not exist */
135 value = SD_link_get_property_value(route[i], noexist1);
137 INFO2("\tProperty: %s for link %s is undefined", noexist, SD_link_get_name(route[i]));
139 INFO3("\tLink %s property: %s has value: %s",SD_link_get_name(route[i]),noexist,value);
143 /* creation of the tasks and their dependencies */
144 taskA = SD_task_create("Task A", NULL, 10.0);
145 taskB = SD_task_create("Task B", NULL, 40.0);
146 taskC = SD_task_create("Task C", NULL, 30.0);
147 taskD = SD_task_create("Task D", NULL, 60.0);
150 SD_task_dependency_add(NULL, NULL, taskB, taskA);
151 SD_task_dependency_add(NULL, NULL, taskC, taskA);
152 SD_task_dependency_add(NULL, NULL, taskD, taskB);
153 SD_task_dependency_add(NULL, NULL, taskD, taskC);
156 SD_task_watch(taskD, SD_DONE);
157 SD_task_watch(taskB, SD_DONE);
158 SD_task_unwatch(taskD, SD_DONE);
161 /* scheduling parameters */
162 workstation_list[0] = w1;
163 workstation_list[1] = w2;
164 computation_amount[0] = computation_amount1;
165 computation_amount[1] = computation_amount2;
167 communication_amount[1] = communication_amount12;
168 communication_amount[2] = communication_amount21;
174 INFO2("Estimated time for '%s': %f", SD_task_get_name(task),
175 SD_task_get_execution_time(task, workstation_number, workstation_list,
176 computation_amount, communication_amount, rate));
178 /* let's launch the simulation! */
180 SD_task_schedule(taskA, workstation_number, workstation_list,
181 computation_amount, communication_amount, rate);
182 SD_task_schedule(taskB, workstation_number, workstation_list,
183 computation_amount, communication_amount, rate);
184 SD_task_schedule(taskC, workstation_number, workstation_list,
185 computation_amount, communication_amount, rate);
186 SD_task_schedule(taskD, workstation_number, workstation_list,
187 computation_amount, communication_amount, rate);
189 changed_tasks = SD_simulate(-1.0);
190 for (i = 0; changed_tasks[i] != NULL; i++) {
191 INFO3("Task '%s' start time: %f, finish time: %f",
192 SD_task_get_name(changed_tasks[i]),
193 SD_task_get_start_time(changed_tasks[i]),
194 SD_task_get_finish_time(changed_tasks[i]));
197 xbt_assert0(changed_tasks[0] == taskD &&
198 changed_tasks[1] == taskB &&
199 changed_tasks[2] == NULL,
200 "Unexpected simulation results");
202 xbt_free(changed_tasks);
204 DEBUG0("Destroying tasks...");
206 SD_task_destroy(taskA);
207 SD_task_destroy(taskB);
208 SD_task_destroy(taskC);
209 SD_task_destroy(taskD);
211 DEBUG0("Tasks destroyed. Exiting SimDag...");