Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement link names in SimDag.
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 19 Jun 2006 13:02:30 +0000 (13:02 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 19 Jun 2006 13:02:30 +0000 (13:02 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2393 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/simdag/private.h
src/simdag/sd_global.c
src/simdag/sd_link.c
src/simdag/sd_workstation.c

index c3d0f13..7884ad0 100644 (file)
 typedef struct SD_global {
   xbt_dict_t workstations; /* workstation list */
   int workstation_count; /* number of workstations */
 typedef struct SD_global {
   xbt_dict_t workstations; /* workstation list */
   int workstation_count; /* number of workstations */
+  xbt_dict_t links; /* link list */
 } s_SD_global_t, *SD_global_t;
 
 extern SD_global_t sd_global;
 
 /* Link private data */
 typedef struct SD_link_data {
 } s_SD_global_t, *SD_global_t;
 
 extern SD_global_t sd_global;
 
 /* Link private data */
 typedef struct SD_link_data {
-  voidsurf_link; /* surf object */
-
+  void *surf_link; /* surf object */
+  char *name;
 } s_SD_link_data_t;
 
 /* Workstation private data */
 typedef struct SD_workstation_data {
 } s_SD_link_data_t;
 
 /* Workstation private data */
 typedef struct SD_workstation_data {
-  voidsurf_workstation; /* surf object */
+  void *surf_workstation; /* surf object */
   /* TODO: route */
 } s_SD_workstation_data_t;
 
 /* Private functions */
 
   /* TODO: route */
 } s_SD_workstation_data_t;
 
 /* Private functions */
 
-SD_link_t __SD_link_create(const char *name, void *surf_link, void *data);
-void __SD_link_destroy(SD_link_t link);
+SD_link_t __SD_link_create(void *surf_link, char *name, void *data);
+void __SD_link_destroy(void *link);
 
 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
 void __SD_workstation_destroy(void *workstation);
 
 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data);
 void __SD_workstation_destroy(void *workstation);
index 8ce1104..bf190c0 100644 (file)
@@ -14,25 +14,43 @@ void SD_init(int *argc, char **argv) {
   sd_global = xbt_new0(s_SD_global_t, 1);
   sd_global->workstations = xbt_dict_new();
   sd_global->workstation_count = 0;
   sd_global = xbt_new0(s_SD_global_t, 1);
   sd_global->workstations = xbt_dict_new();
   sd_global->workstation_count = 0;
+  /*sd_global->links = xbt_dynar_new(sizeof(s_SD_link_t), __SD_link_destroy);*/
+  sd_global->links = xbt_dict_new();
 
   surf_init(argc, argv);
 }
 
 
   surf_init(argc, argv);
 }
 
-/* Creates the environnement described in a xml file of a platform descriptions.
+/* Creates the environnement described in a xml file of a platform description.
  */
 void SD_create_environment(const char *platform_file) {
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   void *surf_workstation = NULL;
  */
 void SD_create_environment(const char *platform_file) {
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   void *surf_workstation = NULL;
+  void *surf_link = NULL;
 
   CHECK_INIT_DONE();
 
   CHECK_INIT_DONE();
-  surf_timer_resource_init(platform_file);
-  surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */
 
 
-  /* now let's create the SD wrappers */
+  surf_timer_resource_init(platform_file);  /* tell Surf to create the environnement */
+
+  
+  /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
+    printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
+
+  surf_workstation_resource_init_KCCFLN05(platform_file);
+  /*  surf_workstation_resource_init_CLM03(platform_file);*/
+
+  /*printf("surf_workstation_resource = %p, workstation_set = %p\n", surf_workstation_resource, workstation_set);
+    printf("surf_network_resource = %p, network_link_set = %p\n", surf_network_resource, network_link_set);*/
+
+
+  /* now let's create the SD wrappers for workstations and links */
   xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
     __SD_workstation_create(surf_workstation, NULL);
   }
   xbt_dict_foreach(workstation_set, cursor, name, surf_workstation) {
     __SD_workstation_create(surf_workstation, NULL);
   }
+
+  xbt_dict_foreach(network_link_set, cursor, name, surf_link) {
+    __SD_link_create(surf_link, name, NULL);
+  }
 }
 
 /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed.
 }
 
 /* Launches the simulation. Returns a NULL-terminated array of SD_task_t whose state has changed.
@@ -41,11 +59,12 @@ SD_task_t* SD_simulate(double how_long)
 {
   /* TODO */
 
 {
   /* TODO */
 
-  /* temporary test to explore the workstations */
+  /* temporary test to explore the workstations and the links */
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   SD_workstation_t workstation = NULL;
   double power, available_power;
   xbt_dict_cursor_t cursor = NULL;
   char *name = NULL;
   SD_workstation_t workstation = NULL;
   double power, available_power;
+  SD_link_t link = NULL;
 
   surf_solve();
   
 
   surf_solve();
   
@@ -54,7 +73,10 @@ SD_task_t* SD_simulate(double how_long)
     available_power = SD_workstation_get_available_power(workstation);
     printf("Workstation name: %s, power: %f Mflop/s, available power: %f%%\n", name, power, (available_power*100));
   }
     available_power = SD_workstation_get_available_power(workstation);
     printf("Workstation name: %s, power: %f Mflop/s, available power: %f%%\n", name, power, (available_power*100));
   }
