Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use type network_element_t instead of void*, and avoid unnecessary casts.
[simgrid.git] / src / surf / network.c
1
2 /*
3  * Network with improved management of tasks, IM (Improved Management).
4  * Uses a heap to store actions so that the share_resources is faster.
5  * This model automatically sets the selective update flag to 1 and is
6  * highly dependent on the maxmin lmm module.
7  */
8
9 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
10  * All rights reserved.                                                     */
11
12 /* This program is free software; you can redistribute it and/or modify it
13  * under the terms of the license (GNU LGPL) which comes with this package. */
14
15 #include "network_private.h"
16 #include "xbt/log.h"
17 #include "xbt/str.h"
18
19 #include "surf_private.h"
20 #include "xbt/dict.h"
21 #include "maxmin_private.h"
22 #include "surf/surfxml_parse_values.h"
23 #include "surf/surf_resource.h"
24 #include "surf/surf_resource_lmm.h"
25
26 #undef GENERIC_LMM_ACTION
27 #undef GENERIC_ACTION
28 #define GENERIC_LMM_ACTION(action) (action)->generic_lmm_action
29 #define GENERIC_ACTION(action) GENERIC_LMM_ACTION(action).generic_action
30
31
32 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
33                                 "Logging specific to the SURF network module");
34
35 surf_model_t surf_network_model = NULL;
36 static lmm_system_t network_maxmin_system = NULL;
37 static void (*network_solve) (lmm_system_t) = NULL;
38
39 xbt_dynar_t smpi_bw_factor = NULL;
40 xbt_dynar_t smpi_lat_factor = NULL;
41
42 typedef struct s_smpi_factor *smpi_factor_t;
43 typedef struct s_smpi_factor {
44   long factor;
45   double value;
46 } s_smpi_factor_t;
47
48
49 double sg_sender_gap = 0.0;
50 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
51 double sg_bandwidth_factor = 1.0;       /* default value; can be set by model or from command line */
52 double sg_weight_S_parameter = 0.0;     /* default value; can be set by model or from command line */
53
54 double sg_tcp_gamma = 0.0;
55 int sg_network_crosstraffic = 0;
56
57 xbt_dict_t gap_lookup = NULL;
58
59 e_UM_t network_update_mechanism = UM_UNDEFINED;
60 static int net_selective_update = 0;
61
62 static int net_action_is_suspended(surf_action_t action);
63 static void net_update_action_remaining_lazy(double now);
64
65 static xbt_swag_t net_modified_set = NULL;
66 static xbt_heap_t net_action_heap = NULL;
67
68
69 /******************************************************************************/
70 /*                           Factors callbacks                                */
71 /******************************************************************************/
72 static double constant_latency_factor(double size)
73 {
74   return sg_latency_factor;
75 }
76
77 static double constant_bandwidth_factor(double size)
78 {
79   return sg_bandwidth_factor;
80 }
81
82 static double constant_bandwidth_constraint(double rate, double bound,
83                                             double size)
84 {
85   return rate;
86 }
87
88 /**********************/
89 /*   SMPI callbacks   */
90 /**********************/
91 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
92 {
93   char *value = NULL;
94   unsigned int iter = 0;
95   s_smpi_factor_t fact;
96   xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
97
98   smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
99   radical_elements = xbt_str_split(smpi_coef_string, ";");
100   xbt_dynar_foreach(radical_elements, iter, value) {
101
102     radical_elements2 = xbt_str_split(value, ":");
103     if (xbt_dynar_length(radical_elements2) != 2)
104       xbt_die("Malformed radical for smpi factor!");
105     fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
106     fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
107     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
108     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
109     xbt_dynar_free(&radical_elements2);
110   }
111   xbt_dynar_free(&radical_elements);
112   return smpi_factor;
113 }
114
115 static double smpi_bandwidth_factor(double size)
116 {
117   if (!smpi_bw_factor)
118     smpi_bw_factor =
119         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/bw_factor"));
120
121   unsigned int iter = 0;
122   s_smpi_factor_t fact;
123   xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
124     if (size >= fact.factor) {
125       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
126       return fact.value;
127     }
128   }
129
130   return 1.0;
131 }
132
133 static double smpi_latency_factor(double size)
134 {
135   if (!smpi_lat_factor)
136     smpi_lat_factor =
137         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/lat_factor"));
138
139   unsigned int iter = 0;
140   s_smpi_factor_t fact;
141   xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
142     if (size >= fact.factor) {
143       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
144       return fact.value;
145     }
146   }
147
148   return 1.0;
149 }
150
151 /**--------- <copy/paste C code snippet in surf/network.c> -----------*/
152
153 static double smpi_bandwidth_constraint(double rate, double bound,
154                                         double size)
155 {
156   return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
157 }
158
159 static double (*latency_factor_callback) (double) =
160     &constant_latency_factor;
161 static double (*bandwidth_factor_callback) (double) =
162     &constant_bandwidth_factor;
163 static double (*bandwidth_constraint_callback) (double, double, double) =
164     &constant_bandwidth_constraint;
165
166 static void (*gap_append) (double, const link_CM02_t,
167                            surf_action_network_CM02_t) = NULL;
168 static void (*gap_remove) (surf_action_network_CM02_t) = NULL;
169
170 static void *net_create_resource(const char *name,
171                                  double bw_initial,
172                                  tmgr_trace_t bw_trace,
173                                  double lat_initial,
174                                  tmgr_trace_t lat_trace,
175                                  e_surf_resource_state_t
176                                  state_initial,
177                                  tmgr_trace_t state_trace,
178                                  e_surf_link_sharing_policy_t
179                                  policy, xbt_dict_t properties)
180 {
181   link_CM02_t nw_link = (link_CM02_t)
182       surf_resource_lmm_new(sizeof(s_link_CM02_t),
183                             surf_network_model, name, properties,
184                             network_maxmin_system,
185                             sg_bandwidth_factor * bw_initial,
186                             history,
187                             state_initial, state_trace,
188                             bw_initial, bw_trace);
189
190   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
191              "Link '%s' declared several times in the platform file.",
192              name);
193
194   nw_link->lat_current = lat_initial;
195   if (lat_trace)
196     nw_link->lat_event =
197         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
198
199   if (policy == SURF_LINK_FATPIPE)
200     lmm_constraint_shared(nw_link->lmm_resource.constraint);
201
202   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
203   XBT_DEBUG("Create link '%s'",name);
204
205   return nw_link;
206 }
207
208 static void net_parse_link_init(sg_platf_link_cbarg_t link)
209 {
210   if (link->policy == SURF_LINK_FULLDUPLEX) {
211     char *link_id;
212     link_id = bprintf("%s_UP", link->id);
213     net_create_resource(link_id,
214                         link->bandwidth,
215                         link->bandwidth_trace,
216                         link->latency,
217                         link->latency_trace,
218                         link->state,
219                         link->state_trace, link->policy, link->properties);
220     xbt_free(link_id);
221     link_id = bprintf("%s_DOWN", link->id);
222     net_create_resource(link_id,
223                         link->bandwidth,
224                         link->bandwidth_trace,
225                         link->latency,
226                         link->latency_trace,
227                         link->state,
228                         link->state_trace, link->policy, link->properties);
229     xbt_free(link_id);
230   } else {
231     net_create_resource(link->id,
232                         link->bandwidth,
233                         link->bandwidth_trace,
234                         link->latency,
235                         link->latency_trace,
236                         link->state,
237                         link->state_trace, link->policy, link->properties);
238   }
239 }
240
241 static void net_add_traces(void)
242 {
243   xbt_dict_cursor_t cursor = NULL;
244   char *trace_name, *elm;
245
246   static int called = 0;
247   if (called)
248     return;
249   called = 1;
250
251   /* connect all traces relative to network */
252   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
253     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
254     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
255
256     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
257                trace_name, elm);
258     xbt_assert(trace,
259                "Cannot connect trace %s to link %s: trace undefined",
260                trace_name, elm);
261
262     link->lmm_resource.state_event =
263         tmgr_history_add_trace(history, trace, 0.0, 0, link);
264   }
265
266   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
267     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
268     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
269
270     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
271                trace_name, elm);
272     xbt_assert(trace,
273                "Cannot connect trace %s to link %s: trace undefined",
274                trace_name, elm);
275
276     link->lmm_resource.power.event =
277         tmgr_history_add_trace(history, trace, 0.0, 0, link);
278   }
279
280   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
281     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
282     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
283
284     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
285                trace_name, elm);
286     xbt_assert(trace,
287                "Cannot connect trace %s to link %s: trace undefined",
288                trace_name, elm);
289
290     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
291   }
292 }
293
294 static void net_define_callbacks(void)
295 {
296   /* Figuring out the network links */
297   sg_platf_link_add_cb(net_parse_link_init);
298   sg_platf_postparse_add_cb(net_add_traces);
299 }
300
301 static int net_resource_used(void *resource_id)
302 {
303   return lmm_constraint_used(network_maxmin_system, ((surf_resource_lmm_t)
304                                                      resource_id)->
305                              constraint);
306 }
307
308 static int net_action_unref(surf_action_t action)
309 {
310   action->refcount--;
311   if (!action->refcount) {
312     xbt_swag_remove(action, action->state_set);
313     if (((surf_action_lmm_t)action)->variable) {
314       lmm_variable_free(network_maxmin_system,
315                         ((surf_action_lmm_t) action)->variable);
316     }
317     if (network_update_mechanism == UM_LAZY) {  // remove action from the heap
318       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t) action);
319       xbt_swag_remove(action, net_modified_set);
320     }
321     surf_action_free(&action);
322     return 1;
323   }
324   return 0;
325 }
326
327
328
329 static void net_action_cancel(surf_action_t action)
330 {
331   XBT_DEBUG("cancel action %p", action);
332   surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
333   if (network_update_mechanism == UM_LAZY) {    // remove action from the heap
334     xbt_swag_remove(action, net_modified_set);
335     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t) action);
336   }
337 }
338
339 void net_action_recycle(surf_action_t action)
340 {
341   return;
342 }
343
344 #ifdef HAVE_LATENCY_BOUND_TRACKING
345 int net_get_link_latency_limited(surf_action_t action)
346 {
347   return action->latency_limited;
348 }
349 #endif
350
351 double net_action_get_remains(surf_action_t action)
352 {
353   if (network_update_mechanism == UM_LAZY)      /* update remains before return it */
354     net_update_action_remaining_lazy(surf_get_clock());
355   return action->remains;
356 }
357
358 static void net_update_action_remaining_lazy(double now)
359 {
360   surf_action_lmm_t action = NULL;
361   double delta = 0.0;
362
363   xbt_swag_foreach(action, net_modified_set) {
364
365     if (action->suspended != 0) {
366       continue;
367     }
368
369     delta = now - action->last_update;
370
371     double_update(&(((surf_action_t)action)->remains),
372                   lmm_variable_getvalue(action->variable) * delta);
373
374     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
375       double_update(&(((surf_action_t)action)->max_duration), delta);
376
377     if ((((surf_action_t)action)->remains <= 0) &&
378         (lmm_get_variable_weight(action->variable) > 0)) {
379       ((surf_action_t)action)->finish = surf_get_clock();
380       surf_network_model->action_state_set((surf_action_t) action,
381                                            SURF_ACTION_DONE);
382       surf_action_lmm_heap_remove(net_action_heap,action);
383     } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
384                && (((surf_action_t)action)->max_duration <= 0))) {
385       ((surf_action_t)action)->finish = surf_get_clock();
386       surf_network_model->action_state_set((surf_action_t) action,
387                                            SURF_ACTION_DONE);
388       surf_action_lmm_heap_remove(net_action_heap,action);
389     }
390
391     action->last_update = now;
392   }
393 }
394
395 static double net_share_resources_full(double now)
396 {
397   s_surf_action_lmm_t s_action;
398   surf_action_network_CM02_t action = NULL;
399   xbt_swag_t running_actions =
400       surf_network_model->states.running_action_set;
401   double min;
402
403   min = generic_maxmin_share_resources(running_actions,
404                                        xbt_swag_offset(s_action,
405                                                        variable),
406                                        network_maxmin_system,
407                                        network_solve);
408
409 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable)  )))
410
411   xbt_swag_foreach(action, running_actions) {
412 #ifdef HAVE_LATENCY_BOUND_TRACKING
413     if (lmm_is_variable_limited_by_latency(GENERIC_LMM_ACTION(action).variable)) {
414       action->latency_limited = 1;
415     } else {
416       action->latency_limited = 0;
417     }
418 #endif
419     if (action->latency > 0) {
420       min = (min < 0) ? action->latency : min(min, action->latency);
421     }
422   }
423
424   XBT_DEBUG("Min of share resources %f", min);
425
426   return min;
427 }
428
429 static double net_share_resources_lazy(double now)
430 {
431   surf_action_network_CM02_t action = NULL;
432   double min = -1;
433   double value;
434
435   XBT_DEBUG
436       ("Before share resources, the size of modified actions set is %d",
437        xbt_swag_size(net_modified_set));
438   net_update_action_remaining_lazy(now);
439
440   lmm_solve(network_maxmin_system);
441
442   XBT_DEBUG
443       ("After share resources, The size of modified actions set is %d",
444        xbt_swag_size(net_modified_set));
445
446   xbt_swag_foreach(action, net_modified_set) {
447     int max_dur_flag = 0;
448
449     if (GENERIC_ACTION(action).state_set !=
450         surf_network_model->states.running_action_set)
451       continue;
452
453     /* bogus priority, skip it */
454     if (GENERIC_ACTION(action).priority <= 0)
455       continue;
456
457     min = -1;
458     value = lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable);
459     if (value > 0) {
460       if (GENERIC_ACTION(action).remains > 0) {
461         value = GENERIC_ACTION(action).remains / value;
462         min = now + value;
463       } else {
464         value = 0.0;
465         min = now;
466       }
467     }
468
469     if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
470         && (min == -1
471             || GENERIC_ACTION(action).start +
472             GENERIC_ACTION(action).max_duration < min)) {
473       min = GENERIC_ACTION(action).start +
474           GENERIC_ACTION(action).max_duration;
475       max_dur_flag = 1;
476     }
477
478     XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
479               GENERIC_ACTION(action).start, now + value,
480               GENERIC_ACTION(action).max_duration);
481
482     if (min != -1) {
483       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
484       surf_action_lmm_heap_insert(net_action_heap,(surf_action_lmm_t)action, min, max_dur_flag ? MAX_DURATION : NORMAL);
485       XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
486                 now);
487     } else DIE_IMPOSSIBLE;
488   }
489
490   //hereafter must have already the min value for this resource model
491   if (xbt_heap_size(net_action_heap) > 0)
492     min = xbt_heap_maxkey(net_action_heap) - now;
493   else
494     min = -1;
495
496   XBT_DEBUG("The minimum with the HEAP %lf", min);
497
498   return min;
499 }
500
501 static void net_update_actions_state_full(double now, double delta)
502 {
503   double deltap = 0.0;
504   surf_action_network_CM02_t action = NULL;
505   surf_action_network_CM02_t next_action = NULL;
506   xbt_swag_t running_actions =
507       surf_network_model->states.running_action_set;
508   /*
509      xbt_swag_t failed_actions =
510      surf_network_model->states.failed_action_set;
511    */
512
513   xbt_swag_foreach_safe(action, next_action, running_actions) {
514     deltap = delta;
515     if (action->latency > 0) {
516       if (action->latency > deltap) {
517         double_update(&(action->latency), deltap);
518         deltap = 0.0;
519       } else {
520         double_update(&(deltap), action->latency);
521         action->latency = 0.0;
522       }
523       if ((action->latency == 0.0) && !(GENERIC_LMM_ACTION(action).suspended))
524         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
525                                    action->weight);
526     }
527 #ifdef HAVE_TRACING
528     if (TRACE_is_enabled()) {
529       int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
530       unsigned int i;
531       for (i = 0; i < n; i++){
532         lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
533                                                             GENERIC_LMM_ACTION(action).variable,
534                                                             i);
535         link_CM02_t link = lmm_constraint_id(constraint);
536         TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
537                                         ((surf_action_t)action)->category,
538                                         lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
539                                         now - delta,
540                                         delta);
541       }
542     }
543 #endif
544     if (!lmm_get_number_of_cnst_from_var
545         (network_maxmin_system, GENERIC_LMM_ACTION(action).variable)) {
546       /* There is actually no link used, hence an infinite bandwidth.
547        * This happens often when using models like vivaldi.
548        * In such case, just make sure that the action completes immediately.
549        */
550       double_update(&(GENERIC_ACTION(action).remains),
551                     GENERIC_ACTION(action).remains);
552     }
553     double_update(&(GENERIC_ACTION(action).remains),
554                   lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * deltap);
555     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
556       double_update(&(((surf_action_t)action)->max_duration), delta);
557
558     if ((GENERIC_ACTION(action).remains <= 0) &&
559         (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 0)) {
560       ((surf_action_t)action)->finish = surf_get_clock();
561       surf_network_model->action_state_set((surf_action_t) action,
562                                            SURF_ACTION_DONE);
563
564       if (gap_remove)
565         gap_remove(action);
566     } else if ((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
567                && (((surf_action_t)action)->max_duration <= 0)) {
568       ((surf_action_t)action)->finish = surf_get_clock();
569       surf_network_model->action_state_set((surf_action_t) action,
570                                            SURF_ACTION_DONE);
571       if (gap_remove)
572         gap_remove(action);
573     }
574   }
575
576   return;
577 }
578
579 static void net_update_actions_state_lazy(double now, double delta)
580 {
581   surf_action_network_CM02_t action = NULL;
582
583   while ((xbt_heap_size(net_action_heap) > 0)
584          && (double_equals(xbt_heap_maxkey(net_action_heap), now))) {
585     action = xbt_heap_pop(net_action_heap);
586     XBT_DEBUG("Action %p: finish", action);
587     GENERIC_ACTION(action).finish = surf_get_clock();
588 #ifdef HAVE_TRACING
589     if (TRACE_is_enabled()) {
590       int n = lmm_get_number_of_cnst_from_var(network_maxmin_system, GENERIC_LMM_ACTION(action).variable);
591       unsigned int i;
592       for (i = 0; i < n; i++){
593         lmm_constraint_t constraint = lmm_get_cnst_from_var(network_maxmin_system,
594                                                             GENERIC_LMM_ACTION(action).variable,
595                                                             i);
596         link_CM02_t link = lmm_constraint_id(constraint);
597         TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
598                                         ((surf_action_t)action)->category,
599                                         lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable),
600                                         GENERIC_LMM_ACTION(action).last_update,
601                                         now - GENERIC_LMM_ACTION(action).last_update);
602       }
603     }
604 #endif
605
606     // if I am wearing a latency hat
607     if (GENERIC_LMM_ACTION(action).hat == LATENCY) {
608       lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
609                                  action->weight);
610       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
611       GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
612
613       // if I am wearing a max_duration or normal hat
614     } else if (GENERIC_LMM_ACTION(action).hat == MAX_DURATION ||
615         GENERIC_LMM_ACTION(action).hat == NORMAL) {
616       // no need to communicate anymore
617       // assume that flows that reached max_duration have remaining of 0
618       GENERIC_ACTION(action).remains = 0;
619       ((surf_action_t)action)->finish = surf_get_clock();
620       surf_network_model->action_state_set((surf_action_t) action,
621                                            SURF_ACTION_DONE);
622       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
623     }
624   }
625   return;
626 }
627
628 static void net_update_resource_state(void *id,
629                                       tmgr_trace_event_t event_type,
630                                       double value, double date)
631 {
632   link_CM02_t nw_link = id;
633   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
634   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
635   /*     value, event_type); */
636
637   if (event_type == nw_link->lmm_resource.power.event) {
638     double delta =
639         sg_weight_S_parameter / value - sg_weight_S_parameter /
640         (nw_link->lmm_resource.power.peak *
641          nw_link->lmm_resource.power.scale);
642     lmm_variable_t var = NULL;
643     lmm_element_t elem = NULL;
644     surf_action_network_CM02_t action = NULL;
645
646     nw_link->lmm_resource.power.peak = value;
647     lmm_update_constraint_bound(network_maxmin_system,
648                                 nw_link->lmm_resource.constraint,
649                                 sg_bandwidth_factor *
650                                 (nw_link->lmm_resource.power.peak *
651                                  nw_link->lmm_resource.power.scale));
652 #ifdef HAVE_TRACING
653     TRACE_surf_link_set_bandwidth(date,
654                                   (char
655                                    *) (((nw_link->lmm_resource).
656                                         generic_resource).name),
657                                   sg_bandwidth_factor *
658                                   (nw_link->lmm_resource.power.peak *
659                                    nw_link->lmm_resource.power.scale));
660 #endif
661     if (sg_weight_S_parameter > 0) {
662       while ((var = lmm_get_var_from_cnst
663               (network_maxmin_system, nw_link->lmm_resource.constraint,
664                &elem))) {
665         action = lmm_variable_id(var);
666         action->weight += delta;
667         if (!(GENERIC_LMM_ACTION(action).suspended))
668           lmm_update_variable_weight(network_maxmin_system,
669                                      GENERIC_LMM_ACTION(action).variable, action->weight);
670       }
671     }
672     if (tmgr_trace_event_free(event_type))
673       nw_link->lmm_resource.power.event = NULL;
674   } else if (event_type == nw_link->lat_event) {
675     double delta = value - nw_link->lat_current;
676     lmm_variable_t var = NULL;
677     lmm_element_t elem = NULL;
678     surf_action_network_CM02_t action = NULL;
679
680     nw_link->lat_current = value;
681     while ((var = lmm_get_var_from_cnst
682             (network_maxmin_system, nw_link->lmm_resource.constraint,
683              &elem))) {
684       action = lmm_variable_id(var);
685       action->lat_current += delta;
686       action->weight += delta;
687       if (action->rate < 0)
688         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
689                                   sg_tcp_gamma / (2.0 *
690                                                   action->lat_current));
691       else {
692         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
693                                   min(action->rate,
694                                       sg_tcp_gamma / (2.0 *
695                                                       action->
696                                                       lat_current)));
697
698         if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
699           XBT_INFO("Flow is limited BYBANDWIDTH");
700         } else {
701           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
702                    action->lat_current);
703         }
704       }
705       if (!(GENERIC_LMM_ACTION(action).suspended))
706         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
707                                    action->weight);
708
709     }
710     if (tmgr_trace_event_free(event_type))
711       nw_link->lat_event = NULL;
712   } else if (event_type == nw_link->lmm_resource.state_event) {
713     if (value > 0)
714       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
715     else {
716       lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
717       lmm_variable_t var = NULL;
718       lmm_element_t elem = NULL;
719
720       nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
721       while ((var = lmm_get_var_from_cnst
722               (network_maxmin_system, cnst, &elem))) {
723         surf_action_t action = lmm_variable_id(var);
724
725         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
726             surf_action_state_get(action) == SURF_ACTION_READY) {
727           action->finish = date;
728           surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
729         }
730       }
731     }
732     if (tmgr_trace_event_free(event_type))
733       nw_link->lmm_resource.state_event = NULL;
734   } else {
735     XBT_CRITICAL("Unknown event ! \n");
736     xbt_abort();
737   }
738
739   XBT_DEBUG
740       ("There were a resource state event, need to update actions related to the constraint (%p)",
741        nw_link->lmm_resource.constraint);
742   return;
743 }
744
745
746 static surf_action_t net_communicate(network_element_t src,
747                                      network_element_t dst,
748                                      double size, double rate)
749 {
750   unsigned int i;
751   link_CM02_t link;
752   int failed = 0;
753   surf_action_network_CM02_t action = NULL;
754   double bandwidth_bound;
755   double latency = 0.0;
756   xbt_dynar_t back_route = NULL;
757   int constraints_per_variable = 0;
758
759   xbt_dynar_t route = xbt_dynar_new(global_routing->size_of_link, NULL);
760
761   XBT_IN("(%s,%s,%g,%g)", src->name, dst->name, size, rate);
762
763   routing_get_route_and_latency(src, dst, &route, &latency);
764   xbt_assert(!xbt_dynar_is_empty(route) || latency,
765              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
766              src->name, dst->name);
767
768   xbt_dynar_foreach(route, i, link) {
769     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
770       failed = 1;
771       break;
772     }
773   }
774   if (sg_network_crosstraffic == 1) {
775     routing_get_route_and_latency(dst, src, &back_route, NULL);
776     xbt_dynar_foreach(back_route, i, link) {
777       if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
778         failed = 1;
779         break;
780       }
781     }
782   }
783
784   action =
785       surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
786                       surf_network_model, failed);
787 #ifdef HAVE_LATENCY_BOUND_TRACKING
788   action->latency_limited = 0;
789 #endif
790   action->weight = action->latency = latency;
791
792   xbt_swag_insert(action, ((surf_action_t)action)->state_set);
793   action->rate = rate;
794   if (network_update_mechanism == UM_LAZY) {
795     GENERIC_LMM_ACTION(action).index_heap = -1;
796     GENERIC_LMM_ACTION(action).last_update = surf_get_clock();
797   }
798
799   bandwidth_bound = -1.0;
800   if (sg_weight_S_parameter > 0) {
801     xbt_dynar_foreach(route, i, link) {
802       action->weight +=
803           sg_weight_S_parameter /
804           (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
805     }
806   }
807   xbt_dynar_foreach(route, i, link) {
808     double bb = bandwidth_factor_callback(size) *
809         (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
810     bandwidth_bound =
811         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
812   }
813
814   action->lat_current = action->latency;
815   action->latency *= latency_factor_callback(size);
816   action->rate =
817       bandwidth_constraint_callback(action->rate, bandwidth_bound, size);
818   if (gap_append) {
819     xbt_assert(!xbt_dynar_is_empty(route),
820                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
821
822     link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0);
823     gap_append(size, link, action);
824     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
825               action, src->name, dst->name, action->sender.gap,
826               action->latency);
827   }
828
829   constraints_per_variable = xbt_dynar_length(route);
830   if (back_route != NULL)
831     constraints_per_variable += xbt_dynar_length(back_route);
832
833   if (action->latency > 0) {
834     GENERIC_LMM_ACTION(action).variable =
835         lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
836                          constraints_per_variable);
837     if (network_update_mechanism == UM_LAZY) {
838       // add to the heap the event when the latency is payed
839       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
840                 action->latency + GENERIC_LMM_ACTION(action).last_update);
841       surf_action_lmm_heap_insert(net_action_heap,(surf_action_lmm_t)action, action->latency + GENERIC_LMM_ACTION(action).last_update,
842                   xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
843     }
844   } else
845     GENERIC_LMM_ACTION(action).variable =
846         lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
847                          constraints_per_variable);
848
849   if (action->rate < 0) {
850     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
851                               (action->lat_current > 0) ?
852                               sg_tcp_gamma / (2.0 *
853                                               action->lat_current) : -1.0);
854   } else {
855     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
856                               (action->lat_current > 0) ?
857                               min(action->rate,
858                                   sg_tcp_gamma / (2.0 *
859                                                   action->lat_current))
860                               : action->rate);
861   }
862
863   xbt_dynar_foreach(route, i, link) {
864     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
865                GENERIC_LMM_ACTION(action).variable, 1.0);
866   }
867
868   if (sg_network_crosstraffic == 1) {
869     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
870     xbt_dynar_foreach(back_route, i, link) {
871       lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
872                  GENERIC_LMM_ACTION(action).variable, .05);
873     }
874   }
875
876   xbt_dynar_free(&route);
877   XBT_OUT();
878
879   return (surf_action_t) action;
880 }
881
882 static xbt_dynar_t net_get_route(void *src, void *dst)
883 {
884   xbt_dynar_t route = NULL;
885   routing_get_route_and_latency(src, dst, &route, NULL);
886   return route;
887 }
888
889 static double net_get_link_bandwidth(const void *link)
890 {
891   surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
892   return lmm->power.peak * lmm->power.scale;
893 }
894
895 static double net_get_link_latency(const void *link)
896 {
897   return ((link_CM02_t) link)->lat_current;
898 }
899
900 static int net_link_shared(const void *link)
901 {
902   return
903       lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
904 }
905
906 static void net_action_suspend(surf_action_t action)
907 {
908   ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 1;
909   lmm_update_variable_weight(network_maxmin_system,
910                              ((surf_action_network_CM02_t)
911                               action)->generic_lmm_action.variable, 0.0);
912
913   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
914     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
915 }
916
917 static void net_action_resume(surf_action_t action)
918 {
919   if (((surf_action_network_CM02_t) action)->generic_lmm_action.suspended) {
920     lmm_update_variable_weight(network_maxmin_system,
921                                ((surf_action_network_CM02_t)
922                                 action)->generic_lmm_action.variable,
923                                ((surf_action_network_CM02_t)
924                                 action)->weight);
925     ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 0;
926     if (network_update_mechanism == UM_LAZY)    // remove action from the heap
927       surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
928   }
929 }
930
931 static int net_action_is_suspended(surf_action_t action)
932 {
933   return ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended;
934 }
935
936 void net_action_set_max_duration(surf_action_t action, double duration)
937 {
938   action->max_duration = duration;
939   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
940     surf_action_lmm_heap_remove(net_action_heap,(surf_action_lmm_t)action);
941 }
942
943 #ifdef HAVE_TRACING
944 static void net_action_set_category(surf_action_t action,
945                                     const char *category)
946 {
947   action->category = xbt_strdup(category);
948 }
949 #endif
950
951 static void net_finalize(void)
952 {
953   surf_model_exit(surf_network_model);
954   surf_network_model = NULL;
955
956   lmm_system_free(network_maxmin_system);
957   network_maxmin_system = NULL;
958
959   if (network_update_mechanism == UM_LAZY) {
960     xbt_heap_free(net_action_heap);
961     xbt_swag_free(net_modified_set);
962   }
963
964   if (smpi_bw_factor)
965     xbt_dynar_free(&smpi_bw_factor);
966   if (smpi_lat_factor)
967     xbt_dynar_free(&smpi_lat_factor);
968 }
969
970 static void smpi_gap_append(double size, const link_CM02_t link,
971                             surf_action_network_CM02_t action)
972 {
973   const char *src = link->lmm_resource.generic_resource.name;
974   xbt_fifo_t fifo;
975   surf_action_network_CM02_t last_action;
976   double bw;
977
978   if (sg_sender_gap > 0.0) {
979     if (!gap_lookup) {
980       gap_lookup = xbt_dict_new();
981     }
982     fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
983     action->sender.gap = 0.0;
984     if (fifo && xbt_fifo_size(fifo) > 0) {
985       /* Compute gap from last send */
986       last_action =
987           (surf_action_network_CM02_t)
988           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
989       bw = net_get_link_bandwidth(link);
990       action->sender.gap =
991           last_action->sender.gap + max(sg_sender_gap,
992                                         last_action->sender.size / bw);
993       action->latency += action->sender.gap;
994     }
995     /* Append action as last send */
996     action->sender.link_name = link->lmm_resource.generic_resource.name;
997     fifo =
998         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
999                                           action->sender.link_name);
1000     if (!fifo) {
1001       fifo = xbt_fifo_new();
1002       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
1003     }
1004     action->sender.fifo_item = xbt_fifo_push(fifo, action);
1005     action->sender.size = size;
1006   }
1007 }
1008
1009 static void smpi_gap_remove(surf_action_network_CM02_t action)
1010 {
1011   xbt_fifo_t fifo;
1012   size_t size;
1013
1014   if (sg_sender_gap > 0.0 && action->sender.link_name
1015       && action->sender.fifo_item) {
1016     fifo =
1017         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
1018                                           action->sender.link_name);
1019     xbt_fifo_remove_item(fifo, action->sender.fifo_item);
1020     size = xbt_fifo_size(fifo);
1021     if (size == 0) {
1022       xbt_fifo_free(fifo);
1023       xbt_dict_remove(gap_lookup, action->sender.link_name);
1024       size = xbt_dict_length(gap_lookup);
1025       if (size == 0) {
1026         xbt_dict_free(&gap_lookup);
1027       }
1028     }
1029   }
1030 }
1031
1032 static void surf_network_model_init_internal(void)
1033 {
1034   s_surf_action_network_CM02_t comm;
1035   surf_network_model = surf_model_init();
1036
1037   surf_network_model->name = "network";
1038   surf_network_model->action_unref = net_action_unref;
1039   surf_network_model->action_cancel = net_action_cancel;
1040   surf_network_model->action_recycle = net_action_recycle;
1041   surf_network_model->get_remains = net_action_get_remains;
1042 #ifdef HAVE_LATENCY_BOUND_TRACKING
1043   surf_network_model->get_latency_limited = net_get_link_latency_limited;
1044 #endif
1045 #ifdef HAVE_TRACING
1046   surf_network_model->set_category = net_action_set_category;
1047 #endif
1048
1049   surf_network_model->model_private->resource_used = net_resource_used;
1050   if (network_update_mechanism == UM_LAZY) {
1051     surf_network_model->model_private->share_resources =
1052         net_share_resources_lazy;
1053     surf_network_model->model_private->update_actions_state =
1054         net_update_actions_state_lazy;
1055   } else if (network_update_mechanism == UM_FULL) {
1056     surf_network_model->model_private->share_resources =
1057         net_share_resources_full;
1058     surf_network_model->model_private->update_actions_state =
1059         net_update_actions_state_full;
1060   }
1061
1062   surf_network_model->model_private->update_resource_state =
1063       net_update_resource_state;
1064   surf_network_model->model_private->finalize = net_finalize;
1065
1066   surf_network_model->suspend = net_action_suspend;
1067   surf_network_model->resume = net_action_resume;
1068   surf_network_model->is_suspended = net_action_is_suspended;
1069   surf_cpu_model->set_max_duration = net_action_set_max_duration;
1070
1071   surf_network_model->extension.network.communicate = net_communicate;
1072   surf_network_model->extension.network.get_route = net_get_route;
1073   surf_network_model->extension.network.get_link_bandwidth =
1074       net_get_link_bandwidth;
1075   surf_network_model->extension.network.get_link_latency =
1076       net_get_link_latency;
1077   surf_network_model->extension.network.link_shared = net_link_shared;
1078   surf_network_model->extension.network.add_traces = net_add_traces;
1079   surf_network_model->extension.network.create_resource =
1080       net_create_resource;
1081
1082   if (!network_maxmin_system)
1083     network_maxmin_system = lmm_system_new(net_selective_update);
1084
1085   routing_model_create(sizeof(link_CM02_t),
1086                        net_create_resource("__loopback__",
1087                                            498000000, NULL, 0.000015, NULL,
1088                                            SURF_RESOURCE_ON, NULL,
1089                                            SURF_LINK_FATPIPE, NULL));
1090
1091   if (network_update_mechanism == UM_LAZY) {
1092     net_action_heap = xbt_heap_new(8, NULL);
1093     xbt_heap_set_update_callback(net_action_heap,
1094                                  surf_action_lmm_update_index_heap);
1095     net_modified_set =
1096         xbt_swag_new(xbt_swag_offset(comm, generic_lmm_action.action_list_hookup));
1097     network_maxmin_system->keep_track = net_modified_set;
1098   }
1099 }
1100
1101 static void set_update_mechanism(void)
1102 {
1103   char *optim = xbt_cfg_get_string(_surf_cfg_set, "network/optim");
1104   int select =
1105       xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
1106
1107   if (!strcmp(optim, "Full")) {
1108     network_update_mechanism = UM_FULL;
1109     net_selective_update = select;
1110   } else if (!strcmp(optim, "Lazy")) {
1111     network_update_mechanism = UM_LAZY;
1112     net_selective_update = 1;
1113     xbt_assert((select == 1)
1114                ||
1115                (xbt_cfg_is_default_value
1116                 (_surf_cfg_set, "network/maxmin_selective_update")),
1117                "Disabling selective update while using the lazy update mechanism is dumb!");
1118   } else {
1119     xbt_die("Unsupported optimization (%s) for this model", optim);
1120   }
1121 }
1122
1123 /************************************************************************/
1124 /* New model based on LV08 and experimental results of MPI ping-pongs   */
1125 /************************************************************************/
1126 /* @Inproceedings{smpi_ipdps, */
1127 /*  author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
1128 /*  title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
1129 /*  booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
1130 /*  address={Anchorage (Alaska) USA}, */
1131 /*  month=may, */
1132 /*  year={2011} */
1133 /*  } */
1134 void surf_network_model_init_SMPI(void)
1135 {
1136
1137   if (surf_network_model)
1138     return;
1139   set_update_mechanism();
1140
1141   surf_network_model_init_internal();
1142   latency_factor_callback = &smpi_latency_factor;
1143   bandwidth_factor_callback = &smpi_bandwidth_factor;
1144   bandwidth_constraint_callback = &smpi_bandwidth_constraint;
1145   gap_append = &smpi_gap_append;
1146   gap_remove = &smpi_gap_remove;
1147   net_define_callbacks();
1148   xbt_dynar_push(model_list, &surf_network_model);
1149   network_solve = lmm_solve;
1150
1151   xbt_cfg_setdefault_double(_surf_cfg_set, "network/sender_gap", 10e-6);
1152   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1153 }
1154
1155 /************************************************************************/
1156 /* New model based on optimizations discussed during Pedro Velho's thesis*/
1157 /************************************************************************/
1158 /* @techreport{VELHO:2011:HAL-00646896:1, */
1159 /*      url = {http://hal.inria.fr/hal-00646896/en/}, */
1160 /*      title = {{Flow-level network models: have we reached the limits?}}, */
1161 /*      author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
1162 /*      type = {Rapport de recherche}, */
1163 /*      institution = {INRIA}, */
1164 /*      number = {RR-7821}, */
1165 /*      year = {2011}, */
1166 /*      month = Nov, */
1167 /*      pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
1168 /*  } */
1169 void surf_network_model_init_LegrandVelho(void)
1170 {
1171   if (surf_network_model)
1172     return;
1173
1174   set_update_mechanism();
1175
1176   surf_network_model_init_internal();
1177   net_define_callbacks();
1178   xbt_dynar_push(model_list, &surf_network_model);
1179   network_solve = lmm_solve;
1180
1181   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor",
1182                             13.01);
1183   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1184                             0.97);
1185   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 20537);
1186 }
1187
1188 /***************************************************************************/
1189 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
1190 /***************************************************************************/
1191 /* @TechReport{      rr-lip2002-40, */
1192 /*   author        = {Henri Casanova and Loris Marchal}, */
1193 /*   institution   = {LIP}, */
1194 /*   title         = {A Network Model for Simulation of Grid Application}, */
1195 /*   number        = {2002-40}, */
1196 /*   month         = {oct}, */
1197 /*   year          = {2002} */
1198 /* } */
1199 void surf_network_model_init_CM02(void)
1200 {
1201
1202   if (surf_network_model)
1203     return;
1204
1205   set_update_mechanism();
1206   surf_network_model_init_internal();
1207   net_define_callbacks();
1208   xbt_dynar_push(model_list, &surf_network_model);
1209   network_solve = lmm_solve;
1210
1211   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 1.0);
1212   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1213                             1.0);
1214   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 0.0);
1215 }
1216
1217 /***************************************************************************/
1218 /* The models from Steven H. Low                                           */
1219 /***************************************************************************/
1220 /* @article{Low03,                                                         */
1221 /*   author={Steven H. Low},                                               */
1222 /*   title={A Duality Model of {TCP} and Queue Management Algorithms},     */
1223 /*   year={2003},                                                          */
1224 /*   journal={{IEEE/ACM} Transactions on Networking},                      */
1225 /*    volume={11}, number={4},                                             */
1226 /*  }                                                                      */
1227 void surf_network_model_init_Reno(void)
1228 {
1229   if (surf_network_model)
1230     return;
1231
1232   set_update_mechanism();
1233   surf_network_model_init_internal();
1234   net_define_callbacks();
1235
1236   xbt_dynar_push(model_list, &surf_network_model);
1237   lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
1238                                     func_reno_fpi);
1239   network_solve = lagrange_solve;
1240
1241   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1242   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1243                             0.92);
1244   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1245 }
1246
1247
1248 void surf_network_model_init_Reno2(void)
1249 {
1250   if (surf_network_model)
1251     return;
1252
1253   set_update_mechanism();
1254   surf_network_model_init_internal();
1255   net_define_callbacks();
1256
1257   xbt_dynar_push(model_list, &surf_network_model);
1258   lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
1259                                     func_reno2_fpi);
1260   network_solve = lagrange_solve;
1261
1262   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1263   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1264                             0.92);
1265   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S_parameter",
1266                             8775);
1267 }
1268
1269 void surf_network_model_init_Vegas(void)
1270 {
1271   if (surf_network_model)
1272     return;
1273
1274   set_update_mechanism();
1275   surf_network_model_init_internal();
1276   net_define_callbacks();
1277
1278   xbt_dynar_push(model_list, &surf_network_model);
1279   lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
1280                                     func_vegas_fpi);
1281   network_solve = lagrange_solve;
1282
1283   xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1284   xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1285                             0.92);
1286   xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1287 }