Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update destructors and test access to surf structures
[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 #define CHECK_INIT_DONE() xbt_assert0(init_done, "SG_init not called yet")
8
9 SG_global_t sg_global = NULL;
10
11 static int init_done = 0;
12
13 /* Initialises SG internal data. This function should be called before any other SG function.
14  */
15 void SG_init(int *argc, char **argv) {
16   xbt_assert0(!init_done, "SG_init already called");
17
18   sg_global = xbt_new0(s_SG_global_t, 1);
19   sg_global->workstations = xbt_dict_new();
20   sg_global->workstation_count = 0;
21
22   surf_init(argc, argv);
23
24   init_done = 1;
25 }
26
27 /* Creates the environnement described in a xml file of a platform descriptions.
28  */
29 void SG_create_environment(const char *platform_file) {
30   xbt_dict_cursor_t cursor = NULL;
31   char *name = NULL;
32   void *workstation = NULL;
33
34   CHECK_INIT_DONE();
35   surf_timer_resource_init(platform_file);
36   surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */
37
38   /* now let's create the SG wrappers */
39   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
40     __SG_workstation_create(name, workstation, NULL);
41   }
42 }
43
44 /* Launches the simulation. Returns a NULL-terminated array of SG_task_t whose state has changed.
45  */
46 SG_task_t* SG_simulate(double how_long)
47 {
48   /* TODO */
49
50   /* temporary test to access to the surf workstation structure */
51   xbt_dict_cursor_t cursor = NULL;
52   char *name = NULL;
53   void *workstation = NULL;
54   const char *surf_name;
55   int speed;
56
57   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
58     surf_name = surf_workstation_resource->common_public->get_resource_name(workstation);
59     speed = surf_workstation_resource->extension_public->get_speed(workstation, 1.0);
60     printf("Workstation name: %s, Surf name: %s, speed: %d\n", name, surf_name, speed);
61   }
62
63   return NULL;
64 }
65
66 /* Destroys all SG data. This function should be called when the simulation is over.
67  */
68 void SG_clean() {
69   if (init_done) {
70     xbt_dict_free(&sg_global->workstations);
71     xbt_free(sg_global);
72     surf_exit();
73     /* TODO: destroy the workstations, the links and the tasks */
74   }
75 }