Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6df63ed3d379c36552d1a1867b93d0c11932c927
[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) action)->index_heap = i;
71 }
72
73 /* insert action on heap using a given key and a hat (heap_action_type)
74  * a hat can be of three types for communications:
75  *
76  * NORMAL = this is a normal heap entry stating the date to finish transmitting
77  * LATENCY = this is a heap entry to warn us when the latency is payed
78  * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
79  */
80 static void heap_insert(surf_action_network_CM02_t action, double key,
81                         enum heap_action_type hat)
82 {
83   action->hat = hat;
84   xbt_heap_push(net_action_heap, action, key);
85 }
86
87 static void heap_remove(surf_action_network_CM02_t action)
88 {
89   action->hat = NOTSET;
90   if (((surf_action_network_CM02_t) action)->index_heap >= 0) {
91     xbt_heap_remove(net_action_heap, action->index_heap);
92   }
93 }
94
95 /******************************************************************************/
96 /*                           Factors callbacks                                */
97 /******************************************************************************/
98 static double constant_latency_factor(double size)
99 {
100   return sg_latency_factor;
101 }
102
103 static double constant_bandwidth_factor(double size)
104 {
105   return sg_bandwidth_factor;
106 }
107
108 static double constant_bandwidth_constraint(double rate, double bound,
109                                             double size)
110 {
111   return rate;
112 }
113
114 /**********************/
115 /*   SMPI callbacks   */
116 /**********************/
117 static xbt_dynar_t parse_factor(const char *smpi_coef_string)
118 {
119   char *value = NULL;
120   unsigned int iter = 0;
121   s_smpi_factor_t fact;
122   xbt_dynar_t smpi_factor, radical_elements, radical_elements2 = NULL;
123
124   smpi_factor = xbt_dynar_new(sizeof(s_smpi_factor_t), NULL);
125   radical_elements = xbt_str_split(smpi_coef_string, ";");
126   xbt_dynar_foreach(radical_elements, iter, value) {
127
128     radical_elements2 = xbt_str_split(value, ":");
129     if (xbt_dynar_length(radical_elements2) != 2)
130       xbt_die("Malformed radical for smpi factor!");
131     fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
132     fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
133     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
134     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
135     xbt_dynar_free(&radical_elements2);
136   }
137   xbt_dynar_free(&radical_elements);
138   return smpi_factor;
139 }
140
141 static double smpi_bandwidth_factor(double size)
142 {
143   if (!smpi_bw_factor)
144     smpi_bw_factor =
145         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/bw_factor"));
146
147   unsigned int iter = 0;
148   s_smpi_factor_t fact;
149   xbt_dynar_foreach(smpi_bw_factor, iter, fact) {
150     if (size >= fact.factor) {
151       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
152       return fact.value;
153     }
154   }
155
156   return 1.0;
157 }
158
159 static double smpi_latency_factor(double size)
160 {
161   if (!smpi_lat_factor)
162     smpi_lat_factor =
163         parse_factor(xbt_cfg_get_string(_surf_cfg_set, "smpi/lat_factor"));
164
165   unsigned int iter = 0;
166   s_smpi_factor_t fact;
167   xbt_dynar_foreach(smpi_lat_factor, iter, fact) {
168     if (size >= fact.factor) {
169       XBT_DEBUG("%lf >= %ld return %f", size, fact.factor, fact.value);
170       return fact.value;
171     }
172   }
173
174   return 1.0;
175 }
176
177 /**--------- <copy/paste C code snippet in surf/network.c> -----------*/
178
179 static double smpi_bandwidth_constraint(double rate, double bound,
180                                         double size)
181 {
182   return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
183 }
184
185 static double (*latency_factor_callback) (double) =
186     &constant_latency_factor;
187 static double (*bandwidth_factor_callback) (double) =
188     &constant_bandwidth_factor;
189 static double (*bandwidth_constraint_callback) (double, double, double) =
190     &constant_bandwidth_constraint;
191
192 static void (*gap_append) (double, const link_CM02_t,
193                            surf_action_network_CM02_t) = NULL;
194 static void (*gap_remove) (surf_action_network_CM02_t) = NULL;
195
196 static void *net_create_resource(const char *name,
197                                  double bw_initial,
198                                  tmgr_trace_t bw_trace,
199                                  double lat_initial,
200                                  tmgr_trace_t lat_trace,
201                                  e_surf_resource_state_t
202                                  state_initial,
203                                  tmgr_trace_t state_trace,
204                                  e_surf_link_sharing_policy_t
205                                  policy, xbt_dict_t properties)
206 {
207   link_CM02_t nw_link = (link_CM02_t)
208       surf_resource_lmm_new(sizeof(s_link_CM02_t),
209                             surf_network_model, name, properties,
210                             network_maxmin_system,
211                             sg_bandwidth_factor * bw_initial,
212                             history,
213                             state_initial, state_trace,
214                             bw_initial, bw_trace);
215
216   xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
217              "Link '%s' declared several times in the platform file.",
218              name);
219
220   nw_link->lat_current = lat_initial;
221   if (lat_trace)
222     nw_link->lat_event =
223         tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
224
225   if (policy == SURF_LINK_FATPIPE)
226     lmm_constraint_shared(nw_link->lmm_resource.constraint);
227
228   xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
229
230   return nw_link;
231 }
232
233 static void net_parse_link_init(sg_platf_link_cbarg_t link)
234 {
235   if (link->policy == SURF_LINK_FULLDUPLEX) {
236     char *link_id;
237     link_id = bprintf("%s_UP", link->id);
238     net_create_resource(link_id,
239                         link->bandwidth,
240                         link->bandwidth_trace,
241                         link->latency,
242                         link->latency_trace,
243                         link->state,
244                         link->state_trace, link->policy, link->properties);
245     xbt_free(link_id);
246     link_id = bprintf("%s_DOWN", link->id);
247     net_create_resource(link_id,
248                         link->bandwidth,
249                         link->bandwidth_trace,
250                         link->latency,
251                         link->latency_trace,
252                         link->state,
253                         link->state_trace, link->policy, link->properties);
254     xbt_free(link_id);
255   } else {
256     net_create_resource(link->id,
257                         link->bandwidth,
258                         link->bandwidth_trace,
259                         link->latency,
260                         link->latency_trace,
261                         link->state,
262                         link->state_trace, link->policy, link->properties);
263   }
264 }
265
266 static void net_add_traces(void)
267 {
268   xbt_dict_cursor_t cursor = NULL;
269   char *trace_name, *elm;
270
271   static int called = 0;
272   if (called)
273     return;
274   called = 1;
275
276   /* connect all traces relative to network */
277   xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
278     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
279     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
280
281     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
282                trace_name, elm);
283     xbt_assert(trace,
284                "Cannot connect trace %s to link %s: trace undefined",
285                trace_name, elm);
286
287     link->lmm_resource.state_event =
288         tmgr_history_add_trace(history, trace, 0.0, 0, link);
289   }
290
291   xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
292     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
293     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
294
295     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
296                trace_name, elm);
297     xbt_assert(trace,
298                "Cannot connect trace %s to link %s: trace undefined",
299                trace_name, elm);
300
301     link->lmm_resource.power.event =
302         tmgr_history_add_trace(history, trace, 0.0, 0, link);
303   }
304
305   xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
306     tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
307     link_CM02_t link = xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
308
309     xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
310                trace_name, elm);
311     xbt_assert(trace,
312                "Cannot connect trace %s to link %s: trace undefined",
313                trace_name, elm);
314
315     link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
316   }
317 }
318
319 static void net_define_callbacks(void)
320 {
321   /* Figuring out the network links */
322   sg_platf_link_add_cb(net_parse_link_init);
323   sg_platf_postparse_add_cb(net_add_traces);
324 }
325
326 static int net_resource_used(void *resource_id)
327 {
328   return lmm_constraint_used(network_maxmin_system, ((surf_resource_lmm_t)
329                                                      resource_id)->
330                              constraint);
331 }
332
333 static int net_action_unref(surf_action_t action)
334 {
335   action->refcount--;
336   if (!action->refcount) {
337     xbt_swag_remove(action, action->state_set);
338     if (((surf_action_lmm_t)action)->variable) {
339       lmm_variable_free(network_maxmin_system,
340                         ((surf_action_lmm_t) action)->variable);
341     }
342     if (network_update_mechanism == UM_LAZY) {  // remove action from the heap
343       heap_remove((surf_action_network_CM02_t) action);
344       xbt_swag_remove(action, net_modified_set);
345     }
346 #ifdef HAVE_TRACING
347     xbt_free(((surf_action_network_CM02_t) action)->src_name);
348     xbt_free(((surf_action_network_CM02_t) action)->dst_name);
349     xbt_free(action->category);
350 #endif
351     surf_action_free(&action);
352     return 1;
353   }
354   return 0;
355 }
356
357
358
359 static void net_action_cancel(surf_action_t action)
360 {
361   XBT_DEBUG("cancel action %p", action);
362   surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
363   if (network_update_mechanism == UM_LAZY) {    // remove action from the heap
364     xbt_swag_remove(action, net_modified_set);
365     heap_remove((surf_action_network_CM02_t) action);
366   }
367 }
368
369 void net_action_recycle(surf_action_t action)
370 {
371   return;
372 }
373
374 #ifdef HAVE_LATENCY_BOUND_TRACKING
375 int net_get_link_latency_limited(surf_action_t action)
376 {
377   return action->latency_limited;
378 }
379 #endif
380
381 double net_action_get_remains(surf_action_t action)
382 {
383   if (network_update_mechanism == UM_LAZY)      /* update remains before return it */
384     update_action_remaining_lazy(surf_get_clock());
385   return action->remains;
386 }
387
388 static void update_action_remaining_lazy(double now)
389 {
390   surf_action_network_CM02_t action = NULL;
391   double delta = 0.0;
392
393   xbt_swag_foreach(action, net_modified_set) {
394
395     if (GENERIC_LMM_ACTION(action).suspended != 0) {
396       continue;
397     }
398
399     delta = now - action->last_update;
400
401     double_update(&(((surf_action_t)action)->remains),
402                   lmm_variable_getvalue(((surf_action_lmm_t) action)->variable) * delta);
403
404     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
405       double_update(&(((surf_action_t)action)->max_duration), delta);
406
407     if ((((surf_action_t)action)->remains <= 0) &&
408         (lmm_get_variable_weight(((surf_action_lmm_t)action)->variable) > 0)) {
409       ((surf_action_t)action)->finish = surf_get_clock();
410       surf_network_model->action_state_set((surf_action_t) action,
411                                            SURF_ACTION_DONE);
412       heap_remove(action);
413     } else if (((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
414                && (((surf_action_t)action)->max_duration <= 0))) {
415       ((surf_action_t)action)->finish = surf_get_clock();
416       surf_network_model->action_state_set((surf_action_t) action,
417                                            SURF_ACTION_DONE);
418       heap_remove(action);
419     }
420
421     action->last_update = now;
422   }
423 }
424
425 static double net_share_resources_full(double now)
426 {
427   s_surf_action_lmm_t s_action;
428   surf_action_network_CM02_t action = NULL;
429   xbt_swag_t running_actions =
430       surf_network_model->states.running_action_set;
431   double min;
432
433   min = generic_maxmin_share_resources(running_actions,
434                                        xbt_swag_offset(s_action,
435                                                        variable),
436                                        network_maxmin_system,
437                                        network_solve);
438
439 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable)  )))
440
441   xbt_swag_foreach(action, running_actions) {
442 #ifdef HAVE_LATENCY_BOUND_TRACKING
443     if (lmm_is_variable_limited_by_latency(action->variable)) {
444       GENERIC_LMM_ACTION(action).latency_limited = 1;
445     } else {
446       GENERIC_LMM_ACTION(action).latency_limited = 0;
447     }
448 #endif
449     if (action->latency > 0) {
450       min = (min < 0) ? action->latency : min(min, action->latency);
451     }
452   }
453
454   XBT_DEBUG("Min of share resources %f", min);
455
456   return min;
457 }
458
459 static double net_share_resources_lazy(double now)
460 {
461   surf_action_network_CM02_t action = NULL;
462   double min = -1;
463   double value;
464
465   XBT_DEBUG
466       ("Before share resources, the size of modified actions set is %d",
467        xbt_swag_size(net_modified_set));
468   update_action_remaining_lazy(now);
469
470   lmm_solve(network_maxmin_system);
471
472   XBT_DEBUG
473       ("After share resources, The size of modified actions set is %d",
474        xbt_swag_size(net_modified_set));
475
476   xbt_swag_foreach(action, net_modified_set) {
477     int max_dur_flag = 0;
478
479     if (GENERIC_ACTION(action).state_set !=
480         surf_network_model->states.running_action_set) {
481       continue;
482     }
483
484     /* bogus priority, skip it */
485     if (GENERIC_ACTION(action).priority <= 0) {
486       continue;
487     }
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 (action->index_heap >= 0) {
515       heap_remove((surf_action_network_CM02_t) action);
516     }
517
518     if (min != -1) {
519       heap_insert((surf_action_network_CM02_t) action, min,
520                   max_dur_flag ? MAX_DURATION : NORMAL);
521       XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min,
522                 now);
523     }
524   }
525
526   //hereafter must have already the min value for this resource model
527   if (xbt_heap_size(net_action_heap) > 0) {
528     min = xbt_heap_maxkey(net_action_heap) - now;
529   } else {
530     min = -1;
531   }
532
533   XBT_DEBUG("The minimum with the HEAP %lf", min);
534
535   return min;
536 }
537
538 static void net_update_actions_state_full(double now, double delta)
539 {
540   double deltap = 0.0;
541   surf_action_network_CM02_t action = NULL;
542   surf_action_network_CM02_t next_action = NULL;
543   xbt_swag_t running_actions =
544       surf_network_model->states.running_action_set;
545   /*
546      xbt_swag_t failed_actions =
547      surf_network_model->states.failed_action_set;
548    */
549
550   xbt_swag_foreach_safe(action, next_action, running_actions) {
551     deltap = delta;
552     if (action->latency > 0) {
553       if (action->latency > deltap) {
554         double_update(&(action->latency), deltap);
555         deltap = 0.0;
556       } else {
557         double_update(&(deltap), action->latency);
558         action->latency = 0.0;
559       }
560       if ((action->latency == 0.0) && !(GENERIC_LMM_ACTION(action).suspended))
561         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
562                                    action->weight);
563     }
564 #ifdef HAVE_TRACING
565     if (TRACE_is_enabled()) {
566       xbt_dynar_t route = NULL;
567       routing_get_route_and_latency(action->src_name, action->dst_name,
568                                     &route, NULL);
569       link_CM02_t link;
570       unsigned int i;
571       xbt_dynar_foreach(route, i, link) {
572         TRACE_surf_link_set_utilization(link->lmm_resource.
573                                         generic_resource.name,
574                                         (((surf_action_t)action)->data,
575                                         (surf_action_t) action,
576                                         lmm_variable_getvalue(action->
577                                                               variable),
578                                         now - delta, delta);
579       }
580     }
581 #endif
582     if (!lmm_get_number_of_cnst_from_var
583         (network_maxmin_system, GENERIC_LMM_ACTION(action).variable)) {
584       /* There is actually no link used, hence an infinite bandwidth.
585        * This happens often when using models like vivaldi.
586        * In such case, just make sure that the action completes immediately.
587        */
588       double_update(&(GENERIC_ACTION(action).remains),
589                     GENERIC_ACTION(action).remains);
590     }
591     double_update(&(GENERIC_ACTION(action).remains),
592                   lmm_variable_getvalue(GENERIC_LMM_ACTION(action).variable) * deltap);
593     if (((surf_action_t)action)->max_duration != NO_MAX_DURATION)
594       double_update(&(((surf_action_t)action)->max_duration), delta);
595
596     if ((GENERIC_ACTION(action).remains <= 0) &&
597         (lmm_get_variable_weight(GENERIC_LMM_ACTION(action).variable) > 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
602       if (gap_remove)
603         gap_remove(action);
604     } else if ((((surf_action_t)action)->max_duration != NO_MAX_DURATION)
605                && (((surf_action_t)action)->max_duration <= 0)) {
606       ((surf_action_t)action)->finish = surf_get_clock();
607       surf_network_model->action_state_set((surf_action_t) action,
608                                            SURF_ACTION_DONE);
609       if (gap_remove)
610         gap_remove(action);
611     }
612   }
613
614   return;
615 }
616
617 static void net_update_actions_state_lazy(double now, double delta)
618 {
619   surf_action_network_CM02_t action = NULL;
620
621   while ((xbt_heap_size(net_action_heap) > 0)
622          && (double_equals(xbt_heap_maxkey(net_action_heap), now))) {
623     action = xbt_heap_pop(net_action_heap);
624     XBT_DEBUG("Action %p: finish", action);
625     GENERIC_ACTION(action).finish = surf_get_clock();
626
627     // if I am wearing a latency hat
628     if (action->hat == LATENCY) {
629       lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
630                                  action->weight);
631       heap_remove(action);
632       action->last_update = surf_get_clock();
633
634       // if I am wearing a max_duration or normal hat
635     } else if (action->hat == MAX_DURATION || action->hat == NORMAL) {
636       // no need to communicate anymore
637       // assume that flows that reached max_duration have remaining of 0
638       GENERIC_ACTION(action).remains = 0;
639       ((surf_action_t)action)->finish = surf_get_clock();
640       surf_network_model->action_state_set((surf_action_t) action,
641                                            SURF_ACTION_DONE);
642       heap_remove(action);
643     }
644   }
645   return;
646 }
647
648 static void net_update_resource_state(void *id,
649                                       tmgr_trace_event_t event_type,
650                                       double value, double date)
651 {
652   link_CM02_t nw_link = id;
653   /*   printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
654   /*     "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
655   /*     value, event_type); */
656
657   if (event_type == nw_link->lmm_resource.power.event) {
658     double delta =
659         sg_weight_S_parameter / value - sg_weight_S_parameter /
660         (nw_link->lmm_resource.power.peak *
661          nw_link->lmm_resource.power.scale);
662     lmm_variable_t var = NULL;
663     lmm_element_t elem = NULL;
664     surf_action_network_CM02_t action = NULL;
665
666     nw_link->lmm_resource.power.peak = value;
667     lmm_update_constraint_bound(network_maxmin_system,
668                                 nw_link->lmm_resource.constraint,
669                                 sg_bandwidth_factor *
670                                 (nw_link->lmm_resource.power.peak *
671                                  nw_link->lmm_resource.power.scale));
672 #ifdef HAVE_TRACING
673     TRACE_surf_link_set_bandwidth(date,
674                                   (char
675                                    *) (((nw_link->lmm_resource).
676                                         generic_resource).name),
677                                   sg_bandwidth_factor *
678                                   (nw_link->lmm_resource.power.peak *
679                                    nw_link->lmm_resource.power.scale));
680 #endif
681     if (sg_weight_S_parameter > 0) {
682       while ((var = lmm_get_var_from_cnst
683               (network_maxmin_system, nw_link->lmm_resource.constraint,
684                &elem))) {
685         action = lmm_variable_id(var);
686         action->weight += delta;
687         if (!(GENERIC_LMM_ACTION(action).suspended))
688           lmm_update_variable_weight(network_maxmin_system,
689                                      GENERIC_LMM_ACTION(action).variable, action->weight);
690       }
691     }
692     if (tmgr_trace_event_free(event_type))
693       nw_link->lmm_resource.power.event = NULL;
694   } else if (event_type == nw_link->lat_event) {
695     double delta = value - nw_link->lat_current;
696     lmm_variable_t var = NULL;
697     lmm_element_t elem = NULL;
698     surf_action_network_CM02_t action = NULL;
699
700     nw_link->lat_current = value;
701     while ((var = lmm_get_var_from_cnst
702             (network_maxmin_system, nw_link->lmm_resource.constraint,
703              &elem))) {
704       action = lmm_variable_id(var);
705       action->lat_current += delta;
706       action->weight += delta;
707       if (action->rate < 0)
708         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
709                                   sg_tcp_gamma / (2.0 *
710                                                   action->lat_current));
711       else {
712         lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
713                                   min(action->rate,
714                                       sg_tcp_gamma / (2.0 *
715                                                       action->
716                                                       lat_current)));
717
718         if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
719           XBT_INFO("Flow is limited BYBANDWIDTH");
720         } else {
721           XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
722                    action->lat_current);
723         }
724       }
725       if (!(GENERIC_LMM_ACTION(action).suspended))
726         lmm_update_variable_weight(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
727                                    action->weight);
728
729     }
730     if (tmgr_trace_event_free(event_type))
731       nw_link->lat_event = NULL;
732   } else if (event_type == nw_link->lmm_resource.state_event) {
733     if (value > 0)
734       nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
735     else {
736       lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
737       lmm_variable_t var = NULL;
738       lmm_element_t elem = NULL;
739
740       nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
741       while ((var = lmm_get_var_from_cnst
742               (network_maxmin_system, cnst, &elem))) {
743         surf_action_t action = lmm_variable_id(var);
744
745         if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
746             surf_action_state_get(action) == SURF_ACTION_READY) {
747           action->finish = date;
748           surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
749         }
750       }
751     }
752     if (tmgr_trace_event_free(event_type))
753       nw_link->lmm_resource.state_event = NULL;
754   } else {
755     XBT_CRITICAL("Unknown event ! \n");
756     xbt_abort();
757   }
758
759   XBT_DEBUG
760       ("There were a resource state event, need to update actions related to the constraint (%p)",
761        nw_link->lmm_resource.constraint);
762   return;
763 }
764
765
766 static surf_action_t net_communicate(const char *src_name,
767                                      const char *dst_name, double size,
768                                      double rate)
769 {
770   unsigned int i;
771   link_CM02_t link;
772   int failed = 0;
773   surf_action_network_CM02_t action = NULL;
774   double bandwidth_bound;
775   double latency = 0.0;
776   xbt_dynar_t back_route = NULL;
777   int constraints_per_variable = 0;
778
779   xbt_dynar_t route = xbt_dynar_new(global_routing->size_of_link, NULL);
780
781   XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
782
783   routing_get_route_and_latency(src_name, dst_name, &route, &latency);
784   xbt_assert(!xbt_dynar_is_empty(route) || latency,
785              "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
786              src_name, dst_name);
787
788   xbt_dynar_foreach(route, i, link) {
789     if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
790       failed = 1;
791       break;
792     }
793   }
794   if (sg_network_crosstraffic == 1) {
795     routing_get_route_and_latency(dst_name, src_name, &back_route, NULL);
796     xbt_dynar_foreach(back_route, i, link) {
797       if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
798         failed = 1;
799         break;
800       }
801     }
802   }
803
804   action =
805       surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
806                       surf_network_model, failed);
807 #ifdef HAVE_LATENCY_BOUND_TRACKING
808   (GENERIC_LMM_ACTION(action)).latency_limited = 0;
809 #endif
810   action->weight = action->latency = latency;
811
812   xbt_swag_insert(action, ((surf_action_t)action)->state_set);
813   action->rate = rate;
814   if (network_update_mechanism == UM_LAZY) {
815     action->index_heap = -1;
816     action->last_update = surf_get_clock();
817   }
818
819   bandwidth_bound = -1.0;
820   if (sg_weight_S_parameter > 0) {
821     xbt_dynar_foreach(route, i, link) {
822       action->weight +=
823           sg_weight_S_parameter /
824           (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
825     }
826   }
827   xbt_dynar_foreach(route, i, link) {
828     double bb = bandwidth_factor_callback(size) *
829         (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
830     bandwidth_bound =
831         (bandwidth_bound < 0.0) ? bb : min(bandwidth_bound, bb);
832   }
833
834   action->lat_current = action->latency;
835   action->latency *= latency_factor_callback(size);
836   action->rate =
837       bandwidth_constraint_callback(action->rate, bandwidth_bound, size);
838   if (gap_append) {
839     xbt_assert(!xbt_dynar_is_empty(route),
840                "Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
841
842     link = *(link_CM02_t *) xbt_dynar_get_ptr(route, 0);
843     gap_append(size, link, action);
844     XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
845               action, src_name, dst_name, action->sender.gap,
846               action->latency);
847   }
848
849   constraints_per_variable = xbt_dynar_length(route);
850   if (back_route != NULL)
851     constraints_per_variable += xbt_dynar_length(back_route);
852
853   if (action->latency > 0) {
854     GENERIC_LMM_ACTION(action).variable =
855         lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
856                          constraints_per_variable);
857     if (network_update_mechanism == UM_LAZY) {
858       // add to the heap the event when the latency is payed
859       XBT_DEBUG("Added action (%p) one latency event at date %f", action,
860                 action->latency + action->last_update);
861       heap_insert(action, action->latency + action->last_update,
862                   xbt_dynar_is_empty(route) ? NORMAL : LATENCY);
863     }
864   } else
865     GENERIC_LMM_ACTION(action).variable =
866         lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
867                          constraints_per_variable);
868
869   if (action->rate < 0) {
870     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
871                               (action->lat_current > 0) ?
872                               sg_tcp_gamma / (2.0 *
873                                               action->lat_current) : -1.0);
874   } else {
875     lmm_update_variable_bound(network_maxmin_system, GENERIC_LMM_ACTION(action).variable,
876                               (action->lat_current > 0) ?
877                               min(action->rate,
878                                   sg_tcp_gamma / (2.0 *
879                                                   action->lat_current))
880                               : action->rate);
881   }
882
883   xbt_dynar_foreach(route, i, link) {
884     lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
885                GENERIC_LMM_ACTION(action).variable, 1.0);
886   }
887
888   if (sg_network_crosstraffic == 1) {
889     XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
890     xbt_dynar_foreach(back_route, i, link) {
891       lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
892                  GENERIC_LMM_ACTION(action).variable, .05);
893     }
894   }
895 #ifdef HAVE_TRACING
896   if (TRACE_is_enabled()) {
897     action->src_name = xbt_strdup(src_name);
898     action->dst_name = xbt_strdup(dst_name);
899   } else {
900     action->src_name = action->dst_name = NULL;
901   }
902 #endif
903
904   xbt_dynar_free(&route);
905   XBT_OUT();
906
907   return (surf_action_t) action;
908 }
909
910 static xbt_dynar_t net_get_route(const char *src, const char *dst)
911 {
912   xbt_dynar_t route = NULL;
913   routing_get_route_and_latency(src, dst, &route, NULL);
914   return route;
915 }
916
917 static double net_get_link_bandwidth(const void *link)
918 {
919   surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
920   return lmm->power.peak * lmm->power.scale;
921 }
922
923 static double net_get_link_latency(const void *link)
924 {
925   return ((link_CM02_t) link)->lat_current;
926 }
927
928 static int net_link_shared(const void *link)
929 {
930   return
931       lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
932 }
933
934 static void net_action_suspend(surf_action_t action)
935 {
936   ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 1;
937   lmm_update_variable_weight(network_maxmin_system,
938                              ((surf_action_network_CM02_t)
939                               action)->generic_lmm_action.variable, 0.0);
940
941   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
942     heap_remove((surf_action_network_CM02_t) action);
943 }
944
945 static void net_action_resume(surf_action_t action)
946 {
947   if (((surf_action_network_CM02_t) action)->generic_lmm_action.suspended) {
948     lmm_update_variable_weight(network_maxmin_system,
949                                ((surf_action_network_CM02_t)
950                                 action)->generic_lmm_action.variable,
951                                ((surf_action_network_CM02_t)
952                                 action)->weight);
953     ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended = 0;
954     if (network_update_mechanism == UM_LAZY)    // remove action from the heap
955       heap_remove((surf_action_network_CM02_t) action);
956   }
957 }
958
959 static int net_action_is_suspended(surf_action_t action)
960 {
961   return ((surf_action_network_CM02_t) action)->generic_lmm_action.suspended;
962 }
963
964 void net_action_set_max_duration(surf_action_t action, double duration)
965 {
966   action->max_duration = duration;
967   if (network_update_mechanism == UM_LAZY)      // remove action from the heap
968     heap_remove((surf_action_network_CM02_t) action);
969 }
970
971 #ifdef HAVE_TRACING
972 static void net_action_set_category(surf_action_t action,
973                                     const char *category)
974 {
975   action->category = xbt_strdup(category);
976 }
977 #endif
978
979 static void net_finalize(void)
980 {
981   surf_model_exit(surf_network_model);
982   surf_network_model = NULL;
983
984   lmm_system_free(network_maxmin_system);
985   network_maxmin_system = NULL;
986
987   if (network_update_mechanism == UM_LAZY) {
988     xbt_heap_free(net_action_heap);
989     xbt_swag_free(net_modified_set);
990   }
991
992   if (smpi_bw_factor)
993     xbt_dynar_free(&smpi_bw_factor);
994   if (smpi_lat_factor)
995     xbt_dynar_free(&smpi_lat_factor);
996 }
997
998 static void smpi_gap_append(double size, const link_CM02_t link,
999                             surf_action_network_CM02_t action)
1000 {
1001   const char *src = link->lmm_resource.generic_resource.name;
1002   xbt_fifo_t fifo;
1003   surf_action_network_CM02_t last_action;
1004   double bw;
1005
1006   if (sg_sender_gap > 0.0) {
1007     if (!gap_lookup) {
1008       gap_lookup = xbt_dict_new();
1009     }
1010     fifo = (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup, src);
1011     action->sender.gap = 0.0;
1012     if (fifo && xbt_fifo_size(fifo) > 0) {
1013       /* Compute gap from last send */
1014       last_action =
1015           (surf_action_network_CM02_t)
1016           xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
1017       bw = net_get_link_bandwidth(link);
1018       action->sender.gap =
1019           last_action->sender.gap + max(sg_sender_gap,
1020                                         last_action->sender.size / bw);
1021       action->latency += action->sender.gap;
1022     }
1023     /* Append action as last send */
1024     action->sender.link_name = link->lmm_resource.generic_resource.name;
1025     fifo =
1026         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
1027                                           action->sender.link_name);
1028     if (!fifo) {
1029       fifo = xbt_fifo_new();
1030       xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
1031     }
1032     action->sender.fifo_item = xbt_fifo_push(fifo, action);
1033     action->sender.size = size;
1034   }
1035 }
1036
1037 static void smpi_gap_remove(surf_action_network_CM02_t action)
1038 {
1039   xbt_fifo_t fifo;
1040   size_t size;
1041
1042   if (sg_sender_gap > 0.0 && action->sender.link_name
1043       && action->sender.fifo_item) {
1044     fifo =
1045         (xbt_fifo_t) xbt_dict_get_or_null(gap_lookup,
1046                                           action->sender.link_name);
1047     xbt_fifo_remove_item(fifo, action->sender.fifo_item);
1048     size = xbt_fifo_size(fifo);
1049     if (size == 0) {
1050       xbt_fifo_free(fifo);
1051       xbt_dict_remove(gap_lookup, action->sender.link_name);
1052       size = xbt_dict_length(gap_lookup);
1053       if (size == 0) {
1054         xbt_dict_free(&gap_lookup);
1055       }
1056     }
1057   }
1058 }
1059
1060 static void surf_network_model_init_internal(void)
1061 {
1062   s_surf_action_network_CM02_t comm;
1063   surf_network_model = surf_model_init();
1064
1065   surf_network_model->name = "network";
1066   surf_network_model->action_unref = net_action_unref;
1067   surf_network_model->action_cancel = net_action_cancel;
1068   surf_network_model->action_recycle = net_action_recycle;
1069   surf_network_model->get_remains = net_action_get_remains;
1070 #ifdef HAVE_LATENCY_BOUND_TRACKING
1071   surf_network_model->get_latency_limited = net_get_link_latency_limited;
1072 #endif
1073 #ifdef HAVE_TRACING
1074   surf_network_model->set_category = net_action_set_category;
1075 #endif
1076
1077   surf_network_model->model_private->resource_used = net_resource_used;
1078   if (network_update_mechanism == UM_LAZY) {
1079     surf_network_model->model_private->share_resources =
1080         net_share_resources_lazy;
1081     surf_network_model->model_private->update_actions_state =
1082         net_update_actions_state_lazy;
1083   } else if (network_update_mechanism == UM_FULL) {
1084     surf_network_model->model_private->share_resources =
1085         net_share_resources_full;
1086     surf_network_model->model_private->update_actions_state =
1087         net_update_actions_state_full;
1088   }
1089
1090   surf_network_model->model_private->update_resource_state =
1091       net_update_resource_state;
1092   surf_network_model->model_private->finalize = net_finalize;
1093
1094   surf_network_model->suspend = net_action_suspend;
1095   surf_network_model->resume = net_action_resume;
1096   surf_network_model->is_suspended = net_action_is_suspended;
1097   surf_cpu_model->set_max_duration = net_action_set_max_duration;
1098
1099   surf_network_model->extension.network.communicate = net_communicate;
1100   surf_network_model->extension.network.get_route = net_get_route;
1101   surf_network_model->extension.network.get_link_bandwidth =
1102       net_get_link_bandwidth;
1103   surf_network_model->extension.network.get_link_latency =
1104       net_get_link_latency;
1105   surf_network_model->extension.network.link_shared = net_link_shared;
1106   surf_network_model->extension.network.add_traces = net_add_traces;
1107   surf_network_model->extension.network.create_resource =
1108       net_create_resource;
1109
1110   if (!network_maxmin_system)
1111     network_maxmin_system = lmm_system_new(net_selective_update);
1112
1113   routing_model_create(sizeof(link_CM02_t),
1114                        net_create_resource("__loopback__",
1115                                            498000000, NULL, 0.000015, NULL,
1116                                            SURF_RESOURCE_ON, NULL,
1117                                            SURF_LINK_FATPIPE, NULL));
1118
1119   if (network_update_mechanism == UM_LAZY) {
1120     net_action_heap = xbt_heap_new(8, NULL);
1121     xbt_heap_set_update_callback(net_action_heap,
1122                                  net_action_update_index_heap);
1123     net_modified_set =
1124         xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
1125     network_maxmin_system->keep_track = net_modified_set;
1126   }
1127 }
1128
1129 static void set_update_mechanism(void)
1130 {
1131 #ifdef HAVE_TRACING
1132   TRACE_set_network_update_mechanism();
1133 #endif
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 }