From: Arnaud Giersch Date: Wed, 28 Mar 2018 08:53:57 +0000 (+0200) Subject: Make func_f/fp/fpi static methods of lmm::Lagrange. X-Git-Tag: v3.20~615 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d0b9afc4d105022cc05b5b13ec06af6479dda020?ds=sidebyside Make func_f/fp/fpi static methods of lmm::Lagrange. --- diff --git a/src/kernel/lmm/lagrange.cpp b/src/kernel/lmm/lagrange.cpp index db92f1e454..37143ad8c3 100644 --- a/src/kernel/lmm/lagrange.cpp +++ b/src/kernel/lmm/lagrange.cpp @@ -26,10 +26,6 @@ namespace simgrid { namespace kernel { namespace lmm { -double (*func_f_def)(const Variable&, double); -double (*func_fp_def)(const Variable&, double); -double (*func_fpi_def)(const Variable&, double); - System* make_new_lagrange_system(bool selective_update) { return new Lagrange(selective_update); @@ -80,7 +76,7 @@ double Lagrange::new_value(const Variable& var) tmp += var.mu; XBT_DEBUG("\t Working on var (%p). cost = %e; Weight = %e", &var, tmp, var.sharing_weight); // uses the partial differential inverse function - return var.func_fpi(var, tmp); + return func_fpi(var, tmp); } double Lagrange::new_mu(const Variable& var) @@ -91,7 +87,7 @@ double Lagrange::new_mu(const Variable& var) for (Element const& elem : var.cnsts) { sigma_i += elem.constraint->lambda; } - mu_i = var.func_fp(var, var.bound) - sigma_i; + mu_i = func_fp(var, var.bound) - sigma_i; if (mu_i < 0.0) return 0.0; return mu_i; @@ -115,7 +111,7 @@ double Lagrange::dual_objective() XBT_DEBUG("var %p : sigma_i = %1.20f", &var, sigma_i); - obj += var.func_f(var, var.func_fpi(var, sigma_i)) - sigma_i * var.func_fpi(var, sigma_i); + obj += func_f(var, func_fpi(var, sigma_i)) - sigma_i * func_fpi(var, sigma_i); if (var.bound > 0) obj += var.mu * var.bound; @@ -396,7 +392,7 @@ double Lagrange::partial_diff_lambda(double lambda, const Constraint& cnst) // replace value of cnst.lambda by the value of parameter lambda sigma_i = (sigma_i - cnst.lambda) + lambda; - diff += -var.func_fpi(var, sigma_i); + diff += -func_fpi(var, sigma_i); } diff += cnst.bound; @@ -410,19 +406,21 @@ double Lagrange::partial_diff_lambda(double lambda, const Constraint& cnst) * * \param func_fpi inverse of the partial differential of f (f prime inverse, (f')^{-1}) * - * Set default functions to the ones passed as parameters. This is a polymorphism in C pure, enjoy the roots of - * programming. - * + * Set default functions to the ones passed as parameters. */ -void set_default_protocol_function(double (*func_f)(const Variable& var, double x), - double (*func_fp)(const Variable& var, double x), - double (*func_fpi)(const Variable& var, double x)) +void Lagrange::set_default_protocol_function(double (*func_f)(const Variable& var, double x), + double (*func_fp)(const Variable& var, double x), + double (*func_fpi)(const Variable& var, double x)) { - func_f_def = func_f; - func_fp_def = func_fp; - func_fpi_def = func_fpi; + Lagrange::func_f = func_f; + Lagrange::func_fp = func_fp; + Lagrange::func_fpi = func_fpi; } +double (*Lagrange::func_f)(const Variable&, double); +double (*Lagrange::func_fp)(const Variable&, double); +double (*Lagrange::func_fpi)(const Variable&, double); + /**************** Vegas and Reno functions *************************/ /* NOTE for Reno: all functions consider the network coefficient (alpha) equal to 1. */ diff --git a/src/kernel/lmm/maxmin.cpp b/src/kernel/lmm/maxmin.cpp index 42de20657e..0b27a670c4 100644 --- a/src/kernel/lmm/maxmin.cpp +++ b/src/kernel/lmm/maxmin.cpp @@ -725,9 +725,6 @@ void Variable::initialize(simgrid::kernel::resource::Action* id_value, double sh visited = visited_value; mu = 0.0; new_mu = 0.0; - func_f = func_f_def; - func_fp = func_fp_def; - func_fpi = func_fpi_def; xbt_assert(not variable_set_hook.is_linked()); xbt_assert(not saturated_variable_set_hook.is_linked()); diff --git a/src/kernel/lmm/maxmin.hpp b/src/kernel/lmm/maxmin.hpp index f0cafe76e3..8c006f5c2a 100644 --- a/src/kernel/lmm/maxmin.hpp +++ b/src/kernel/lmm/maxmin.hpp @@ -137,10 +137,6 @@ namespace lmm { /** Default functions associated to the chosen protocol. When using the lagrangian approach. */ -XBT_PUBLIC void set_default_protocol_function(double (*func_f)(const Variable& var, double x), - double (*func_fp)(const Variable& var, double x), - double (*func_fpi)(const Variable& var, double x)); - XBT_PUBLIC double func_reno_f(const Variable& var, double x); XBT_PUBLIC double func_reno_fp(const Variable& var, double x); XBT_PUBLIC double func_reno_fpi(const Variable& var, double x); @@ -409,9 +405,6 @@ public: /* \begin{For Lagrange only} */ double mu; double new_mu; - double (*func_f)(const Variable& var, double x); /* (f) */ - double (*func_fp)(const Variable& var, double x); /* (f') */ - double (*func_fpi)(const Variable& var, double x); /* (f')^{-1} */ /* \end{For Lagrange only} */ private: @@ -625,12 +618,20 @@ public: explicit Lagrange(bool selective_update) : System(selective_update) {} void solve() final { lagrange_solve(); } + static void set_default_protocol_function(double (*func_f)(const Variable& var, double x), + double (*func_fp)(const Variable& var, double x), + double (*func_fpi)(const Variable& var, double x)); + private: void lagrange_solve(); bool check_feasible(bool warn); double dual_objective(); + static double (*func_f)(const Variable& var, double x); /* (f) */ + static double (*func_fp)(const Variable& var, double x); /* (f') */ + static double (*func_fpi)(const Variable& var, double x); /* (f')^{-1} */ + /* * Local prototypes to implement the Lagrangian optimization with optimal step, also called dichotomy. */ @@ -648,10 +649,6 @@ XBT_PUBLIC System* make_new_maxmin_system(bool selective_update); XBT_PUBLIC System* make_new_fair_bottleneck_system(bool selective_update); XBT_PUBLIC System* make_new_lagrange_system(bool selective_update); -extern XBT_PRIVATE double (*func_f_def)(const Variable&, double); -extern XBT_PRIVATE double (*func_fp_def)(const Variable&, double); -extern XBT_PRIVATE double (*func_fpi_def)(const Variable&, double); - /** @} */ } } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index b4c77ac1ab..72bce2129b 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -87,8 +87,8 @@ void surf_network_model_init_Reno() if (surf_network_model) return; - set_default_protocol_function(simgrid::kernel::lmm::func_reno_f, simgrid::kernel::lmm::func_reno_fp, - simgrid::kernel::lmm::func_reno_fpi); + using namespace simgrid::kernel; + lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); @@ -104,8 +104,8 @@ void surf_network_model_init_Reno2() if (surf_network_model) return; - set_default_protocol_function(simgrid::kernel::lmm::func_reno2_f, simgrid::kernel::lmm::func_reno2_fp, - simgrid::kernel::lmm::func_reno2_fpi); + using namespace simgrid::kernel; + lmm::Lagrange::set_default_protocol_function(lmm::func_reno2_f, lmm::func_reno2_fp, lmm::func_reno2_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); @@ -120,8 +120,8 @@ void surf_network_model_init_Vegas() if (surf_network_model) return; - set_default_protocol_function(simgrid::kernel::lmm::func_vegas_f, simgrid::kernel::lmm::func_vegas_fp, - simgrid::kernel::lmm::func_vegas_fpi); + using namespace simgrid::kernel; + lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); xbt_cfg_setdefault_double("network/latency-factor", 13.01); xbt_cfg_setdefault_double("network/bandwidth-factor", 0.97); diff --git a/teshsuite/surf/lmm_usage/lmm_usage.cpp b/teshsuite/surf/lmm_usage/lmm_usage.cpp index 02d5eaef3f..6bfc152bf5 100644 --- a/teshsuite/surf/lmm_usage/lmm_usage.cpp +++ b/teshsuite/surf/lmm_usage/lmm_usage.cpp @@ -104,9 +104,9 @@ static void test1(method_t method) double b = 10.0; if (method == LAGRANGE_VEGAS) - set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); else if (method == LAGRANGE_RENO) - set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); lmm::System* Sys = new_system(method, true); lmm::Constraint* L1 = Sys->constraint_new(nullptr, a); @@ -190,9 +190,9 @@ static void test1(method_t method) static void test2(method_t method) { if (method == LAGRANGE_VEGAS) - set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); if (method == LAGRANGE_RENO) - set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); lmm::System* Sys = new_system(method, true); @@ -256,9 +256,9 @@ static void test3(method_t method) A[14][15] = 1.0; if (method == LAGRANGE_VEGAS) - set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_vegas_f, lmm::func_vegas_fp, lmm::func_vegas_fpi); if (method == LAGRANGE_RENO) - set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); + lmm::Lagrange::set_default_protocol_function(lmm::func_reno_f, lmm::func_reno_fp, lmm::func_reno_fpi); lmm::System* Sys = new_system(method, true);