X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ad32fd753f73b8a8a14242781eb011e78446995a..f601750c63a340979328ed9817fe225c5ce43959:/src/include/surf/maxmin.h diff --git a/src/include/surf/maxmin.h b/src/include/surf/maxmin.h index 9aa09d257c..df7571f3dc 100644 --- a/src/include/surf/maxmin.h +++ b/src/include/surf/maxmin.h @@ -1,22 +1,27 @@ -/* Copyright (c) 2004-2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef _SURF_MAXMIN_H -#define _SURF_MAXMIN_H +#ifndef SURF_MAXMIN_H +#define SURF_MAXMIN_H -#include "src/portable.h" +#include "src/internal_config.h" #include "xbt/misc.h" #include "xbt/asserts.h" #include "surf/datatypes.h" #include -/** @addtogroup SURF_lmm - * @details +namespace simgrid { +namespace surf { +class Action; +} +} + +/** @addtogroup SURF_lmm + * @details * A linear maxmin solver to resolve inequations systems. - * + * * Most SimGrid model rely on a "fluid/steady-state" modeling that simulate the sharing of resources between actions at * relatively coarse-grain. Such sharing is generally done by solving a set of linear inequations. Let's take an * example and assume we have the variables \f$x_1\f$, \f$x_2\f$, \f$x_3\f$, and \f$x_4\f$ . Let's say that \f$x_1\f$ @@ -39,7 +44,7 @@ * This is called *max-min fairness* and is the most commonly used objective in SimGrid. Another possibility is to * maximize \f$\sum_if(x_i)\f$, where \f$f\f$ is a strictly increasing concave function. * - * Constraint: + * Constraint: * - bound (set) * - shared (set) * - usage (computed) @@ -51,7 +56,7 @@ * * Element: * - value (set) - * + * * A possible system could be: * - three variables: `var1`, `var2`, `var3` * - two constraints: `cons1`, `cons2` @@ -60,19 +65,19 @@ * - `elem2` linking `var2` and `cons1` * - `elem3` linking `var2` and `cons2` * - `elem4` linking `var3` and `cons2` - * + * * And the corresponding inequations will be: - * + * * var1.value <= var1.bound * var2.value <= var2.bound * var3.value <= var3.bound * var1.weight * var1.value * elem1.value + var2.weight * var2.value * elem2.value <= cons1.bound * var2.weight * var2.value * elem3.value + var3.weight * var3.value * elem4.value <= cons2.bound - * + * * where `var1.value`, `var2.value` and `var3.value` are the unknown values. - * - * If a constraint is not shared, the sum is replaced by a max. - * For example, a third non-shared constraint `cons3` and the associated elements `elem5` and `elem6` could write as: + * + * If a constraint is not shared, the sum is replaced by a max. + * For example, a third non-shared constraint `cons3` and the associated elements `elem5` and `elem6` could write as: * * max( var1.weight * var1.value * elem5.value , var3.weight * var3.value * elem6.value ) <= cons3.bound * @@ -94,28 +99,28 @@ * (lmm_solve()) activates it when appropriate. It is possible that the variable is again disabled, e.g. to model the * pausing of an action. * - * Concurrency limit and maximum - * - * We call concurrency, the number of variables that can be enabled at any time for each constraint. + * Concurrency limit and maximum + * + * We call concurrency, the number of variables that can be enabled at any time for each constraint. * From a model perspective, this "concurrency" often represents the number of actions that actually compete for one * constraint. * The LMM solver is able to limit the concurrency for each constraint, and to monitor its maximum value. - * + * * One may want to limit the concurrency of constraints for essentially three reasons: * - Keep LMM system in a size that can be solved (it does not react very well with tens of thousands of variables per * constraint) - * - Stay within parameters where the fluid model is accurate enough. + * - Stay within parameters where the fluid model is accurate enough. * - Model serialization effects * * The concurrency limit can also be set to a negative value to disable concurrency limit. This can improve performance * slightly. - * + * * Overall, each constraint contains three fields related to concurrency: * - concurrency_limit which is the limit enforced by the solver * - concurrency_current which is the current concurrency - * - concurrency_maximum which is the observed maximum concurrency + * - concurrency_maximum which is the observed maximum concurrency * - * Variables also have one field related to concurrency: concurrency_share. + * Variables also have one field related to concurrency: concurrency_share. * In effect, in some cases, one variable is involved multiple times (i.e. two elements) in a constraint. * For example, cross-traffic is modeled using 2 elements per constraint. * concurrency_share formally corresponds to the maximum number of elements that associate the variable and any given @@ -124,8 +129,9 @@ XBT_PUBLIC_DATA(double) sg_maxmin_precision; XBT_PUBLIC_DATA(double) sg_surf_precision; - -static XBT_INLINE void double_update(double *variable, double value, double precision) +XBT_PUBLIC_DATA(int) sg_concurrency_limit; + +static inline void double_update(double *variable, double value, double precision) { //printf("Updating %g -= %g +- %g\n",*variable,value,precision); //xbt_assert(value==0 || value>precision); @@ -137,12 +143,12 @@ static XBT_INLINE void double_update(double *variable, double value, double prec *variable = 0.0; } -static XBT_INLINE int double_positive(double value, double precision) +static inline int double_positive(double value, double precision) { return (value > precision); } -static XBT_INLINE int double_equals(double value1, double value2, double precision) +static inline int double_equals(double value1, double value2, double precision) { return (fabs(value1 - value2) < precision); } @@ -152,9 +158,9 @@ SG_BEGIN_DECL() /** @{ @ingroup SURF_lmm */ /** * @brief Create a new Linear MaxMim system - * @param selective_update [description] + * @param selective_update whether we should do lazy updates */ -XBT_PUBLIC(lmm_system_t) lmm_system_new(int selective_update); +XBT_PUBLIC(lmm_system_t) lmm_system_new(bool selective_update); /** * @brief Free an existing Linear MaxMin system @@ -166,7 +172,7 @@ XBT_PUBLIC(void) lmm_system_free(lmm_system_t sys); * @brief Create a new Linear MaxMin constraint * @param sys The system in which we add a constraint * @param id Data associated to the constraint (e.g.: a network link) - * @param bound_value The bound value of the constraint + * @param bound_value The bound value of the constraint */ XBT_PUBLIC(lmm_constraint_t) lmm_constraint_new(lmm_system_t sys, void *id,double bound_value); @@ -197,6 +203,8 @@ XBT_PUBLIC(void) lmm_constraint_free(lmm_system_t sys, lmm_constraint_t cnst); */ XBT_PUBLIC(double) lmm_constraint_get_usage(lmm_constraint_t cnst); +XBT_PUBLIC(int) lmm_constraint_get_variable_amount(lmm_constraint_t cnst); + /** * @brief Sets the concurrency limit for this constraint * @param cnst A constraint @@ -233,8 +241,9 @@ XBT_PUBLIC(int) lmm_constraint_concurrency_maximum_get(lmm_constraint_t cnst); * @param bound The maximum value of the variable (-1.0 if no maximum value) * @param number_of_constraints The maximum number of constraint to associate to the variable */ -XBT_PUBLIC(lmm_variable_t) lmm_variable_new(lmm_system_t sys, void *id, double weight_value, double bound, - int number_of_constraints); +XBT_PUBLIC(lmm_variable_t) +lmm_variable_new(lmm_system_t sys, simgrid::surf::Action* id, double weight_value, double bound, + int number_of_constraints); /** * @brief Free a variable * @param sys The system associated to the variable @@ -316,7 +325,7 @@ XBT_PUBLIC(double) lmm_get_cnst_weight_from_var(lmm_system_t sys, lmm_variable_t XBT_PUBLIC(int) lmm_get_number_of_cnst_from_var(lmm_system_t sys, lmm_variable_t var); /** - * @brief Get a var associated to a constraint + * @brief Get a var associated to a constraint * @details Get the first variable of the next variable of elem if elem is not NULL * @param sys The system associated to the variable (not used) * @param cnst A constraint @@ -335,7 +344,7 @@ XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst(lmm_system_t sys, lmm_constrain * * @return A variable associated to a constraint */ -XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst_safe(lmm_system_t /*sys*/, lmm_constraint_t cnst, +XBT_PUBLIC(lmm_variable_t) lmm_get_var_from_cnst_safe(lmm_system_t sys, lmm_constraint_t cnst, lmm_element_t * elem, lmm_element_t * nextelem, int * numelem); /** @@ -349,7 +358,7 @@ XBT_PUBLIC(lmm_constraint_t) lmm_get_first_active_constraint(lmm_system_t sys); * @brief Get the next active constraint of a constraint in a system * @param sys A system * @param cnst An active constraint of the system - * + * * @return The next active constraint */ XBT_PUBLIC(lmm_constraint_t) lmm_get_next_active_constraint(lmm_system_t sys, lmm_constraint_t cnst); @@ -452,4 +461,4 @@ XBT_PUBLIC(double func_vegas_fpi) (lmm_variable_t var, double x); /** @} */ SG_END_DECL() -#endif /* _SURF_MAXMIN_H */ +#endif