Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add private structures and functions + wrapping for Surf links and workstations
authorthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 15 Jun 2006 14:44:52 +0000 (14:44 +0000)
committerthiery <thiery@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 15 Jun 2006 14:44:52 +0000 (14:44 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2381 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/simdag/datatypes.h
include/simdag/simdag.h
src/simdag/private.h
src/simdag/sd_global.c
src/simdag/sd_link.c
src/simdag/sd_task.c
src/simdag/sd_workstation.c

index f21af30..1b1ad0b 100644 (file)
@@ -2,21 +2,28 @@
 #define SIMDAG_DATATYPES_H
 
 /* Link */
 #define SIMDAG_DATATYPES_H
 
 /* Link */
+typedef struct SG_link_data *SG_link_data_t;
+
 typedef struct SG_link {
 typedef struct SG_link {
-  void *data;
+  SG_link_data_t sgdata; /* SG internal data */
+  void *data; /* user data */
   char *name;
   char *name;
+
   /*double capacity;*/
   /*double current_bandwidth;
     double current_latency;*/
 } s_SG_link_t, *SG_link_t;
 
 /* Workstation */
   /*double capacity;*/
   /*double current_bandwidth;
     double current_latency;*/
 } s_SG_link_t, *SG_link_t;
 
 /* Workstation */
+typedef struct SG_workstation_data *SG_workstation_data_t;
+
 typedef struct SG_workstation {
 typedef struct SG_workstation {
-  void *data;
+  SG_workstation_data_t sgdata; /* SG internal data */
+  void *data; /* user data */
   char *name;
   char *name;
-  /*double power;
+
+  /*  double power;
     double available_power;*/
     double available_power;*/
-  /* TODO: route */
 } s_SG_workstation_t, *SG_workstation_t;
 
 /* Task state */
 } s_SG_workstation_t, *SG_workstation_t;
 
 /* Task state */
index 90ed019..609f689 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef SIMDAG_H
-#define SIMDAG_H
+#ifndef SIMDAG_SIMDAG_H
+#define SIMDAG_SIMDAG_H
 
 #include "simdag/datatypes.h"
 #include "xbt/misc.h"
 
 #include "simdag/datatypes.h"
 #include "xbt/misc.h"
@@ -8,20 +8,24 @@ SG_BEGIN_DECL()
 
 /************************** Link handling ***********************************/
 
 
 /************************** Link handling ***********************************/
 
-SG_link_t    SG_link_create(void *data, const char *name,/* double capacity,*/
-                           double bandwidth, double latency);
+/* private (called by SG_environment_create)
+SG_link_t    SG_link_create(void *data, const char *name,
+double bandwidth, double latency);*/
 void*        SG_link_get_data(SG_link_t link);
 void         SG_link_set_data(SG_link_t link, void *data);
 const char*  SG_link_get_name(SG_link_t link);
 double       SG_link_get_capacity(SG_link_t link);
 double       SG_link_get_current_bandwidth(SG_link_t link);
 double       SG_link_get_current_latency(SG_link_t link);
 void*        SG_link_get_data(SG_link_t link);
 void         SG_link_set_data(SG_link_t link, void *data);
 const char*  SG_link_get_name(SG_link_t link);
 double       SG_link_get_capacity(SG_link_t link);
 double       SG_link_get_current_bandwidth(SG_link_t link);
 double       SG_link_get_current_latency(SG_link_t link);
+/* private (called by SG_clean)
 void         SG_link_destroy(SG_link_t link);
 void         SG_link_destroy(SG_link_t link);
+*/
 
 /************************** Workstation handling ****************************/
 
 
 /************************** Workstation handling ****************************/
 
+/* private (called by SG_environment_create)
 SG_workstation_t   SG_workstation_create(void *data, const char *name, double power,
 SG_workstation_t   SG_workstation_create(void *data, const char *name, double power,
-                                        double available_power);
+  double available_power);*/
 SG_workstation_t   SG_workstation_get_by_name(const char *name);
 SG_workstation_t*  SG_workstation_get_list(void);
 int                SG_workstation_get_number(void);
 SG_workstation_t   SG_workstation_get_by_name(const char *name);
 SG_workstation_t*  SG_workstation_get_list(void);
 int                SG_workstation_get_number(void);
@@ -32,7 +36,9 @@ SG_link_t*         SG_workstation_route_get_list(SG_workstation_t src, SG_workst
 int                SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst);
 double             SG_workstation_get_power(SG_workstation_t workstation);
 double             SG_workstation_get_available_power(SG_workstation_t workstation);
 int                SG_workstation_route_get_size(SG_workstation_t src, SG_workstation_t dst);
 double             SG_workstation_get_power(SG_workstation_t workstation);
 double             SG_workstation_get_available_power(SG_workstation_t workstation);
+/* private (called by SG_clean)
 void               SG_workstation_destroy(SG_workstation_t workstation);
 void               SG_workstation_destroy(SG_workstation_t workstation);
+*/
 
 /************************** Task handling ************************************/
 
 
 /************************** Task handling ************************************/
 
@@ -62,7 +68,9 @@ void              SG_task_destroy(SG_task_t task);
 /************************** Global *******************************************/
 
 void              SG_init(int *argc, char **argv);
 /************************** Global *******************************************/
 
 void              SG_init(int *argc, char **argv);
+void              SG_create_environment(const char *platform_file);
 SG_task_t         *SG_simulate(double how_long); /* returns a NULL-terminated array of SG_task_t whose state has changed */
 SG_task_t         *SG_simulate(double how_long); /* returns a NULL-terminated array of SG_task_t whose state has changed */
+void              SG_clean(); /* cleans everything */
 
 SG_END_DECL()
 
 
 SG_END_DECL()
 
index e032bdc..c86ff69 100644 (file)
@@ -2,6 +2,10 @@
 #define SIMDAG_PRIVATE_H
 
 #include "xbt/dict.h"
 #define SIMDAG_PRIVATE_H
 
 #include "xbt/dict.h"
+#include "simdag/simdag.h"
+#include "simdag/datatypes.h"
+
+/* Global variables */
 
 typedef struct SG_global {
   xbt_dict_t workstations; /* workstation list */
 
 typedef struct SG_global {
   xbt_dict_t workstations; /* workstation list */
@@ -10,4 +14,24 @@ typedef struct SG_global {
 
 extern SG_global_t sg_global;
 
 
 extern SG_global_t sg_global;
 
+/* Link private data */
+typedef struct SG_link_data {
+  void* surf_link; /* surf object */
+
+} s_SG_link_data_t;
+
+/* Workstation private data */
+typedef struct SG_workstation_data {
+  void* surf_workstation; /* surf object */
+  /* TODO: route */
+} s_SG_workstation_data_t;
+
+/* Private functions */
+
+SG_link_t __SG_link_create(const char *name, void *surf_link, void *data);
+void __SG_link_destroy(SG_link_t link);
+
+SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data);
+void __SG_workstation_destroy(SG_workstation_t workstation);
+
 #endif
 #endif
index 332e26c..985797b 100644 (file)
@@ -4,6 +4,10 @@
 #include "xbt/sysdep.h"
 #include "surf/surf.h"
 
 #include "xbt/sysdep.h"
 #include "surf/surf.h"
 
+#define CHECK_INIT_DONE() xbt_assert0(init_done, "SG_init not called yet")
+
+SG_global_t sg_global = NULL;
+
 static int init_done = 0;
 
 /* Initialises SG internal data. This function should be called before any other SG function.
 static int init_done = 0;
 
 /* Initialises SG internal data. This function should be called before any other SG function.
@@ -20,20 +24,24 @@ void SG_init(int *argc, char **argv) {
   init_done = 1;
 }
 
   init_done = 1;
 }
 
-/* Checks that SG_init has been called.
- */
-void check_init_done() {
-  xbt_assert0(init_done, "SG_init not called yet");
-}
-
 /* Creates the environnement described in a xml file of a platform descriptions.
  */
 /* Creates the environnement described in a xml file of a platform descriptions.
  */
-void SG_create_environnement(const char *platform_file) {
-  check_init_done();
+void SG_create_environment(const char *platform_file) {
+  xbt_dict_cursor_t cursor = NULL;
+  char *name = NULL;
+  void *workstation = NULL;
+
+  CHECK_INIT_DONE();
   surf_timer_resource_init(platform_file);
   surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */
   surf_timer_resource_init(platform_file);
   surf_workstation_resource_init_KCCFLN05(platform_file); /* tell Surf to create the environnement */
-}
 
 
+  /* now let's create the SG wrappers */
+  xbt_dict_foreach(workstation_set, cursor, name, workstation) {
+    
+    __SG_workstation_create(name, workstation, NULL);
+  }
+
+}
 
 /* Launches the simulation. Returns a NULL-terminated array of SG_task_t whose state has changed.
  */
 
 /* Launches the simulation. Returns a NULL-terminated array of SG_task_t whose state has changed.
  */
@@ -42,3 +50,14 @@ SG_task_t* SG_simulate(double how_long)
   /* TODO */
   return NULL;
 }
   /* TODO */
   return NULL;
 }
+
+/* Destroys all SG data. This function should be called when the simulation is over.
+ */
+void SG_clean() {
+  if (init_done) {
+    xbt_dict_free(&sg_global->workstations);
+    xbt_free(sg_global);
+    surf_exit();
+    /* TODO: destroy the workstations, the links and the tasks */
+  }
+}
index 272ceba..fcfc578 100644 (file)
@@ -1,15 +1,19 @@
+#include "private.h"
 #include "simdag/simdag.h"
 #include "xbt/sysdep.h" /* xbt_new0 */
 
 /* Creates a link.
  */
 #include "simdag/simdag.h"
 #include "xbt/sysdep.h" /* xbt_new0 */
 
 /* Creates a link.
  */
-SG_link_t SG_link_create(void *data, const char *name,/* double capacity,*/ double bandwidth, double latency) {
-  /*  xbt_assert0(capacity >= 0, "Invalid parameter");*/ /* or capacity > 0 ? */
+SG_link_t __SG_link_create(const char *name, void *surf_link, void *data) {
+  xbt_assert0(surf_link != NULL, "surf_link is NULL !");
+  SG_link_data_t sgdata = xbt_new0(s_SG_link_data_t, 1); /* link private data */
+  sgdata->surf_link = surf_link;
 
   SG_link_t link = xbt_new0(s_SG_link_t, 1);
 
   SG_link_t link = xbt_new0(s_SG_link_t, 1);
-
-  link->data = data;
   link->name = xbt_strdup(name);
   link->name = xbt_strdup(name);
+  link->data = data;
+  link->sgdata = sgdata;
+
   /*link->capacity = capacity;*/
   /* link->current_bandwidth = bandwidth;
      link->current_latency = latency;*/
   /*link->capacity = capacity;*/
   /* link->current_bandwidth = bandwidth;
      link->current_latency = latency;*/
@@ -68,11 +72,11 @@ double SG_link_get_current_latency(SG_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 SG_link_destroy(SG_link_t link) {
+void __SG_link_destroy(SG_link_t link) {
   xbt_assert0(link, "Invalid parameter");
 
   if (link->name)
   xbt_assert0(link, "Invalid parameter");
 
   if (link->name)
-    free(link->name);
+    xbt_free(link->name);
 
 
-  free(link);
+  xbt_free(link);
 }
 }
index d4a81dd..3a22af5 100644 (file)
@@ -119,8 +119,8 @@ void SG_task_unschedule(SG_task_t task) {
  */
 void SG_task_destroy(SG_task_t task) {
   if (task->name)
  */
 void SG_task_destroy(SG_task_t task) {
   if (task->name)
-    free(task->name);
+    xbt_free(task->name);
 
   /* TODO: dependencies + watch */
 
   /* TODO: dependencies + watch */
-  free(task);
+  xbt_free(task);
 }
 }
index 38ffb85..42b93b4 100644 (file)
@@ -1,20 +1,21 @@
+#include "private.h"
 #include "simdag/simdag.h"
 #include "xbt/dict.h"
 #include "xbt/sysdep.h"
 #include "simdag/simdag.h"
 #include "xbt/dict.h"
 #include "xbt/sysdep.h"
-#include "private.h"
 
 
-/* Creates a workstation.
+/* Creates a workstation and registers it in SG.
  */
  */
-SG_workstation_t SG_workstation_create(void *data, const char *name, double power,
-                                     double available_power) {
-  xbt_assert0(power >= 0 && available_power >= 0, "Invalid parameter"); /* or > 0 ? */
-
-  SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1);
+SG_workstation_t __SG_workstation_create(const char *name, void *surf_workstation, void *data) {
+  SG_workstation_data_t sgdata = xbt_new0(s_SG_workstation_data_t, 1); /* workstation private data */
+  sgdata->surf_workstation = surf_workstation;
   
   
-  workstation->data = data;
+  SG_workstation_t workstation = xbt_new0(s_SG_workstation_t, 1);
   workstation->name = xbt_strdup(name);
   workstation->name = xbt_strdup(name);
-  /*workstation->power = power;
-  workstation->available_power = power;*/
+  workstation->data = data; /* user data */
+  workstation->sgdata = sgdata; /* private data */
+  
+  xbt_dict_set(sg_global->workstations, name, workstation, free); /* add the workstation to the dictionary */
+
   /* TODO: route */
 
   return workstation;
   /* TODO: route */
 
   return workstation;
@@ -73,7 +74,8 @@ void* SG_workstation_get_data(SG_workstation_t workstation) {
  */
 const char* SG_workstation_get_name(SG_workstation_t workstation) {
   xbt_assert0(workstation != NULL, "Invalid parameter");
  */
 const char* SG_workstation_get_name(SG_workstation_t workstation) {
   xbt_assert0(workstation != NULL, "Invalid parameter");
-  return workstation->name;
+  return NULL;
+  /*  return workstation->name;*/
 }
 
 SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
 }
 
 SG_link_t* SG_workstation_route_get_list(SG_workstation_t src, SG_workstation_t dst) {
@@ -106,13 +108,15 @@ double SG_workstation_get_available_power(SG_workstation_t workstation) {
 
 /* Destroys a workstation. The user data (if any) should have been destroyed first.
  */
 
 /* Destroys a workstation. The user data (if any) should have been destroyed first.
  */
-void SG_workstation_destroy(SG_workstation_t workstation) {
+void __SG_workstation_destroy(SG_workstation_t workstation) {
   xbt_assert0(workstation != NULL, "Invalid parameter");
 
   xbt_assert0(workstation != NULL, "Invalid parameter");
 
-  if (workstation->name)
-    free(workstation->name);
-
+  SG_workstation_data_t sgdata = workstation->sgdata;
+  if (sgdata != NULL) {
+    xbt_free(sgdata);
+  }
+  
   /* TODO: route */
 
   /* TODO: route */
 
-  free(workstation);
+  xbt_free(workstation);
 }
 }