Logo AND Algorithmique Numérique Distribuée

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