Logo AND Algorithmique Numérique Distribuée

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