1 #include "simdag/simdag.h"
3 #include "xbt/asserts.h"
4 #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_dynar_new(sizeof(s_SD_link_t), __SD_link_destroy);*/
18 sd_global->links = xbt_dict_new();
20 surf_init(argc, argv);
23 /* Creates the environnement described in a xml file of a platform description.
25 void SD_create_environment(const char *platform_file) {
26 xbt_dict_cursor_t cursor = NULL;
28 void *surf_workstation = NULL;
29 void *surf_link = NULL;
33 surf_timer_resource_init(platform_file); /* tell Surf to create the environnement */
36 /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
37 printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
39 surf_workstation_resource_init_KCCFLN05(platform_file);
40 /*surf_workstation_resource_init_CLM03(platform_file);*/
42 /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
43 printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
46 /* now let's create the SD wrappers for workstations and links */
47 xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
48 __SD_workstation_create(surf_workstation, NULL);
51 xbt_dict_foreach(network_link_set, cursor, name, surf_link) {
52 __SD_link_create(surf_link, name, NULL);
56 /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed.
58 SD_task_t* SD_simulate(double how_long)
62 /* temporary test to explore the workstations and the links */
63 xbt_dict_cursor_t cursor = NULL;
65 SD_workstation_t workstation = NULL;
66 double power, available_power, bandwidth, latency;
67 SD_link_t link = NULL;
71 xbt_dict_foreach(sd_global->workstations, cursor, name, workstation) {
72 power = SD_workstation_get_power(workstation);
73 available_power = SD_workstation_get_available_power(workstation);
74 printf("Workstation name: %s, power: %f Mflop/s, available power: %f%%\n", name, power, (available_power*100));
77 xbt_dict_foreach(sd_global->links, cursor, name, link) {
78 bandwidth = SD_link_get_current_bandwidth(link);
79 latency = SD_link_get_current_latency(link);
80 printf("Link name: %s, bandwidth: %f, latency; %f\n", name, bandwidth, latency);
83 /* test the route between two workstations */
84 SD_workstation_t src, dst;
85 xbt_dict_cursor_first(sd_global->workstations, &cursor);
86 xbt_dict_cursor_get_or_free(&cursor, &name, (void**) &src);
87 xbt_dict_cursor_step(cursor);
88 xbt_dict_cursor_get_or_free(&cursor, &name, (void**) &dst);
89 xbt_dict_cursor_free(&cursor);
91 SD_link_t *route = SD_workstation_route_get_list(src, dst);
92 int route_size = SD_workstation_route_get_size(src, dst);
94 printf("Route between %s and %s (%d links) : ", SD_workstation_get_name(src), SD_workstation_get_name(dst), route_size);
96 for (i = 0; i < route_size; i++) {
97 printf("%s ", SD_link_get_name(route[i]));
104 /* Destroys all SD data. This function should be called when the simulation is over.
107 if (sd_global != NULL) {
108 xbt_dict_free(&sd_global->workstations);
109 xbt_dict_free(&sd_global->links);
112 /* TODO: destroy the tasks */