Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added a gtnets_jitter_seed parameter enabling jitted repeatable experiments, activate...
[simgrid.git] / src / surf / network.c
index 225a7e7..b32a57c 100644 (file)
@@ -20,12 +20,9 @@ double latency_factor = 1.0;    /* default value */
 double bandwidth_factor = 1.0;  /* default value */
 double weight_S_parameter = 0.0;        /* default value */
 
-int card_number = 0;
-int host_count = 0;
 double sg_tcp_gamma = 0.0;
 
 
-
 static link_CM02_t link_new(char *name,
                             double bw_initial,
                             tmgr_trace_t bw_trace,
@@ -39,11 +36,12 @@ static link_CM02_t link_new(char *name,
 {
   link_CM02_t nw_link = (link_CM02_t)
     surf_resource_lmm_new(sizeof(s_link_CM02_t),
-        surf_network_model,name,properties,
-        network_maxmin_system, bandwidth_factor * bw_initial,
-        history,
-        state_initial,state_trace,
-        bw_initial,bw_trace);
+                          surf_network_model, name, properties,
+                          network_maxmin_system,
+                          bandwidth_factor * bw_initial,
+                          history,
+                          state_initial, state_trace,
+                          bw_initial, bw_trace);
 
   xbt_assert1(!xbt_dict_get_or_null(surf_network_model->resource_set, name),
               "Link '%s' declared several times in the platform file.", name);
@@ -56,7 +54,8 @@ static link_CM02_t link_new(char *name,
   if (policy == SURF_LINK_FATPIPE)
     lmm_constraint_shared(nw_link->lmm_resource.constraint);
 
-  xbt_dict_set(surf_network_model->resource_set, name, nw_link, surf_resource_free);
+  xbt_dict_set(surf_network_model->resource_set, name, nw_link,
+               surf_resource_free);
 
   return nw_link;
 }
@@ -113,31 +112,36 @@ static void add_traces(void)
   /* connect all traces relative to network */
   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
+    link_CM02_t link =
+      xbt_dict_get_or_null(surf_network_model->resource_set, elm);
 
     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
                 trace_name, elm);
     xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined",
                 trace_name, elm);
 
-    link->lmm_resource.state_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->lmm_resource.state_event =
+      tmgr_history_add_trace(history, trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
+    link_CM02_t link =
+      xbt_dict_get_or_null(surf_network_model->resource_set, elm);
 
     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
                 trace_name, elm);
     xbt_assert2(trace, "Cannot connect trace %s to link %s: trace undefined",
                 trace_name, elm);
 
-    link->lmm_resource.power.event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
+    link->lmm_resource.power.event =
+      tmgr_history_add_trace(history, trace, 0.0, 0, link);
   }
 
   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
-    link_CM02_t link = xbt_dict_get_or_null(surf_network_model->resource_set, elm);
+    link_CM02_t link =
+      xbt_dict_get_or_null(surf_network_model->resource_set, elm);
 
     xbt_assert2(link, "Cannot connect trace %s to link %s: link undefined",
                 trace_name, elm);
@@ -185,6 +189,11 @@ static void action_recycle(surf_action_t action)
   return;
 }
 
+static double action_get_remains(surf_action_t action)
+{
+  return action->remains;
+}
+
 static double share_resources(double now)
 {
   s_surf_action_network_CM02_t s_action;
@@ -244,11 +253,13 @@ static void update_actions_state(double now, double delta)
     if ((action->generic_action.remains <= 0) &&
         (lmm_get_variable_weight(action->variable) > 0)) {
       action->generic_action.finish = surf_get_clock();
-      surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE);
-    } else if ((action->generic_action.max_duration != NO_MAX_DURATION) &&
-               (action->generic_action.max_duration <= 0)) {
+      surf_network_model->action_state_set((surf_action_t) action,
+                                           SURF_ACTION_DONE);
+    } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
+               && (action->generic_action.max_duration <= 0)) {
       action->generic_action.finish = surf_get_clock();
-      surf_network_model->action_state_set((surf_action_t) action, SURF_ACTION_DONE);
+      surf_network_model->action_state_set((surf_action_t) action,
+                                           SURF_ACTION_DONE);
     }
   }
 
