]> AND Public Git Repository - simgrid.git/blobdiff - src/kernel/lmm/bmf_test.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
introduce thread_execute
[simgrid.git] / src / kernel / lmm / bmf_test.cpp
index 0ad0f61b96ba9182bbb2b248b49e73615a21efbb..2fe15f4c2cada69d73ef0d7dd1906bf62aa371c4 100644 (file)
@@ -65,6 +65,33 @@ TEST_CASE("kernel::bmf Basic tests", "[kernel-bmf-basic]")
     REQUIRE(double_equals(rho_2->get_value(), (3.0 / 2.0) / 10.0, sg_maxmin_precision));
   }
 
+  SECTION("Variable penalty/priority")
+  {
+    /*
+     * A variable with twice the penalty gets half of the share
+     *
+     * In details:
+     *   o System:  a1 * p1 * \rho1  +  a2 * p2 * \rho2 < C
+     *   o consumption_weight: a1=1 ; a2=1
+     *   o sharing_penalty:    p1=1 ; p2=2
+     *
+     * Expectations
+     *   o rho1 = 2* rho2 (because rho2 has twice the penalty)
+     *   o rho1 + rho2 = C (because all weights are 1)
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 3);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1);
+    lmm::Variable* rho_2      = Sys.variable_new(nullptr, 2);
+
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 2, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 1, sg_maxmin_precision));
+  }
+
   SECTION("Disable variable doesn't count")
   {
     /*
@@ -141,6 +168,92 @@ TEST_CASE("kernel::bmf Basic tests", "[kernel-bmf-basic]")
     REQUIRE(double_equals(rho_2->get_value(), .8, sg_maxmin_precision));
   }
 
+  SECTION("Fatpipe")
+  {
+    /*
+     * Two flows using a fatpipe resource
+     *
+     * In details:
+     *   o System:  a1 * p1 * \rho1 < C and  a2 * p2 * \rho2 < C
+     *   o consumption_weight: a1=1 ; a2=1
+     *   o sharing_penalty:    p1=1 ; p2=1
+     *
+     * Expectations
+     *   o a1*rho1 = C
+     *   o a2*rho2 = C
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 3);
+    sys_cnst->set_sharing_policy(lmm::Constraint::SharingPolicy::FATPIPE, {});
+    lmm::Variable* rho_1 = Sys.variable_new(nullptr, 1);
+    lmm::Variable* rho_2 = Sys.variable_new(nullptr, 1);
+
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 3.0, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 3.0, sg_maxmin_precision));
+  }
+
+  SECTION("(un)Bounded variable")
+  {
+    /*
+     * Assures a player receives the share if bound is greater than share
+     *
+     *   o System:  a1 * p1 * \rho1 + a2 * p2 * \rho2 < C
+     *   o bounds: b1=1, b2=-1
+     *   o consumption_weight: a1=1, a2=1
+     *   o sharing_penalty:    p1=1, p2=1
+     *
+     * Expectations
+     *   o rho1 = .5
+     *   o rho2 = .5
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 1);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1, 1);
+    lmm::Variable* rho_2      = Sys.variable_new(nullptr, 1);
+
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.solve();
+    REQUIRE(double_equals(rho_1->get_value(), .5, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), .5, sg_maxmin_precision));
+  }
+
+  SECTION("Dynamic bounds")
+  {
+    /*
+     * Resource bound is modified by user callback and shares are adapted accordingly
+     *
+     *   o System:  a1 * p1 * \rho1 + a2 * p2 * \rho2 < C
+     *   o consumption_weight: a1=1, a2=1
+     *   o sharing_penalty:    p1=1, p2=1
+     *
+     * Expectations
+     *   o rho1 = .5 and .25
+     *   o rho2 =  - and .25
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 1);
+    sys_cnst->set_sharing_policy(lmm::Constraint::SharingPolicy::NONLINEAR,
+                                 [](double bound, int n) { return bound / n; });
+    // alone, full capacity
+    lmm::Variable* rho_1 = Sys.variable_new(nullptr, 1);
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.solve();
+    REQUIRE(double_equals(rho_1->get_value(), 1, sg_maxmin_precision));
+
+    // add another variable, half initial capacity
+    lmm::Variable* rho_2 = Sys.variable_new(nullptr, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), .25, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), .25, sg_maxmin_precision));
+  }
+
   Sys.variable_free_all();
 }
 
@@ -221,6 +334,77 @@ TEST_CASE("kernel::bmf Advanced tests", "[kernel-bmf-advanced]")
     REQUIRE(double_equals(rho_3->get_value(), 4.0 / 9.0, sg_maxmin_precision));
   }
 
+  SECTION("IO - example")
+  {
+    /*
+     * Two flows sharing 1 disk
+     * read, write and readwrite constraint
+     *
+     * In details:
+     *   o System:  a1 * p1 * \rho1 + a2 * p2 * \rho2 < C1
+     *   o System:  a1 * p1 * \rho1 + a2 * p2 * \rho2 < C2
+     *   o System:  a1 * p1 * \rho1 + a2 * p2 * \rho2 < C3
+     *   o C1 == C2 == C3
+     *   o consumption_weight: a1=1, a2=1
+     *   o sharing_penalty:    p1=1, p2=1
+     *
+     * Expectations
+     *   o rho1 = rho2 = C/2
+
+     * Matrices:
+     * [1 10] * [rho1 rho2] = [1]
+     * [10 1]                 [1]
+     */
+
+    lmm::Constraint* sys_cnst  = Sys.constraint_new(nullptr, 1e6);
+    lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 1e6);
+    lmm::Constraint* sys_cnst3 = Sys.constraint_new(nullptr, 1e6);
+    lmm::Variable* rho_1       = Sys.variable_new(nullptr, 1, -1, 3);
+    lmm::Variable* rho_2       = Sys.variable_new(nullptr, 1, -1, 3);
+
+    /* A' and C' matrices are dependent on the order of initialization
+     * this order is needed to identify a bug in the solver */
+    Sys.expand(sys_cnst2, rho_2, 1);
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.expand(sys_cnst3, rho_1, 1);
+    Sys.expand(sys_cnst3, rho_2, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 1e6 / 2.0, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 1e6 / 2.0, sg_maxmin_precision));
+  }
+
+  SECTION("Proportional fairness")
+  {
+    /*
+     * 3 flows sharing 2 resources with crosstraffic
+     *
+     * Regular max-min would give B/2 for every flow.
+     * BMF is equivalent to proportional fairness in this case, and give a quite
+     * different sharing.
+     *
+     */
+
+    lmm::Constraint* sys_cnst  = Sys.constraint_new(nullptr, 1);
+    lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 1);
+    lmm::Variable* rho_1       = Sys.variable_new(nullptr, 1, -1, 2);
+    lmm::Variable* rho_2       = Sys.variable_new(nullptr, 1, -1, 2);
+    lmm::Variable* rho_3       = Sys.variable_new(nullptr, 1, -1, 2);
+
+    double epsilon = 0.05;
+    Sys.expand(sys_cnst, rho_1, 1.0);
+    Sys.expand(sys_cnst2, rho_1, epsilon);
+    Sys.expand(sys_cnst, rho_2, 1.0);
+    Sys.expand(sys_cnst2, rho_2, epsilon);
+    Sys.expand(sys_cnst2, rho_3, 1.0);
+    Sys.expand(sys_cnst, rho_3, epsilon);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 1.0 / (2.0 + 2 * epsilon), sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 1.0 / (2.0 + 2 * epsilon), sg_maxmin_precision));
+    REQUIRE(double_equals(rho_3->get_value(), 1.0 / (1.0 + epsilon), sg_maxmin_precision));
+  }
+
   Sys.variable_free_all();
 }
 
