Logo AND Algorithmique Numérique Distribuée

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