@@ -266,17 +277,22 @@ static void update_resource_state(void *id,
 
   if (event_type == nw_link->lmm_resource.power.event) {
     double delta =
-      weight_S_parameter / value - weight_S_parameter / nw_link->lmm_resource.power.current;
+      weight_S_parameter / value - weight_S_parameter /
+      (nw_link->lmm_resource.power.peak * nw_link->lmm_resource.power.scale);
     lmm_variable_t var = NULL;
     lmm_element_t elem = NULL;
     surf_action_network_CM02_t action = NULL;
 
-    nw_link->lmm_resource.power.current = value;
-    lmm_update_constraint_bound(network_maxmin_system, nw_link->lmm_resource.constraint,
-                                bandwidth_factor * nw_link->lmm_resource.power.current);
+    nw_link->lmm_resource.power.peak = value;
+    lmm_update_constraint_bound(network_maxmin_system,
+                                nw_link->lmm_resource.constraint,
+                                bandwidth_factor *
+                                (nw_link->lmm_resource.power.peak *
+                                 nw_link->lmm_resource.power.scale));
     if (weight_S_parameter > 0) {
       while ((var = lmm_get_var_from_cnst
-              (network_maxmin_system, nw_link->lmm_resource.constraint, &elem))) {
+              (network_maxmin_system, nw_link->lmm_resource.constraint,
+               &elem))) {
         action = lmm_variable_id(var);
         action->weight += delta;
         if (!(action->suspended))
@@ -284,6 +300,8 @@ static void update_resource_state(void *id,
                                      action->weight);
       }
     }
+    if (tmgr_trace_event_free(event_type))
+      nw_link->lmm_resource.power.event = NULL;
   } else if (event_type == nw_link->lat_event) {
     double delta = value - nw_link->lat_current;
     lmm_variable_t var = NULL;
@@ -292,7 +310,8 @@ static void update_resource_state(void *id,
 
     nw_link->lat_current = value;
     while ((var = lmm_get_var_from_cnst
-            (network_maxmin_system, nw_link->lmm_resource.constraint, &elem))) {
+            (network_maxmin_system, nw_link->lmm_resource.constraint,
+             &elem))) {
       action = lmm_variable_id(var);
       action->lat_current += delta;
       action->weight += delta;
@@ -309,6 +328,8 @@ static void update_resource_state(void *id,
                                    action->weight);
 
     }
+    if (tmgr_trace_event_free(event_type))
+      nw_link->lat_event = NULL;
   } else if (event_type == nw_link->lmm_resource.state_event) {
     if (value > 0)
       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
@@ -329,6 +350,8 @@ static void update_resource_state(void *id,
         }
       }
     }
