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.
9 /* Copyright (c) 2009, 2010, 2011. The SimGrid Team.
10 * All rights reserved. */
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. */
15 #include "network_private.h"
19 #include "surf_private.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"
27 #define GENERIC_ACTION(action) action->generic_action
30 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
31 "Logging specific to the SURF network module");
33 surf_model_t surf_network_model = NULL;
34 static lmm_system_t network_maxmin_system = NULL;
35 static void (*network_solve) (lmm_system_t) = NULL;
37 double sg_sender_gap = 0.0;
38 double sg_latency_factor = 1.0; /* default value; can be set by model or from command line */
39 double sg_bandwidth_factor = 1.0; /* default value; can be set by model or from command line */
40 double sg_weight_S_parameter = 0.0; /* default value; can be set by model or from command line */
42 double sg_tcp_gamma = 0.0;
43 int sg_network_crosstraffic = 0;
45 xbt_dict_t gap_lookup = NULL;
47 e_UM_t network_update_mechanism = UM_UNDEFINED;
48 static int selective_update = 0;
50 static int net_action_is_suspended(surf_action_t action);
51 static void update_action_remaining(double now);
53 static xbt_swag_t net_modified_set = NULL;
54 static xbt_heap_t net_action_heap = NULL;
55 xbt_swag_t keep_track = NULL;
57 /* added to manage the communication action's heap */
58 static void net_action_update_index_heap(void *action, int i)
60 ((surf_action_network_CM02_t) action)->index_heap = i;
63 /* insert action on heap using a given key and a hat (heap_action_type)
64 * a hat can be of three types for communications:
66 * NORMAL = this is a normal heap entry stating the date to finish transmitting
67 * LATENCY = this is a heap entry to warn us when the latency is payed
68 * MAX_DURATION =this is a heap entry to warn us when the max_duration limit is reached
70 static void heap_insert(surf_action_network_CM02_t action, double key, enum heap_action_type hat){
72 xbt_heap_push(net_action_heap, action, key);
75 static void heap_remove(surf_action_network_CM02_t action){
77 if(((surf_action_network_CM02_t) action)->index_heap >= 0){
78 xbt_heap_remove(net_action_heap,action->index_heap);
82 /******************************************************************************/
83 /* Factors callbacks */
84 /******************************************************************************/
85 static double constant_latency_factor(double size)
87 return sg_latency_factor;
90 static double constant_bandwidth_factor(double size)
92 return sg_bandwidth_factor;
95 static double constant_bandwidth_constraint(double rate, double bound,
101 /**********************/
103 /**********************/
104 static double smpi_bandwidth_factor(double size)
107 if (size >= 65472) return 0.940694;
108 if (size >= 15424) return 0.697866;
109 if (size >= 9376) return 0.58729;
110 if (size >= 5776) return 1.08739;
111 if (size >= 3484) return 0.77493;
112 if (size >= 1426) return 0.608902;
113 if (size >= 732) return 0.341987;
114 if (size >= 257) return 0.338112;
115 if (size >= 0) return 0.812084;
119 static double smpi_latency_factor(double size)
122 if (size >= 65472) return 11.6436;
123 if (size >= 15424) return 3.48845;
124 if (size >= 9376) return 2.59299;
125 if (size >= 5776) return 2.18796;
126 if (size >= 3484) return 1.88101;
127 if (size >= 1426) return 1.61075;
128 if (size >= 732) return 1.9503;
129 if (size >= 257) return 1.95341;
130 if (size >= 0) return 2.01467;
133 /**--------- <copy/paste C code snippet in surf/network.c> -----------*/
135 static double smpi_bandwidth_constraint(double rate, double bound,
138 return rate < 0 ? bound : min(bound, rate * smpi_bandwidth_factor(size));
141 static double (*latency_factor_callback) (double) =
142 &constant_latency_factor;
143 static double (*bandwidth_factor_callback) (double) =
144 &constant_bandwidth_factor;
145 static double (*bandwidth_constraint_callback) (double, double, double) =
146 &constant_bandwidth_constraint;
148 static void (*gap_append) (double, const link_CM02_t, surf_action_network_CM02_t) = NULL;
149 static void (*gap_remove) (surf_action_network_CM02_t) = NULL;
151 static void* net_create_resource(const char *name,
153 tmgr_trace_t bw_trace,
155 tmgr_trace_t lat_trace,
156 e_surf_resource_state_t
158 tmgr_trace_t state_trace,
159 e_surf_link_sharing_policy_t
160 policy, xbt_dict_t properties)
162 link_CM02_t nw_link = (link_CM02_t)
163 surf_resource_lmm_new(sizeof(s_link_CM02_t),
164 surf_network_model, name, properties,
165 network_maxmin_system,
166 sg_bandwidth_factor * bw_initial,
168 state_initial, state_trace,
169 bw_initial, bw_trace);
171 xbt_assert(!xbt_lib_get_or_null(link_lib, name, SURF_LINK_LEVEL),
172 "Link '%s' declared several times in the platform file.",
175 nw_link->lat_current = lat_initial;
178 tmgr_history_add_trace(history, lat_trace, 0.0, 0, nw_link);
180 if (policy == SURF_LINK_FATPIPE)
181 lmm_constraint_shared(nw_link->lmm_resource.constraint);
183 xbt_lib_set(link_lib, name, SURF_LINK_LEVEL, nw_link);
188 static void net_parse_link_init(sg_platf_link_cbarg_t link)
190 if(link->policy == SURF_LINK_FULLDUPLEX){
192 link_id = bprintf("%s_UP", link->id);
193 net_create_resource(link_id,
195 link->bandwidth_trace,
203 link_id = bprintf("%s_DOWN", link->id);
204 net_create_resource(link_id,
206 link->bandwidth_trace,
216 net_create_resource(link->id,
218 link->bandwidth_trace,
228 static void net_add_traces(void)
230 xbt_dict_cursor_t cursor = NULL;
231 char *trace_name, *elm;
233 static int called = 0;
238 /* connect all traces relative to network */
239 xbt_dict_foreach(trace_connect_list_link_avail, cursor, trace_name, elm) {
240 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
242 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
244 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
247 "Cannot connect trace %s to link %s: trace undefined",
250 link->lmm_resource.state_event =
251 tmgr_history_add_trace(history, trace, 0.0, 0, link);
254 xbt_dict_foreach(trace_connect_list_bandwidth, cursor, trace_name, elm) {
255 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
257 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
259 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
262 "Cannot connect trace %s to link %s: trace undefined",
265 link->lmm_resource.power.event =
266 tmgr_history_add_trace(history, trace, 0.0, 0, link);
269 xbt_dict_foreach(trace_connect_list_latency, cursor, trace_name, elm) {
270 tmgr_trace_t trace = xbt_dict_get_or_null(traces_set_list, trace_name);
272 xbt_lib_get_or_null(link_lib, elm, SURF_LINK_LEVEL);
274 xbt_assert(link, "Cannot connect trace %s to link %s: link undefined",
277 "Cannot connect trace %s to link %s: trace undefined",
280 link->lat_event = tmgr_history_add_trace(history, trace, 0.0, 0, link);
284 static void net_define_callbacks(void)
286 /* Figuring out the network links */
287 sg_platf_link_add_cb(net_parse_link_init);
288 sg_platf_postparse_add_cb(net_add_traces);
291 static int net_resource_used(void *resource_id)
293 return lmm_constraint_used(network_maxmin_system,
294 ((surf_resource_lmm_t)
295 resource_id)->constraint);
298 static int net_action_unref(surf_action_t action)
301 if (!action->refcount) {
302 xbt_swag_remove(action, action->state_set);
303 if (((surf_action_network_CM02_t) action)->variable){
304 lmm_variable_free(network_maxmin_system,
305 ((surf_action_network_CM02_t) action)->variable);
307 if(network_update_mechanism == UM_LAZY){// remove action from the heap
308 heap_remove((surf_action_network_CM02_t) action);
309 xbt_swag_remove(action, net_modified_set);
312 xbt_free(((surf_action_network_CM02_t) action)->src_name);
313 xbt_free(((surf_action_network_CM02_t) action)->dst_name);
314 xbt_free(action->category);
316 surf_action_free(&action);
324 static void net_action_cancel(surf_action_t action)
326 XBT_DEBUG("cancel action %p",action);
327 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
328 if(network_update_mechanism == UM_LAZY){// remove action from the heap
329 xbt_swag_remove(action, net_modified_set);
330 heap_remove((surf_action_network_CM02_t) action);
334 void net_action_recycle(surf_action_t action)
339 #ifdef HAVE_LATENCY_BOUND_TRACKING
340 static int net_get_link_latency_limited(surf_action_t action)
342 return action->latency_limited;
346 double net_action_get_remains(surf_action_t action)
348 if(network_update_mechanism == UM_LAZY)/* update remains before return it */
349 update_action_remaining(surf_get_clock());
350 return action->remains;
353 static void update_action_remaining(double now){
354 surf_action_network_CM02_t action = NULL;
357 xbt_swag_foreach(action, net_modified_set) {
359 if(action->suspended != 0){
363 delta = now - action->last_update;
365 double_update(&(action->generic_action.remains),
366 lmm_variable_getvalue(action->variable) * delta);
368 if (action->generic_action.max_duration != NO_MAX_DURATION)
369 double_update(&(action->generic_action.max_duration), delta);
371 if ((action->generic_action.remains <= 0) &&
372 (lmm_get_variable_weight(action->variable) > 0)) {
373 action->generic_action.finish = surf_get_clock();
374 surf_network_model->action_state_set((surf_action_t) action,
377 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
378 && (action->generic_action.max_duration <= 0)) {
379 action->generic_action.finish = surf_get_clock();
380 surf_network_model->action_state_set((surf_action_t) action,
385 action->last_update = now;
389 static double net_share_resources_full(double now)
391 s_surf_action_network_CM02_t s_action;
392 surf_action_network_CM02_t action = NULL;
393 xbt_swag_t running_actions =
394 surf_network_model->states.running_action_set;
397 min = generic_maxmin_share_resources(running_actions,
398 xbt_swag_offset(s_action,
400 network_maxmin_system,
403 #define VARIABLE(action) (*((lmm_variable_t*)(((char *) (action)) + xbt_swag_offset(s_action, variable) )))
405 xbt_swag_foreach(action, running_actions) {
406 #ifdef HAVE_LATENCY_BOUND_TRACKING
407 if (lmm_is_variable_limited_by_latency(action->variable)) {
408 (action->generic_action).latency_limited = 1;
410 (action->generic_action).latency_limited = 0;
413 if (action->latency > 0) {
414 min = (min<0)?action->latency:min(min,action->latency);
418 XBT_DEBUG("Min of share resources %f", min);
423 static double net_share_resources_lazy(double now)
425 surf_action_network_CM02_t action = NULL;
429 XBT_DEBUG("Before share resources, the size of modified actions set is %d", xbt_swag_size(net_modified_set));
430 update_action_remaining(now);
432 keep_track = net_modified_set;
433 lmm_solve(network_maxmin_system);
436 XBT_DEBUG("After share resources, The size of modified actions set is %d", xbt_swag_size(net_modified_set));
438 xbt_swag_foreach(action, net_modified_set) {
439 int max_dur_flag = 0;
441 if (GENERIC_ACTION(action).state_set != surf_network_model->states.running_action_set){
445 /* bogus priority, skip it */
446 if (GENERIC_ACTION(action).priority <= 0){
451 value = lmm_variable_getvalue(action->variable);
453 if (GENERIC_ACTION(action).remains > 0) {
454 value = GENERIC_ACTION(action).remains / value;
462 if ((GENERIC_ACTION(action).max_duration != NO_MAX_DURATION)
464 || GENERIC_ACTION(action).start +
465 GENERIC_ACTION(action).max_duration < min)){
466 min = GENERIC_ACTION(action).start +
467 GENERIC_ACTION(action).max_duration;
471 XBT_DEBUG("Action(%p) Start %lf Finish %lf Max_duration %lf", action,
472 GENERIC_ACTION(action).start, now + value,
473 GENERIC_ACTION(action).max_duration);
475 if (action->index_heap >= 0) {
476 heap_remove((surf_action_network_CM02_t) action);
480 heap_insert((surf_action_network_CM02_t) action, min, max_dur_flag?MAX_DURATION:NORMAL);
481 XBT_DEBUG("Insert at heap action(%p) min %lf now %lf", action, min, now);
485 //hereafter must have already the min value for this resource model
486 if(xbt_heap_size(net_action_heap) > 0 ){
487 min = xbt_heap_maxkey(net_action_heap) - now ;
492 XBT_DEBUG("The minimum with the HEAP %lf", min);
497 static void net_update_actions_state_full(double now, double delta)
500 surf_action_network_CM02_t action = NULL;
501 surf_action_network_CM02_t next_action = NULL;
502 xbt_swag_t running_actions =
503 surf_network_model->states.running_action_set;
505 xbt_swag_t failed_actions =
506 surf_network_model->states.failed_action_set;
509 xbt_swag_foreach_safe(action, next_action, running_actions) {
511 if (action->latency > 0) {
512 if (action->latency > deltap) {
513 double_update(&(action->latency), deltap);
516 double_update(&(deltap), action->latency);
517 action->latency = 0.0;
519 if ((action->latency == 0.0) && !(action->suspended))
520 lmm_update_variable_weight(network_maxmin_system, action->variable,
524 if (TRACE_is_enabled()) {
525 xbt_dynar_t route=NULL;
526 routing_get_route_and_latency(action->src_name, action->dst_name,&route,NULL);
529 xbt_dynar_foreach(route, i, link) {
530 TRACE_surf_link_set_utilization(link->lmm_resource.generic_resource.name,
531 action->generic_action.data,
532 (surf_action_t) action,
533 lmm_variable_getvalue
534 (action->variable), now - delta,
539 if(!lmm_get_number_of_cnst_from_var(network_maxmin_system, action->variable)) {
540 /* There is actually no link used, hence an infinite bandwidth.
541 * This happens often when using models like vivaldi.
542 * In such case, just make sure that the action completes immediately.
544 double_update(&(action->generic_action.remains),
545 action->generic_action.remains);
547 double_update(&(action->generic_action.remains),
548 lmm_variable_getvalue(action->variable) * deltap);
549 if (action->generic_action.max_duration != NO_MAX_DURATION)
550 double_update(&(action->generic_action.max_duration), delta);
552 if ((action->generic_action.remains <= 0) &&
553 (lmm_get_variable_weight(action->variable) > 0)) {
554 action->generic_action.finish = surf_get_clock();
555 surf_network_model->action_state_set((surf_action_t) action,
558 if(gap_remove) gap_remove(action);
559 } else if ((action->generic_action.max_duration != NO_MAX_DURATION)
560 && (action->generic_action.max_duration <= 0)) {
561 action->generic_action.finish = surf_get_clock();
562 surf_network_model->action_state_set((surf_action_t) action,
564 if(gap_remove) gap_remove(action);
571 static void net_update_actions_state_lazy(double now, double delta)
573 surf_action_network_CM02_t action = NULL;
575 while ((xbt_heap_size(net_action_heap) > 0)
576 && (double_equals(xbt_heap_maxkey(net_action_heap), now))) {
577 action = xbt_heap_pop(net_action_heap);
578 XBT_DEBUG("Action %p: finish", action);
579 GENERIC_ACTION(action).finish = surf_get_clock();
581 // if I am wearing a latency heat
582 if( action->hat == LATENCY){
583 lmm_update_variable_weight(network_maxmin_system, action->variable,
586 action->last_update = surf_get_clock();
588 // if I am wearing a max_duration or normal hat
589 }else if( action->hat == MAX_DURATION || action->hat == NORMAL ){
590 // no need to communicate anymore
591 // assume that flows that reached max_duration have remaining of 0
592 GENERIC_ACTION(action).remains = 0;
593 action->generic_action.finish = surf_get_clock();
594 surf_network_model->action_state_set((surf_action_t) action,
602 static void net_update_resource_state(void *id,
603 tmgr_trace_event_t event_type,
604 double value, double date)
606 link_CM02_t nw_link = id;
607 /* printf("[" "%lg" "] Asking to update network card \"%s\" with value " */
608 /* "%lg" " for event %p\n", surf_get_clock(), nw_link->name, */
609 /* value, event_type); */
611 if (event_type == nw_link->lmm_resource.power.event) {
613 sg_weight_S_parameter / value - sg_weight_S_parameter /
614 (nw_link->lmm_resource.power.peak *
615 nw_link->lmm_resource.power.scale);
616 lmm_variable_t var = NULL;
617 lmm_element_t elem = NULL;
618 surf_action_network_CM02_t action = NULL;
620 nw_link->lmm_resource.power.peak = value;
621 lmm_update_constraint_bound(network_maxmin_system,
622 nw_link->lmm_resource.constraint,
623 sg_bandwidth_factor *
624 (nw_link->lmm_resource.power.peak *
625 nw_link->lmm_resource.power.scale));
627 TRACE_surf_link_set_bandwidth(date, (char *)(((nw_link->lmm_resource).generic_resource).name),
628 sg_bandwidth_factor *
629 (nw_link->lmm_resource.power.peak *
630 nw_link->lmm_resource.power.scale));
632 if (sg_weight_S_parameter > 0) {
633 while ((var = lmm_get_var_from_cnst
634 (network_maxmin_system, nw_link->lmm_resource.constraint,
636 action = lmm_variable_id(var);
637 action->weight += delta;
638 if (!(action->suspended))
639 lmm_update_variable_weight(network_maxmin_system,
640 action->variable, action->weight);
643 if (tmgr_trace_event_free(event_type))
644 nw_link->lmm_resource.power.event = NULL;
645 } else if (event_type == nw_link->lat_event) {
646 double delta = value - nw_link->lat_current;
647 lmm_variable_t var = NULL;
648 lmm_element_t elem = NULL;
649 surf_action_network_CM02_t action = NULL;
651 nw_link->lat_current = value;
652 while ((var = lmm_get_var_from_cnst
653 (network_maxmin_system, nw_link->lmm_resource.constraint,
655 action = lmm_variable_id(var);
656 action->lat_current += delta;
657 action->weight += delta;
658 if (action->rate < 0)
659 lmm_update_variable_bound(network_maxmin_system, action->variable,
660 sg_tcp_gamma / (2.0 *
661 action->lat_current));
663 lmm_update_variable_bound(network_maxmin_system, action->variable,
665 sg_tcp_gamma / (2.0 *
666 action->lat_current)));
668 if (action->rate < sg_tcp_gamma / (2.0 * action->lat_current)) {
669 XBT_INFO("Flow is limited BYBANDWIDTH");
671 XBT_INFO("Flow is limited BYLATENCY, latency of flow is %f",
672 action->lat_current);
675 if (!(action->suspended))
676 lmm_update_variable_weight(network_maxmin_system, action->variable,
680 if (tmgr_trace_event_free(event_type))
681 nw_link->lat_event = NULL;
682 } else if (event_type == nw_link->lmm_resource.state_event) {
684 nw_link->lmm_resource.state_current = SURF_RESOURCE_ON;
686 lmm_constraint_t cnst = nw_link->lmm_resource.constraint;
687 lmm_variable_t var = NULL;
688 lmm_element_t elem = NULL;
690 nw_link->lmm_resource.state_current = SURF_RESOURCE_OFF;
691 while ((var = lmm_get_var_from_cnst
692 (network_maxmin_system, cnst, &elem))) {
693 surf_action_t action = lmm_variable_id(var);
695 if (surf_action_state_get(action) == SURF_ACTION_RUNNING ||
696 surf_action_state_get(action) == SURF_ACTION_READY) {
697 action->finish = date;
698 surf_network_model->action_state_set(action, SURF_ACTION_FAILED);
702 if (tmgr_trace_event_free(event_type))
703 nw_link->lmm_resource.state_event = NULL;
705 XBT_CRITICAL("Unknown event ! \n");
709 XBT_DEBUG("There were a resource state event, need to update actions related to the constraint (%p)", nw_link->lmm_resource.constraint);
714 static surf_action_t net_communicate(const char *src_name,
715 const char *dst_name, double size,
721 surf_action_network_CM02_t action = NULL;
722 double bandwidth_bound;
724 xbt_dynar_t back_route = NULL;
725 int constraints_per_variable = 0;
727 xbt_dynar_t route=xbt_dynar_new(global_routing->size_of_link,NULL);
729 XBT_IN("(%s,%s,%g,%g)", src_name, dst_name, size, rate);
731 routing_get_route_and_latency(src_name, dst_name, &route, &latency);
732 xbt_assert(!xbt_dynar_is_empty(route) || latency,
733 "You're trying to send data from %s to %s but there is no connection at all between these two hosts.",
736 xbt_dynar_foreach(route, i, link) {
737 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
742 if (sg_network_crosstraffic == 1) {
743 routing_get_route_and_latency(dst_name, src_name, &back_route,NULL);
744 xbt_dynar_foreach(back_route, i, link) {
745 if (link->lmm_resource.state_current == SURF_RESOURCE_OFF) {
753 surf_action_new(sizeof(s_surf_action_network_CM02_t), size,
754 surf_network_model, failed);
755 #ifdef HAVE_LATENCY_BOUND_TRACKING
756 (action->generic_action).latency_limited = 0;
758 action->weight = action->latency = latency;
760 xbt_swag_insert(action, action->generic_action.state_set);
762 if(network_update_mechanism == UM_LAZY){
763 action->index_heap = -1;
764 action->last_update = surf_get_clock();
767 bandwidth_bound = -1.0;
768 if(sg_weight_S_parameter>0) {
769 xbt_dynar_foreach(route, i, link) {
771 sg_weight_S_parameter /
772 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
775 xbt_dynar_foreach(route, i, link) {
776 double bb = bandwidth_factor_callback(size) *
777 (link->lmm_resource.power.peak * link->lmm_resource.power.scale);
778 bandwidth_bound = (bandwidth_bound < 0.0)?bb:min(bandwidth_bound,bb);
781 action->lat_current = action->latency;
782 action->latency *= latency_factor_callback(size);
784 bandwidth_constraint_callback(action->rate, bandwidth_bound,
787 xbt_assert(!xbt_dynar_is_empty(route),"Using a model with a gap (e.g., SMPI) with a platform without links (e.g. vivaldi)!!!");
789 link = *(link_CM02_t*)xbt_dynar_get_ptr(route, 0);
790 gap_append(size, link, action);
791 XBT_DEBUG("Comm %p: %s -> %s gap=%f (lat=%f)",
792 action, src_name, dst_name, action->sender.gap, action->latency);
795 constraints_per_variable = xbt_dynar_length(route);
796 if (back_route != NULL)
797 constraints_per_variable += xbt_dynar_length(back_route);
799 if (action->latency > 0){
801 lmm_variable_new(network_maxmin_system, action, 0.0, -1.0,
802 constraints_per_variable);
803 if(network_update_mechanism == UM_LAZY){
804 // add to the heap the event when the latency is payed
805 XBT_DEBUG("Added action (%p) one latency event at date %f", action, action->latency + action->last_update);
806 heap_insert(action, action->latency + action->last_update, xbt_dynar_is_empty(route)?NORMAL:LATENCY);
810 lmm_variable_new(network_maxmin_system, action, 1.0, -1.0,
811 constraints_per_variable);
813 if (action->rate < 0) {
814 lmm_update_variable_bound(network_maxmin_system, action->variable,
815 (action->lat_current > 0)?
816 sg_tcp_gamma / (2.0 * action->lat_current) :-1.0);
818 lmm_update_variable_bound(network_maxmin_system, action->variable,
819 (action->lat_current > 0)?
820 min(action->rate, sg_tcp_gamma / (2.0 * action->lat_current))
824 xbt_dynar_foreach(route, i, link) {
825 lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
826 action->variable, 1.0);
829 if (sg_network_crosstraffic == 1) {
830 XBT_DEBUG("Fullduplex active adding backward flow using 5%%");
831 xbt_dynar_foreach(back_route, i, link) {
832 lmm_expand(network_maxmin_system, link->lmm_resource.constraint,
833 action->variable, .05);
838 if (TRACE_is_enabled()) {
839 action->src_name = xbt_strdup(src_name);
840 action->dst_name = xbt_strdup(dst_name);
842 action->src_name = action->dst_name = NULL;
846 xbt_dynar_free(&route);
849 return (surf_action_t) action;
852 static xbt_dynar_t net_get_route(const char *src, const char *dst)
854 xbt_dynar_t route=NULL;
855 routing_get_route_and_latency(src, dst,&route,NULL);
859 static double net_get_link_bandwidth(const void *link)
861 surf_resource_lmm_t lmm = (surf_resource_lmm_t) link;
862 return lmm->power.peak * lmm->power.scale;
865 static double net_get_link_latency(const void *link)
867 return ((link_CM02_t) link)->lat_current;
870 static int net_link_shared(const void *link)
873 lmm_constraint_is_shared(((surf_resource_lmm_t) link)->constraint);
876 static void net_action_suspend(surf_action_t action)
878 ((surf_action_network_CM02_t) action)->suspended = 1;
879 lmm_update_variable_weight(network_maxmin_system,
880 ((surf_action_network_CM02_t)
881 action)->variable, 0.0);
883 if(network_update_mechanism == UM_LAZY)// remove action from the heap
884 heap_remove((surf_action_network_CM02_t) action);
887 static void net_action_resume(surf_action_t action)
889 if (((surf_action_network_CM02_t) action)->suspended) {
890 lmm_update_variable_weight(network_maxmin_system,
891 ((surf_action_network_CM02_t)
893 ((surf_action_network_CM02_t)
895 ((surf_action_network_CM02_t) action)->suspended = 0;
896 if(network_update_mechanism == UM_LAZY)// remove action from the heap
897 heap_remove((surf_action_network_CM02_t) action);
901 static int net_action_is_suspended(surf_action_t action)
903 return ((surf_action_network_CM02_t) action)->suspended;
906 void net_action_set_max_duration(surf_action_t action, double duration)
908 action->max_duration = duration;
909 if(network_update_mechanism == UM_LAZY)// remove action from the heap
910 heap_remove((surf_action_network_CM02_t) action);
914 static void net_action_set_category(surf_action_t action, const char *category)
916 action->category = xbt_strdup (category);
920 static void net_finalize(void)
922 surf_model_exit(surf_network_model);
923 surf_network_model = NULL;
925 lmm_system_free(network_maxmin_system);
926 network_maxmin_system = NULL;
928 if(network_update_mechanism == UM_LAZY){
929 xbt_heap_free(net_action_heap);
930 xbt_swag_free(net_modified_set);
934 static void smpi_gap_append(double size, const link_CM02_t link, surf_action_network_CM02_t action) {
935 const char* src = link->lmm_resource.generic_resource.name;
937 surf_action_network_CM02_t last_action;
940 if(sg_sender_gap > 0.0) {
942 gap_lookup = xbt_dict_new();
944 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, src);
945 action->sender.gap = 0.0;
946 if(fifo && xbt_fifo_size(fifo) > 0) {
947 /* Compute gap from last send */
948 last_action = (surf_action_network_CM02_t)xbt_fifo_get_item_content(xbt_fifo_get_last_item(fifo));
949 bw = net_get_link_bandwidth(link);
950 action->sender.gap = last_action->sender.gap + max(sg_sender_gap, last_action->sender.size / bw);
951 action->latency += action->sender.gap;
953 /* Append action as last send */
954 action->sender.link_name = link->lmm_resource.generic_resource.name;
955 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
957 fifo = xbt_fifo_new();
958 xbt_dict_set(gap_lookup, action->sender.link_name, fifo, NULL);
960 action->sender.fifo_item = xbt_fifo_push(fifo, action);
961 action->sender.size = size;
965 static void smpi_gap_remove(surf_action_network_CM02_t action) {
969 if(sg_sender_gap > 0.0 && action->sender.link_name && action->sender.fifo_item) {
970 fifo = (xbt_fifo_t)xbt_dict_get_or_null(gap_lookup, action->sender.link_name);
971 xbt_fifo_remove_item(fifo, action->sender.fifo_item);
972 size = xbt_fifo_size(fifo);
975 xbt_dict_remove(gap_lookup, action->sender.link_name);
976 size = xbt_dict_length(gap_lookup);
978 xbt_dict_free(&gap_lookup);
984 static void surf_network_model_init_internal(void)
986 s_surf_action_network_CM02_t comm;
987 surf_network_model = surf_model_init();
989 surf_network_model->name = "network";
990 surf_network_model->action_unref = net_action_unref;
991 surf_network_model->action_cancel = net_action_cancel;
992 surf_network_model->action_recycle = net_action_recycle;
993 surf_network_model->get_remains = net_action_get_remains;
994 #ifdef HAVE_LATENCY_BOUND_TRACKING
995 surf_network_model->get_latency_limited = net_get_link_latency_limited;
998 surf_network_model->model_private->resource_used = net_resource_used;
999 if(network_update_mechanism == UM_LAZY) {
1000 surf_network_model->model_private->share_resources = net_share_resources_lazy;
1001 surf_network_model->model_private->update_actions_state = net_update_actions_state_lazy;
1002 } else if(network_update_mechanism == UM_FULL) {
1003 surf_network_model->model_private->share_resources = net_share_resources_full;
1004 surf_network_model->model_private->update_actions_state = net_update_actions_state_full;
1007 surf_network_model->model_private->update_resource_state =
1008 net_update_resource_state;
1009 surf_network_model->model_private->finalize = net_finalize;
1011 surf_network_model->suspend = net_action_suspend;
1012 surf_network_model->resume = net_action_resume;
1013 surf_network_model->is_suspended = net_action_is_suspended;
1014 surf_cpu_model->set_max_duration = net_action_set_max_duration;
1016 surf_network_model->extension.network.communicate = net_communicate;
1017 surf_network_model->extension.network.get_route = net_get_route;
1018 surf_network_model->extension.network.get_link_bandwidth =
1019 net_get_link_bandwidth;
1020 surf_network_model->extension.network.get_link_latency =
1021 net_get_link_latency;
1022 surf_network_model->extension.network.link_shared = net_link_shared;
1023 surf_network_model->extension.network.add_traces = net_add_traces;
1024 surf_network_model->extension.network.create_resource =
1025 net_create_resource;
1027 if (!network_maxmin_system)
1028 network_maxmin_system = lmm_system_new(selective_update);
1030 routing_model_create(sizeof(link_CM02_t),
1031 net_create_resource("__loopback__",
1032 498000000, NULL, 0.000015, NULL,
1033 SURF_RESOURCE_ON, NULL,
1034 SURF_LINK_FATPIPE, NULL));
1036 if(network_update_mechanism == UM_LAZY){
1037 net_action_heap = xbt_heap_new(8,NULL);
1038 xbt_heap_set_update_callback(net_action_heap, net_action_update_index_heap);
1040 xbt_swag_new(xbt_swag_offset(comm, action_list_hookup));
1044 static void set_update_mechanism(void) {
1045 char *optim = xbt_cfg_get_string(_surf_cfg_set, "network/optim");
1046 int select = xbt_cfg_get_int(_surf_cfg_set, "network/maxmin_selective_update");
1048 if(!strcmp(optim,"Full")) {
1049 network_update_mechanism = UM_FULL;
1050 selective_update = select;
1051 } else if (!strcmp(optim,"Lazy")) {
1052 network_update_mechanism = UM_LAZY;
1053 selective_update = 1;
1054 xbt_assert((select==1) || (xbt_cfg_is_default_value(_surf_cfg_set,"network/maxmin_selective_update")),
1055 "Disabling selective update while using the lazy update mechanism is dumb!");
1057 xbt_die("Unsupported optimization (%s) for this model",optim);
1061 /************************************************************************/
1062 /* New model based on LV08 and experimental results of MPI ping-pongs */
1063 /************************************************************************/
1064 /* @Inproceedings{smpi_ipdps, */
1065 /* author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
1066 /* title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
1067 /* booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
1068 /* address={Anchorage (Alaska) USA}, */
1072 void surf_network_model_init_SMPI(void)
1075 if (surf_network_model)
1077 set_update_mechanism();
1079 surf_network_model_init_internal();
1080 latency_factor_callback = &smpi_latency_factor;
1081 bandwidth_factor_callback = &smpi_bandwidth_factor;
1082 bandwidth_constraint_callback = &smpi_bandwidth_constraint;
1083 gap_append = &smpi_gap_append;
1084 gap_remove = &smpi_gap_remove;
1085 net_define_callbacks();
1086 xbt_dynar_push(model_list, &surf_network_model);
1087 network_solve = lmm_solve;
1089 xbt_cfg_setdefault_double(_surf_cfg_set, "network/sender_gap", 10e-6);
1090 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1093 /************************************************************************/
1094 /* New model based on optimizations discussed during Pedro Velho's thesis*/
1095 /************************************************************************/
1096 /* @techreport{VELHO:2011:HAL-00646896:1, */
1097 /* url = {http://hal.inria.fr/hal-00646896/en/}, */
1098 /* title = {{Flow-level network models: have we reached the limits?}}, */
1099 /* author = {Velho, Pedro and Schnorr, Lucas and Casanova, Henri and Legrand, Arnaud}, */
1100 /* type = {Rapport de recherche}, */
1101 /* institution = {INRIA}, */
1102 /* number = {RR-7821}, */
1103 /* year = {2011}, */
1105 /* pdf = {http://hal.inria.fr/hal-00646896/PDF/rr-validity.pdf}, */
1107 void surf_network_model_init_LegrandVelho(void)
1109 if (surf_network_model)
1112 set_update_mechanism();
1114 surf_network_model_init_internal();
1115 net_define_callbacks();
1116 xbt_dynar_push(model_list, &surf_network_model);
1117 network_solve = lmm_solve;
1119 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4); // 13.01 when callibration is done without phase effects
1120 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",0.92);// 0.97 when callibration is done without phase effects
1121 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775); // 20537 when callibration is done without phase effects
1124 /***************************************************************************/
1125 /* The nice TCP sharing model designed by Loris Marchal and Henri Casanova */
1126 /***************************************************************************/
1127 /* @TechReport{ rr-lip2002-40, */
1128 /* author = {Henri Casanova and Loris Marchal}, */
1129 /* institution = {LIP}, */
1130 /* title = {A Network Model for Simulation of Grid Application}, */
1131 /* number = {2002-40}, */
1132 /* month = {oct}, */
1135 void surf_network_model_init_CM02(void)
1138 if (surf_network_model)
1141 set_update_mechanism();
1142 surf_network_model_init_internal();
1143 net_define_callbacks();
1144 xbt_dynar_push(model_list, &surf_network_model);
1145 network_solve = lmm_solve;
1147 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 1.0);
1148 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor", 1.0);
1149 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 0.0);
1152 /***************************************************************************/
1153 /* The models from Steven H. Low */
1154 /***************************************************************************/
1155 /* @article{Low03, */
1156 /* author={Steven H. Low}, */
1157 /* title={A Duality Model of {TCP} and Queue Management Algorithms}, */
1159 /* journal={{IEEE/ACM} Transactions on Networking}, */
1160 /* volume={11}, number={4}, */
1162 void surf_network_model_init_Reno(void)
1164 if (surf_network_model)
1167 set_update_mechanism();
1168 surf_network_model_init_internal();
1169 net_define_callbacks();
1171 xbt_dynar_push(model_list, &surf_network_model);
1172 lmm_set_default_protocol_function(func_reno_f, func_reno_fp,
1174 network_solve = lagrange_solve;
1176 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1177 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1179 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);
1183 void surf_network_model_init_Reno2(void)
1185 if (surf_network_model)
1188 set_update_mechanism();
1189 surf_network_model_init_internal();
1190 net_define_callbacks();
1192 xbt_dynar_push(model_list, &surf_network_model);
1193 lmm_set_default_protocol_function(func_reno2_f, func_reno2_fp,
1195 network_solve = lagrange_solve;
1197 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1198 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1200 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S_parameter",
1204 void surf_network_model_init_Vegas(void)
1206 if (surf_network_model)
1209 set_update_mechanism();
1210 surf_network_model_init_internal();
1211 net_define_callbacks();
1213 xbt_dynar_push(model_list, &surf_network_model);
1214 lmm_set_default_protocol_function(func_vegas_f, func_vegas_fp,
1216 network_solve = lagrange_solve;
1218 xbt_cfg_setdefault_double(_surf_cfg_set, "network/latency_factor", 10.4);
1219 xbt_cfg_setdefault_double(_surf_cfg_set, "network/bandwidth_factor",
1221 xbt_cfg_setdefault_double(_surf_cfg_set, "network/weight_S", 8775);