1 #include "simdag/simdag.h"
3 #include "xbt/sysdep.h"
7 SD_global_t sd_global = NULL;
9 /* Initialises SD internal data. This function should be called before any other SD function.
11 void SD_init(int *argc, char **argv) {
12 xbt_assert0(sd_global == NULL, "SD_init already called");
14 sd_global = xbt_new0(s_SD_global_t, 1);
15 sd_global->workstations = xbt_dict_new();
16 sd_global->workstation_count = 0;
17 sd_global->links = xbt_dict_new();
18 sd_global->tasks = xbt_dynar_new(sizeof(SD_task_t), NULL);
21 sd_global->not_scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
22 sd_global->scheduled_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
23 sd_global->running_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
24 sd_global->done_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
25 sd_global->failed_task_set = xbt_swag_new(xbt_swag_offset(task, state_hookup));
27 surf_init(argc, argv);
30 /* Creates the environnement described in a xml file of a platform description.
32 void SD_create_environment(const char *platform_file) {
33 xbt_dict_cursor_t cursor = NULL;
35 void *surf_workstation = NULL;
36 void *surf_link = NULL;
40 surf_timer_resource_init(platform_file); /* tell Surf to create the environnement */
43 /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
44 printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
46 /*surf_workstation_resource_init_KCCFLN05(platform_file);*/
47 surf_workstation_resource_init_CLM03(platform_file);
49 /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
50 printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
53 /* now let's create the SD wrappers for workstations and links */
54 xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
55 __SD_workstation_create(surf_workstation, NULL);
58 xbt_dict_foreach(network_link_set, cursor, name, surf_link) {
59 __SD_link_create(surf_link, NULL);
63 /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed.
65 SD_task_t* SD_simulate(double how_long)
69 double total_time = 0.0; /* we stop the simulation when total_time >= how_long */
70 double elapsed_time = 0.0;
71 int watch_point_reached = 0;
74 surf_action_t surf_action;
76 surf_solve(); /* Takes traces into account. Returns 0.0 */
79 while (elapsed_time >= 0.0 && total_time < how_long && !watch_point_reached) {
80 for (i = 0 ; i < xbt_dynar_length(sd_global->tasks); i++) {
81 xbt_dynar_get_cpy(sd_global->tasks, i, &task);
82 printf("Examining task '%s'...\n", SD_task_get_name(task));
84 /* if the task is scheduled and the dependencies are satisfied,
85 we can execute the task */
86 if (SD_task_get_state(task) == SD_SCHEDULED) {
87 printf("Task '%s' is scheduled.\n", SD_task_get_name(task));
89 if (xbt_dynar_length(task->tasks_before) == 0) {
90 printf("The dependencies are satisfied. Executing task '%s'\n", SD_task_get_name(task));
91 surf_action = __SD_task_run(task);
94 printf("Cannot execute task '%s' because some depencies are not satisfied.\n", SD_task_get_name(task));
98 printf("Task '%s' is not scheduled. Nothing to do.\n", SD_task_get_name(task));
101 elapsed_time = surf_solve();
102 if (elapsed_time > 0.0)
103 total_time += elapsed_time;
104 printf("Total time: %f\n", total_time);
111 /* temporary test to explore the workstations and the links */
112 xbt_dict_cursor_t cursor = NULL;
114 SD_workstation_t workstation = NULL;
115 double power, available_power, bandwidth, latency;
116 SD_link_t link = NULL;
120 xbt_dict_foreach(sd_global->workstations, cursor, name, workstation) {
121 power = SD_workstation_get_power(workstation);
122 available_power = SD_workstation_get_available_power(workstation);
123 printf("Workstation name: %s, power: %f Mflop/s, available power: %f%%\n", name, power, (available_power*100));
126 xbt_dict_foreach(sd_global->links, cursor, name, link) {
127 bandwidth = SD_link_get_current_bandwidth(link);
128 latency = SD_link_get_current_latency(link);
129 printf("Link name: %s, bandwidth: %f, latency: %f\n", name, bandwidth, latency);
132 /* test the route between two workstations */
133 SD_workstation_t src, dst;
134 xbt_dict_cursor_first(sd_global->workstations, &cursor);
135 xbt_dict_cursor_get_or_free(&cursor, &name, (void**) &src);
136 xbt_dict_cursor_step(cursor);
137 xbt_dict_cursor_get_or_free(&cursor, &name, (void**) &dst);
138 xbt_dict_cursor_free(&cursor);
140 SD_link_t *route = SD_workstation_route_get_list(src, dst);
141 int route_size = SD_workstation_route_get_size(src, dst);
143 printf("Route between %s and %s (%d links) : ", SD_workstation_get_name(src), SD_workstation_get_name(dst), route_size);
145 for (i = 0; i < route_size; i++) {
146 printf("%s ", SD_link_get_name(route[i]));
151 /* Destroys all SD internal data. This function should be called when the simulation is over.
152 * The tasks should have been destroyed first.
155 if (sd_global != NULL) {
156 xbt_dict_free(&sd_global->workstations);
157 xbt_dict_free(&sd_global->links);
158 xbt_dynar_free(&sd_global->tasks);
161 xbt_swag_free(sd_global->not_scheduled_task_set);
162 xbt_swag_free(sd_global->scheduled_task_set);
163 xbt_swag_free(sd_global->running_task_set);
164 xbt_swag_free(sd_global->done_task_set);
165 xbt_swag_free(sd_global->failed_task_set);