Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
52c35d53953ec3570c5c58bd829c843aa0c6cc15
[simgrid.git] / src / simdag / sd_global.c
1 #include "simdag/simdag.h"
2 #include "private.h"
3 #include "xbt/asserts.h"
4 #include "xbt/sysdep.h"
5 #include "surf/surf.h"
6
7 SD_global_t sd_global = NULL;
8
9 /* Initialises SD internal data. This function should be called before any other SD function.
10  */
11 void SD_init(int *argc, char **argv) {
12   xbt_assert0(sd_global == NULL, "SD_init already called");
13
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();
19
20   surf_init(argc, argv);
21 }
22
23 /* Creates the environnement described in a xml file of a platform description.
24  */
25 void SD_create_environment(const char *platform_file) {
26   xbt_dict_cursor_t cursor = NULL;
27   char *name = NULL;
28   void *surf_workstation = NULL;
29   void *surf_link = NULL;
30
31   CHECK_INIT_DONE();
32
33   surf_timer_resource_init(platform_file);  /* tell Surf to create the environnement */
34
35   
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);*/
38
39   surf_workstation_resource_init_KCCFLN05(platform_file);
40   /*surf_workstation_resource_init_CLM03(platform_file);*/
41
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);*/
44
45
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);
49   }
50
51   xbt_dict_foreach(network_link_set, cursor, name, surf_link) {
52     __SD_link_create(surf_link, name, NULL);
53   }
54 }
55
56 /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed.
57  */
58 SD_task_t* SD_simulate(double how_long)
59 {
60   /* TODO */
61
62   /* temporary test to explore the workstations and the links */
63   xbt_dict_cursor_t cursor = NULL;
64   char *name = NULL;
65   SD_workstation_t workstation = NULL;
66   double power, available_power, bandwidth, latency;
67   SD_link_t link = NULL;
68
69   surf_solve();
70
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));
75   }
76
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);
81   }
82
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);
90
91   SD_link_t *route = SD_workstation_route_get_list(src, dst);
92   int route_size = SD_workstation_route_get_size(src, dst);
93
94   printf("Route between %s and %s (%d links) : ", SD_workstation_get_name(src), SD_workstation_get_name(dst), route_size);
95   int i;
96   for (i = 0; i < route_size; i++) {
97     printf("%s ", SD_link_get_name(route[i]));
98   }
99   printf("\n");
100
101   return NULL;
102 }
103
104 /* Destroys all SD data. This function should be called when the simulation is over.
105  */
106 void SD_clean() {
107   if (sd_global != NULL) {
108     xbt_dict_free(&sd_global->workstations);
109     xbt_dict_free(&sd_global->links);
110     xbt_free(sd_global);
111     surf_exit();
112     /* TODO: destroy the tasks */
113   }
114 }