Logo AND Algorithmique Numérique Distribuée

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