Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do connect all log channel manually to parent using XBT_LOG_CONNECT() too, so that...
[simgrid.git] / src / surf / surf.c
index aad2569..b46ade3 100644 (file)
@@ -125,15 +125,7 @@ const char *surf_action_state_names[6] = {
   "SURF_ACTION_NOT_IN_THE_SYSTEM"
 };
 
-int surf_network_model_description_size = 3
-#ifdef HAVE_GTNETS
-    + 1
-#endif
-#ifdef HAVE_SDP
-    + 1
-#endif
-    ;
-s_surf_model_description_t surf_network_model_description[] = {
+s_surf_model_description_t surf_network_model_description[surf_network_model_description_size] = {
   {"CM02", NULL, surf_network_model_init_CM02},
 #ifdef HAVE_GTNETS
   {"GTNets", NULL, surf_network_model_init_GTNETS},
@@ -145,17 +137,14 @@ s_surf_model_description_t surf_network_model_description[] = {
   {"Vegas", NULL, surf_network_model_init_Vegas}
 };
 
-int surf_cpu_model_description_size = 1;
-s_surf_model_description_t surf_cpu_model_description[] = {
+s_surf_model_description_t surf_cpu_model_description[surf_cpu_model_description_size] = {
   {"Cas01", NULL, surf_cpu_model_init_Cas01},
 };
 
-int surf_workstation_model_description_size = 4;
-s_surf_model_description_t surf_workstation_model_description[] = {
-  {"CLM03", NULL, surf_workstation_model_init_CLM03},
-  {"KCCFLN05", NULL, surf_workstation_model_init_KCCFLN05},
-  {"compound", NULL, surf_workstation_model_init_compound},
-  {"ptask_L07", NULL, surf_workstation_model_init_ptask_L07}
+s_surf_model_description_t surf_workstation_model_description[surf_workstation_model_description_size] = {
+  {"CLM03", NULL, surf_workstation_model_init_CLM03, create_workstations},
+  {"compound", NULL, surf_workstation_model_init_compound, NULL},
+  {"ptask_L07", NULL, surf_workstation_model_init_ptask_L07, NULL}
 };
 
 void update_model_description(s_surf_model_description_t * table,
@@ -190,16 +179,9 @@ int find_model_description(s_surf_model_description_t * table,
 }
 
 double generic_maxmin_share_resources(xbt_swag_t running_actions,
-                                     size_t offset)
-{
-  return generic_maxmin_share_resources2(running_actions, offset,
-                                        maxmin_system, lmm_solve);
-}
-
-double generic_maxmin_share_resources2(xbt_swag_t running_actions,
-                                      size_t offset,
-                                      lmm_system_t sys,
-                                      void (*solve) (lmm_system_t))
+                                     size_t offset,
+                                     lmm_system_t sys,
+                                     void (*solve) (lmm_system_t))
 {
   surf_action_t action = NULL;
   double min = -1;
@@ -325,6 +307,20 @@ void surf_init(int *argc, char **argv)
 
   const char *initial_path;
 
+  /* Connect our log channels: that must be done manually under windows */
+  XBT_LOG_CONNECT(surf_cpu, surf);
+  XBT_LOG_CONNECT(surf_kernel, surf);
+  XBT_LOG_CONNECT(surf_lagrange_dichotomy, surf_lagrange);
+  XBT_LOG_CONNECT(surf_lagrange, surf);
+  XBT_LOG_CONNECT(surf_maxmin, surf);
+  XBT_LOG_CONNECT(surf_network_gtnets, surf);
+  XBT_LOG_CONNECT(surf_network, surf);
+  XBT_LOG_CONNECT(surf_parse, surf);
+  XBT_LOG_CONNECT(surf_sdp_out, surf);
+  XBT_LOG_CONNECT(surf_sdp, surf);
+  XBT_LOG_CONNECT(surf_timer, surf);
+  XBT_LOG_CONNECT(surf_workstation, surf);
+   
   xbt_init(argc, argv);
   if (!surf_path) {
 
@@ -361,10 +357,10 @@ void surf_init(int *argc, char **argv)
 static char *path_name = NULL;
 FILE *surf_fopen(const char *name, const char *mode)
 {
-  int i;
+  unsigned int iter;
   char *path = NULL;
   FILE *file = NULL;
-  int path_name_len = 0;       /* don't count '\0' */
+  unsigned int path_name_len = 0;      /* don't count '\0' */
 
   xbt_assert0(name, "Need a non-NULL file name");
 
@@ -381,12 +377,16 @@ FILE *surf_fopen(const char *name, const char *mode)
       path_name = xbt_new0(char, path_name_len + 1);
     }
 
-    xbt_dynar_foreach(surf_path, i, path) {
+    xbt_dynar_foreach(surf_path, iter, path) {
       if (path_name_len < strlen(path) + strlen(name) + 1) {
        path_name_len = strlen(path) + strlen(name) + 1;        /* plus '/' */
        path_name = xbt_realloc(path_name, path_name_len + 1);
       }
+      #ifdef WIN32
+      sprintf(path_name, "%s\\%s", path, name);
+      #else
       sprintf(path_name, "%s/%s", path, name);
+      #endif
       file = fopen(path_name, mode);
       if (file)
        return file;
@@ -397,10 +397,10 @@ FILE *surf_fopen(const char *name, const char *mode)
 
 void surf_exit(void)
 {
-  int i;
+  unsigned int iter;
   surf_model_t model = NULL;
 
-  xbt_dynar_foreach(model_list, i, model) {
+  xbt_dynar_foreach(model_list, iter, model) {
     model->common_private->finalize();
   }
 
@@ -424,6 +424,9 @@ void surf_exit(void)
     free(path_name);
     path_name = NULL;
   }
+  surf_parse_free_callbacks();
+  xbt_dict_free(&route_table);
+  NOW=0; /* Just in case the user plans to restart the simulation afterward */
   xbt_exit();
 }
 
@@ -438,7 +441,7 @@ double surf_solve(void)
   surf_model_object_t model_obj = NULL;
   surf_model_t model = NULL;
   tmgr_trace_event_t event = NULL;
-  int i;
+  unsigned int iter;
 
   if (first_run) {
     DEBUG0
@@ -454,7 +457,7 @@ double surf_solve(void)
            update_resource_state(model_obj, event, value);
       }
     }
-    xbt_dynar_foreach(model_list, i, model) {
+    xbt_dynar_foreach(model_list, iter, model) {
       model->common_private->update_actions_state(NOW, 0.0);
     }
     first_run = 0;
@@ -464,7 +467,7 @@ double surf_solve(void)
   min = -1.0;
 
   DEBUG0("Looking for next action end");
-  xbt_dynar_foreach(model_list, i, model) {
+  xbt_dynar_foreach(model_list, iter, model) {
     DEBUG1("Running for Resource [%s]", model->common_public->name);
     model_next_action_end =
        model->common_private->share_resources(NOW);
@@ -507,7 +510,7 @@ double surf_solve(void)
 
   NOW = NOW + min;
 
-  xbt_dynar_foreach(model_list, i, model) {
+  xbt_dynar_foreach(model_list, iter, model) {
     model->common_private->update_actions_state(NOW, min);
   }