-  /* TODO: remove name from SD workstation structure */
+
+  xbt_dict_foreach(sd_global->links, cursor, name, link) {
+    printf("Link name: %s\n", name);
+  }
 
   return NULL;
 }
 
   return NULL;
 }
@@ -64,8 +86,9 @@ SD_task_t* SD_simulate(double how_long)
 void SD_clean() {
   if (sd_global != NULL) {
     xbt_dict_free(&sd_global->workstations);
 void SD_clean() {
   if (sd_global != NULL) {
     xbt_dict_free(&sd_global->workstations);
+    xbt_dict_free(&sd_global->links);
     xbt_free(sd_global);
     surf_exit();
     xbt_free(sd_global);
     surf_exit();
-    /* TODO: destroy the workstations, the links and the tasks */
+    /* TODO: destroy the tasks */
   }
 }
   }
 }
index 424ebc3..3a42574 100644 (file)
@@ -1,45 +1,57 @@
 #include "private.h"
 #include "simdag/simdag.h"
 #include "private.h"
 #include "simdag/simdag.h"
+#include "surf/surf.h"
 #include "xbt/sysdep.h" /* xbt_new0 */
 
 /* Creates a link.
  */
 #include "xbt/sysdep.h" /* xbt_new0 */
 
 /* Creates a link.
  */