+    if (tmgr_trace_event_free(event_type))
+      nw_link->lmm_resource.state_event = NULL;
   } else {
     CRITICAL0("Unknown event ! \n");
     xbt_abort();
@@ -337,8 +360,8 @@ static void update_resource_state(void *id,
   return;
 }
 
-static surf_action_t communicate(const char *src_name, const char *dst_name,int src, int dst, double size,
-                                 double rate)
+static surf_action_t communicate(const char *src_name, const char *dst_name,
+                                 int src, int dst, double size, double rate)
 {
   surf_action_network_CM02_t action = NULL;
   /* LARGE PLATFORMS HACK:
@@ -357,24 +380,28 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int
               src_name, dst_name);
 
   link_CM02_t link;
-  int failed=0;
-  xbt_dynar_foreach(route,i,link) {
+  int failed = 0;
+  xbt_dynar_foreach(route, i, link) {
     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
       failed = 1;
       break;
     }
   }
-  action = surf_action_new(sizeof(s_surf_action_network_CM02_t),size,surf_network_model,failed);
+  action =
+    surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
+                    surf_network_model, failed);
 
   xbt_swag_insert(action, action->generic_action.state_set);
   action->rate = rate;
 
   action->latency = 0.0;
   action->weight = 0.0;
-  xbt_dynar_foreach(route,i,link) {
+  xbt_dynar_foreach(route, i, link) {
     action->latency += link->lat_current;
     action->weight +=
-      link->lat_current + weight_S_parameter / link->lmm_resource.power.current;
+      link->lat_current +
+      weight_S_parameter /
+      (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
   }
   /* LARGE PLATFORMS HACK:
      Add src->link and dst->link latencies */
@@ -385,10 +412,12 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int
      lmm_variable_new(..., total_route_size) */
   if (action->latency > 0)
     action->variable =
-      lmm_variable_new(network_maxmin_system, action, 0.0, -1.0, xbt_dynar_length(route));
+      lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
+                       xbt_dynar_length(route));
   else
     action->variable =
-      lmm_variable_new(network_maxmin_system, action, 1.0, -1.0, xbt_dynar_length(route));
+      lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
+                       xbt_dynar_length(route));
 
   if (action->rate < 0) {
     if (action->lat_current > 0)
@@ -408,7 +437,7 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int
                                 action->rate);
   }
 
-  xbt_dynar_foreach(route,i,link) {
+  xbt_dynar_foreach(route, i, link) {
     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
                action->variable, 1.0);
   }
@@ -422,7 +451,8 @@ static surf_action_t communicate(const char *src_name, const char *dst_name,int
 
 static double get_link_bandwidth(const void *link)
 {
-  return ((link_CM02_t) link)->lmm_resource.power.current;
+  surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
+  return lmm->power.peak * lmm->power.scale;
 }
 
 static double get_link_latency(const void *link)
@@ -470,7 +500,6 @@ static void finalize(void)
   surf_network_model = NULL;
 
   used_routing->finalize();
-  host_count = 0;
   lmm_system_free(network_maxmin_system);
   network_maxmin_system = NULL;
 }
@@ -483,6 +512,7 @@ static void surf_network_model_init_internal(void)
   surf_network_model->action_unref = action_unref;
   surf_network_model->action_cancel = action_cancel;
   surf_network_model->action_recycle = action_recycle;
+  surf_network_model->get_remains = action_get_remains;
 
   surf_network_model->model_private->resource_used = resource_used;
   surf_network_model->model_private->share_resources = share_resources;
@@ -507,9 +537,10 @@ static void surf_network_model_init_internal(void)
     network_maxmin_system = lmm_system_new();
 
   routing_model_create(sizeof(link_CM02_t),
-      link_new(xbt_strdup("__loopback__"),
-          498000000, NULL, 0.000015, NULL,
-          SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE, NULL));
+                       link_new(xbt_strdup("__loopback__"),
+                                498000000, NULL, 0.000015, NULL,
+                                SURF_RESOURCE_ON, NULL, SURF_LINK_FATPIPE,
+                                NULL));
 }
 
 /************************************************************************/
@@ -530,7 +561,7 @@ void surf_network_model_init_LegrandVelho(const char *filename)
   weight_S_parameter = 8775;
 
   update_model_description(surf_network_model_description,
-                           "LegrandVelho", surf_network_model);
+                           "LV08", surf_network_model);
 }
 
 /***************************************************************************/
@@ -617,19 +648,3 @@ void surf_network_model_init_Vegas(const char *filename)
   update_model_description(surf_network_model_description,
                            "Vegas", surf_network_model);
 }
-
-#ifdef HAVE_SDP
-void surf_network_model_init_SDP(const char *filename)
-{
-  if (surf_network_model)
-    return;
-  surf_network_model_init_internal();
-  define_callbacks(filename);
-
-  xbt_dynar_push(model_list, &surf_network_model);
-  network_solve = sdp_solve;
-
-  update_model_description(surf_network_model_description,
-                           "SDP", surf_network_model);
-}
-#endif