@@ -384,6 +568,56 @@ TEST_CASE("kernel::bmf Loop", "[kernel-bmf-loop]")
   Sys.variable_free_all();
 }
 
+TEST_CASE("kernel::bmf Bugs", "[kernel-bmf-bug]")
+{
+  lmm::BmfSystem Sys(false);
+  xbt_log_control_set("ker_bmf.thres:debug");
+
+  SECTION("DadOu's bug: sum of bounds/phi greater than C")
+  {
+    /*
+     * Ptasks in a g5k platform.
+     * Extracted from original test.
+     * The sum of bounds for 1 resource exceed its capacity, giving a negative value in C'
+     */
+
+    lmm::Constraint* sys_cnst  = Sys.constraint_new(nullptr, 2.5e9);
+    lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 2.5e9);
+    lmm::Variable* rho_1       = Sys.variable_new(nullptr, 1, 2.27328e-10, 2);
+    lmm::Variable* rho_2       = Sys.variable_new(nullptr, 1, 2.27328e-10, 2);
+    lmm::Variable* rho_3       = Sys.variable_new(nullptr, 1);
+
+    Sys.expand_add(sys_cnst, rho_1, 1.84467e+19);
+    Sys.expand_add(sys_cnst2, rho_1, 1.84467e+19);
+    Sys.expand_add(sys_cnst, rho_2, 1.84467e+19);
+    Sys.expand_add(sys_cnst, rho_3, 1.91268e+11);
+    Sys.solve();
+  }
+
+  SECTION("is_bmf bug: all limited by bound")
+  {
+    /*
+     * Particular case, 1 flow is saturated and the other increases
+     * its speed until the contraint is reached
+     */
+
+    lmm::Constraint* sys_cnst  = Sys.constraint_new(nullptr, 10);
+    lmm::Constraint* sys_cnst2 = Sys.constraint_new(nullptr, 8);
+    lmm::Variable* rho_1       = Sys.variable_new(nullptr, 1, 1.5, 2);
+    lmm::Variable* rho_2       = Sys.variable_new(nullptr, 1, 3, 2);
+
+    Sys.expand_add(sys_cnst, rho_1, 5.0);
+    Sys.expand_add(sys_cnst2, rho_1, 1.0);
+    Sys.expand_add(sys_cnst, rho_2, 1.0);
+    Sys.expand_add(sys_cnst2, rho_2, 1.0);
+    Sys.solve();
+    REQUIRE(double_equals(rho_1->get_value(), 1.4, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 3, sg_maxmin_precision));
+  }
+
+  Sys.variable_free_all();
+}
+
 TEST_CASE("kernel::bmf Stress-tests", "[.kernel-bmf-stress]")
 {
   lmm::BmfSystem Sys(false);