-SD_link_t __SD_link_create(const char *name, void *surf_link, void *data) {
+SD_link_t __SD_link_create(void *surf_link, char *name, void *data) {
+  CHECK_INIT_DONE();
   xbt_assert0(surf_link != NULL, "surf_link is NULL !");
   xbt_assert0(surf_link != NULL, "surf_link is NULL !");
+  xbt_assert0(name != NULL, "name is NULL !");
+
   SD_link_data_t sd_data = xbt_new0(s_SD_link_data_t, 1); /* link private data */
   sd_data->surf_link = surf_link;
   SD_link_data_t sd_data = xbt_new0(s_SD_link_data_t, 1); /* link private data */
   sd_data->surf_link = surf_link;
+  sd_data->name = xbt_strdup(name);
 
   SD_link_t link = xbt_new0(s_SD_link_t, 1);
 
   SD_link_t link = xbt_new0(s_SD_link_t, 1);
-  link->name = xbt_strdup(name);
-  link->data = data;
-  link->sd_data = sd_data;
+  link->sd_data = sd_data; /* private data */
+  link->data = data; /* user data */
 
   /*link->capacity = capacity;*/
   /* link->current_bandwidth = bandwidth;
      link->current_latency = latency;*/
 
 
   /*link->capacity = capacity;*/
   /* link->current_bandwidth = bandwidth;
      link->current_latency = latency;*/
 
+  /*xbt_dynar_push(sd_global->links, link);*/
+  xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the workstation to the dictionary */
+
   return link;
 }
 
 /* Returns the user data of a link. The user data can be NULL.
  */
 void* SD_link_get_data(SD_link_t link) {
   return link;
 }
 
 /* Returns the user data of a link. The user data can be NULL.
  */
 void* SD_link_get_data(SD_link_t link) {
-  xbt_assert0(link, "Invalid parameter");
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
   return link->data;
 }
 
 /* Sets the user data of a link. The new data can be NULL. The old data should have been freed first if it was not NULL.
  */
 void SD_link_set_data(SD_link_t link, void *data) {
   return link->data;
 }
 
 /* Sets the user data of a link. The new data can be NULL. The old data should have been freed first if it was not NULL.
  */
 void SD_link_set_data(SD_link_t link, void *data) {
-  xbt_assert0(link, "Invalid parameter");
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
   link->data = data;
 }
 
 /* Returns the name of a link. The name can be NULL.
  */
 const char* SD_link_get_name(SD_link_t link) {
   link->data = data;
 }
 
 /* Returns the name of a link. The name can be NULL.
  */
 const char* SD_link_get_name(SD_link_t link) {
-  xbt_assert0(link, "Invalid parameter");
-  return link->name;
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
+  return link->sd_data->name;
+
+  /*  return surf_network_resource->common_public->get_resource_name(link->sd_data->surf_link);*/
 }
 
 /* Returns the capacity of a link.
 }
 
 /* Returns the capacity of a link.
@@ -53,7 +65,8 @@ double SD_link_get_capacity(SD_link_t link) {
 /* Return the current bandwidth of a link.
  */
 double SD_link_get_current_bandwidth(SD_link_t link) {
 /* Return the current bandwidth of a link.
  */
 double SD_link_get_current_bandwidth(SD_link_t link) {
-  xbt_assert0(link, "Invalid parameter");
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
 
   /* TODO */
   return 0;
 
   /* TODO */
   return 0;
@@ -63,7 +76,8 @@ double SD_link_get_current_bandwidth(SD_link_t link) {
 /* Return the current latency of a link.
  */
 double SD_link_get_current_latency(SD_link_t link) {
 /* Return the current latency of a link.
  */
 double SD_link_get_current_latency(SD_link_t link) {
-  xbt_assert0(link, "Invalid parameter");
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
 
   /* TODO */
   return 0;
 
   /* TODO */
   return 0;
@@ -72,14 +86,15 @@ double SD_link_get_current_latency(SD_link_t link) {
 
 /* Destroys a link. The user data (if any) should have been destroyed first.
  */
 
 /* Destroys a link. The user data (if any) should have been destroyed first.
  */
-void __SD_link_destroy(SD_link_t link) {
-  xbt_assert0(link, "Invalid parameter");
+void __SD_link_destroy(void *link) {
+  CHECK_INIT_DONE();
+  xbt_assert0(link != NULL, "Invalid parameter");
 
 
-  if (link->sd_data != NULL)
-    xbt_free(link->sd_data);
-  
-  if (link->name != NULL)
-    xbt_free(link->name);
+  if (((SD_link_t) link)->sd_data != NULL)
+    xbt_free(((SD_link_t) link)->sd_data);
 
 
+  /* TODO: name */
+  
   xbt_free(link);
 }
   xbt_free(link);
 }
+
index 4ae419a..5c25338 100644 (file)
@@ -8,6 +8,7 @@
  */
 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
   CHECK_INIT_DONE();
  */
 SD_workstation_t __SD_workstation_create(void *surf_workstation, void *data) {
   CHECK_INIT_DONE();
+  xbt_assert0(surf_workstation != NULL, "surf_workstation is NULL !");
 
   SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */
   sd_data->surf_workstation = surf_workstation;
 
   SD_workstation_data_t sd_data = xbt_new0(s_SD_workstation_data_t, 1); /* workstation private data */
   sd_data->surf_workstation = surf_workstation;