Logo AND Algorithmique Numérique Distribuée

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