Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Ansi C declaration of the variables (at the beginning of the blocks)
[simgrid.git] / src / surf / surf.c
index f80dadd..84ccf39 100644 (file)
@@ -189,17 +189,10 @@ int find_model_description(s_surf_model_description_t * table,
              name_list);
 }
 
              name_list);
 }
 
-double generic_maxmin_share_models(xbt_swag_t running_actions,
-                                     size_t offset)
-{
-  return generic_maxmin_share_models2(running_actions, offset,
-                                        maxmin_system, lmm_solve);
-}
-
-double generic_maxmin_share_models2(xbt_swag_t running_actions,
-                                      size_t offset,
-                                      lmm_system_t sys,
-                                      void (*solve) (lmm_system_t))
+double generic_maxmin_share_resources(xbt_swag_t running_actions,
+                                     size_t offset,
+                                     lmm_system_t sys,
+                                     void (*solve) (lmm_system_t))
 {
   surf_action_t action = NULL;
   double min = -1;
 {
   surf_action_t action = NULL;
   double min = -1;
@@ -356,17 +349,15 @@ void surf_init(int *argc, char **argv)
     model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
   if (!history)
     history = tmgr_history_new();
     model_list = xbt_dynar_new(sizeof(surf_model_private_t), NULL);
   if (!history)
     history = tmgr_history_new();
-  if (!maxmin_system)
-    maxmin_system = lmm_system_new();
 }
 
 static char *path_name = NULL;
 FILE *surf_fopen(const char *name, const char *mode)
 {
 }
 
 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;
   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");
 
 
   xbt_assert0(name, "Need a non-NULL file name");
 
@@ -383,12 +374,16 @@ FILE *surf_fopen(const char *name, const char *mode)
       path_name = xbt_new0(char, path_name_len + 1);
     }
 
       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);
       }
       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);
       sprintf(path_name, "%s/%s", path, name);
+      #endif
       file = fopen(path_name, mode);
       if (file)
        return file;
       file = fopen(path_name, mode);
       if (file)
        return file;
@@ -399,10 +394,10 @@ FILE *surf_fopen(const char *name, const char *mode)
 
 void surf_exit(void)
 {
 
 void surf_exit(void)
 {
-  int i;
+  unsigned int iter;
   surf_model_t model = NULL;
 
   surf_model_t model = NULL;
 
-  xbt_dynar_foreach(model_list, i, model) {
+  xbt_dynar_foreach(model_list, iter, model) {
     model->common_private->finalize();
   }
 
     model->common_private->finalize();
   }
 
@@ -426,6 +421,9 @@ void surf_exit(void)
     free(path_name);
     path_name = NULL;
   }
     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();
 }
 
   xbt_exit();
 }
 
@@ -440,7 +438,7 @@ double surf_solve(void)
   surf_model_object_t model_obj = NULL;
   surf_model_t model = NULL;
   tmgr_trace_event_t event = NULL;
   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
 
   if (first_run) {
     DEBUG0
@@ -453,10 +451,10 @@ double surf_solve(void)
                                              &value,
                                              (void **) &model_obj))) {
        model_obj->model->common_private->
                                              &value,
                                              (void **) &model_obj))) {
        model_obj->model->common_private->
-           update_model_state(model_obj, event, value);
+           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;
       model->common_private->update_actions_state(NOW, 0.0);
     }
     first_run = 0;
@@ -466,10 +464,10 @@ double surf_solve(void)
   min = -1.0;
 
   DEBUG0("Looking for next action end");
   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 =
     DEBUG1("Running for Resource [%s]", model->common_public->name);
     model_next_action_end =
-       model->common_private->share_models(NOW);
+       model->common_private->share_resources(NOW);
     DEBUG2("Resource [%s] : next action end = %f",
           model->common_public->name, model_next_action_end);
     if (((min < 0.0) || (model_next_action_end < min))
     DEBUG2("Resource [%s] : next action end = %f",
           model->common_public->name, model_next_action_end);
     if (((min < 0.0) || (model_next_action_end < min))
@@ -492,7 +490,7 @@ double surf_solve(void)
                                            &value,
                                            (void **) &model_obj))) {
       if (model_obj->model->common_private->
                                            &value,
                                            (void **) &model_obj))) {
       if (model_obj->model->common_private->
-         model_used(model_obj)) {
+         resource_used(model_obj)) {
        min = next_event_date - NOW;
        DEBUG1
            ("This event will modify model state. Next event set to %f",
        min = next_event_date - NOW;
        DEBUG1
            ("This event will modify model state. Next event set to %f",
@@ -501,7 +499,7 @@ double surf_solve(void)
       /* update state of model_obj according to new value. Does not touch lmm.
          It will be modified if needed when updating actions */
       model_obj->model->common_private->
       /* update state of model_obj according to new value. Does not touch lmm.
          It will be modified if needed when updating actions */
       model_obj->model->common_private->
-         update_model_state(model_obj, event, value);
+         update_resource_state(model_obj, event, value);
     }
   }
 
     }
   }
 
@@ -509,7 +507,7 @@ double surf_solve(void)
 
   NOW = NOW + min;
 
 
   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);
   }
 
     model->common_private->update_actions_state(NOW, min);
   }