Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / kernel / lmm / bmf_test.cpp
index 0062972..ffaf589 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved.               */
+/* Copyright (c) 2019-2023. 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. */
@@ -13,7 +13,6 @@ namespace lmm = simgrid::kernel::lmm;
 TEST_CASE("kernel::bmf Basic tests", "[kernel-bmf-basic]")
 {
   lmm::BmfSystem Sys(false);
-  xbt_log_control_set("ker_bmf.thres:debug");
 
   SECTION("Single flow")
   {
@@ -260,7 +259,6 @@ TEST_CASE("kernel::bmf Basic tests", "[kernel-bmf-basic]")
 TEST_CASE("kernel::bmf Advanced tests", "[kernel-bmf-advanced]")
 {
   lmm::BmfSystem Sys(false);
-  xbt_log_control_set("ker_bmf.thres:debug");
 
   SECTION("2 flows, 2 resources")
   {
@@ -411,7 +409,6 @@ TEST_CASE("kernel::bmf Advanced tests", "[kernel-bmf-advanced]")
 TEST_CASE("kernel::bmf Subflows", "[kernel-bmf-subflow]")
 {
   lmm::BmfSystem Sys(false);
-  xbt_log_control_set("ker_bmf.thres:debug");
 
   SECTION("2 subflows and 1 resource")
   {
@@ -437,10 +434,10 @@ TEST_CASE("kernel::bmf Subflows", "[kernel-bmf-subflow]")
     lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1);
     lmm::Variable* rho_2      = Sys.variable_new(nullptr, 1);
 
-    Sys.expand_add(sys_cnst, rho_1, 5);
-    Sys.expand_add(sys_cnst, rho_1, 7);
-    Sys.expand_add(sys_cnst, rho_2, 7);
-    Sys.expand_add(sys_cnst, rho_2, 5);
+    Sys.expand(sys_cnst, rho_1, 5);
+    Sys.expand(sys_cnst, rho_1, 7);
+    Sys.expand(sys_cnst, rho_2, 7);
+    Sys.expand(sys_cnst, rho_2, 5);
     Sys.solve();
 
     REQUIRE(double_equals(rho_1->get_value(), 5.0 / 24.0, sg_maxmin_precision));
@@ -473,8 +470,8 @@ TEST_CASE("kernel::bmf Subflows", "[kernel-bmf-subflow]")
     lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1);
     lmm::Variable* rho_2      = Sys.variable_new(nullptr, 1);
 
-    Sys.expand_add(sys_cnst, rho_1, 10);
-    Sys.expand_add(sys_cnst, rho_1, 5);
+    Sys.expand(sys_cnst, rho_1, 10);
+    Sys.expand(sys_cnst, rho_1, 5);
     Sys.expand(sys_cnst, rho_2, 10);
     Sys.solve();
 
@@ -508,11 +505,11 @@ TEST_CASE("kernel::bmf Subflows", "[kernel-bmf-subflow]")
     lmm::Variable* rho_1       = Sys.variable_new(nullptr, 1, -1, 2);
     lmm::Variable* rho_2       = Sys.variable_new(nullptr, 1, -1, 2);
 
-    Sys.expand_add(sys_cnst, rho_1, 1.0);
-    Sys.expand_add(sys_cnst, rho_1, 1.0);
+    Sys.expand(sys_cnst, rho_1, 1.0);
+    Sys.expand(sys_cnst, rho_1, 1.0);
     Sys.expand(sys_cnst, rho_2, 1);
-    Sys.expand_add(sys_cnst2, rho_1, 1.0 / 2.0);
-    Sys.expand_add(sys_cnst2, rho_1, 1.0 / 2.0);
+    Sys.expand(sys_cnst2, rho_1, 1.0 / 2.0);
+    Sys.expand(sys_cnst2, rho_1, 1.0 / 2.0);
     Sys.expand(sys_cnst2, rho_2, 3.0 / 2.0);
     Sys.solve();
 
@@ -526,7 +523,6 @@ TEST_CASE("kernel::bmf Subflows", "[kernel-bmf-subflow]")
 TEST_CASE("kernel::bmf Loop", "[kernel-bmf-loop]")
 {
   lmm::BmfSystem Sys(false);
-  xbt_log_control_set("ker_bmf.thres:debug");
 
   SECTION("Initial allocation loops")
   {
@@ -554,7 +550,7 @@ TEST_CASE("kernel::bmf Loop", "[kernel-bmf-loop]")
                   [&vars, &Sys, &A](const auto&) { vars.push_back(Sys.variable_new(nullptr, 1, -1, A.size())); });
     for (size_t j = 0; j < A.size(); j++) {
       for (size_t i = 0; i < A[j].size(); i++) {
-        Sys.expand_add(sys_cnst[j], vars[i], A[j][i]);
+        Sys.expand(sys_cnst[j], vars[i], A[j][i]);
       }
     }
     Sys.solve();
@@ -570,7 +566,6 @@ TEST_CASE("kernel::bmf Loop", "[kernel-bmf-loop]")
 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")
   {
@@ -586,13 +581,63 @@ TEST_CASE("kernel::bmf Bugs", "[kernel-bmf-bug]")
     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.expand(sys_cnst, rho_1, 1.84467e+19);
+    Sys.expand(sys_cnst2, rho_1, 1.84467e+19);
+    Sys.expand(sys_cnst, rho_2, 1.84467e+19);
+    Sys.expand(sys_cnst, rho_3, 1.91268e+11);
     Sys.solve();
   }
 
+  SECTION("DadOu's bug: complete matrix")
+  {
+    constexpr int cnsts = 71;
+    constexpr int flows = 3;
+
+    Eigen::MatrixXd A(cnsts, flows);
+    A << 0, 0, 0, 0, 0, 0, 0, 0, 1.84467e+19, 1.91268e+11, 1.84467e+19, 1.84467e+19, 0, 0, 1.84467e+19, 0, 1.84467e+19,
+        0, 0, 1.84467e+19, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0,
+        4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11,
+        0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 1.256e+09, 0, 0, 2.2372e+10, 0, 0,
+        2.2684e+10, 0, 0, 2.2588e+10, 0, 0, 2.3188e+10, 0, 0, 2.228e+10, 0, 0, 2.058e+10, 0, 0, 2.2684e+10, 0, 0,
+        2.2824e+10, 0, 0, 2.2976e+10, 0, 0, 2.2632e+10, 0, 0, 2.2584e+10, 0, 0, 2.2736e+10, 0, 0, 2.2616e+10, 0, 0,
+        2.0828e+10, 0, 0, 2.3184e+10, 0, 0, 2.2524e+10, 0, 0, 2.278e+10, 0, 0, 2.2164e+10, 0, 0, 1.26e+09, 0, 0,
+        2.1872e+10, 0, 0, 1.4e+09, 0, 0, 2.3184e+10, 0, 0, 8.52e+08, 0, 0, 2.2268e+10, 0, 0, 1.756e+09, 0, 0,
+        2.0636e+10, 0, 0, 3.4e+09, 0, 0, 2.2576e+10, 0, 0, 1.352e+09, 0, 0, 2.2832e+10, 0, 0, 1.2e+09, 0, 0, 2.3092e+10,
+        0, 0, 9.48e+08, 0, 0, 2.2436e+10, 0, 0, 1.4e+09, 0, 0, 2.2572e+10, 0, 0, 1.452e+09, 0, 0, 2.2692e+10, 0, 0,
+        1.3e+09, 0, 0, 2.2832e+10, 0, 0, 1.2e+09, 0, 0, 2.1232e+10, 0, 0, 2.804e+09, 0, 0, 2.3184e+10, 0, 0,
+        8.56001e+08, 0, 0, 2.2512e+10, 0, 0, 1.5e+09, 0, 0;
+
+    Eigen::MatrixXd maxA(cnsts, flows);
+    maxA << 0, 0, 0, 0, 0, 0, 0, 0, 1.84467e+19, 3.1e+09, 1.84467e+19, 1.84467e+19, 0, 0, 1.84467e+19, 0, 1.84467e+19,
+        0, 0, 1.84467e+19, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 1, 4.975e+11, 0, 0,
+        4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11,
+        0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 4.975e+11, 0, 0, 1.256e+09, 0, 0, 3.504e+09, 0, 0,
+        3.056e+09, 0, 0, 3.1e+09, 0, 0, 2.952e+09, 0, 0, 2.404e+09, 0, 0, 2.304e+09, 0, 0, 2.556e+09, 0, 0, 2.4e+09, 0,
+        0, 2.804e+09, 0, 0, 2.552e+09, 0, 0, 2.408e+09, 0, 0, 2.9e+09, 0, 0, 2.4e+09, 0, 0, 2.256e+09, 0, 0, 3.504e+09,
+        0, 0, 3.244e+09, 0, 0, 2.556e+09, 0, 0, 2.952e+09, 0, 0, 1.26e+09, 0, 0, 2.552e+09, 0, 0, 1.4e+09, 0, 0,
+        3.244e+09, 0, 0, 8.52e+08, 0, 0, 2.556e+09, 0, 0, 1.756e+09, 0, 0, 2.256e+09, 0, 0, 3.4e+09, 0, 0, 2.6e+09, 0,
+        0, 1.352e+09, 0, 0, 2.952e+09, 0, 0, 1.2e+09, 0, 0, 2.452e+09, 0, 0, 9.48e+08, 0, 0, 2.804e+09, 0, 0, 1.4e+09,
+        0, 0, 3.1e+09, 0, 0, 1.452e+09, 0, 0, 2.404e+09, 0, 0, 1.3e+09, 0, 0, 2.952e+09, 0, 0, 1.2e+09, 0, 0, 3.056e+09,
+        0, 0, 2.804e+09, 0, 0, 2.4e+09, 0, 0, 8.56001e+08, 0, 0, 2.9e+09, 0, 0, 1.5e+09, 0, 0;
+
+    Eigen::VectorXd C(cnsts);
+    C << 3.2e+20, 3.2e+20, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20,
+        3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 3.2e+20, 1.83484e+10,
+        2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09,
+        2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10,
+        2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10,
+        2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10,
+        2.5e+09, 1.83484e+10, 2.5e+09, 1.83484e+10;
+
+    Eigen::VectorXd phi(flows);
+    phi << 1.35273, 2.27328e-10, 2.27328e-10;
+
+    std::vector<bool> shared(cnsts, true);
+    lmm::BmfSolver solver(A, maxA, C, shared, phi);
+    auto rho = solver.solve();
+    REQUIRE((rho.array() > 0).all());
+  }
+
   SECTION("is_bmf bug: all limited by bound")
   {
     /*
@@ -605,15 +650,68 @@ TEST_CASE("kernel::bmf Bugs", "[kernel-bmf-bug]")
     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.expand(sys_cnst, rho_1, 5.0);
+    Sys.expand(sys_cnst2, rho_1, 1.0);
+    Sys.expand(sys_cnst, rho_2, 1.0);
+    Sys.expand(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));
   }
 
+  SECTION("s4u-cloud-capping bug: all limited by bound extra case")
+  {
+    /*
+     * Inspired by s4u-cloud-capping test.
+     * Step 9: "Put an activity on a PM and an activity on the VM capped by 10%."
+     * Extracted from original test.
+     * The sum of bounds for 1 resource is smaller than C.
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 7.6296e+07);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1, 7.6296e+06, 1);
+    lmm::Variable* rho_2      = Sys.variable_new(nullptr, 1, 3.8148e+07, 1);
+
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.solve();
+    REQUIRE(double_equals(rho_1->get_value(), 7.6296e+06, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 3.8148e+07, sg_maxmin_precision));
+  }
+
+  SECTION("Variable penalty with bounds: thread bug")
+  {
+    /*
+     * Detected by exec-thread.
+     * Fair-sharing vector depends on the penalty too.
+     */
+
+    /* don't change the order of creation, important to trigger the bug */
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 4e8);
+    lmm::Variable* rho_2      = Sys.variable_new(nullptr, .25, 4e8, 1);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1, 1e8, 1);
+    Sys.expand(sys_cnst, rho_2, 1);
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 8e7, sg_maxmin_precision));
+    REQUIRE(double_equals(rho_2->get_value(), 3.2e8, sg_maxmin_precision));
+  }
+
+  SECTION("Variable penalty with bounds greater than C")
+  {
+    /*
+     * Detected by exec-thread. 6 thread running in a 4 core CPU.
+     */
+
+    lmm::Constraint* sys_cnst = Sys.constraint_new(nullptr, 4e8);
+    lmm::Variable* rho_1      = Sys.variable_new(nullptr, 1.0 / 6.0, 6e8, 1);
+    Sys.expand(sys_cnst, rho_1, 1);
+    Sys.solve();
+
+    REQUIRE(double_equals(rho_1->get_value(), 4e8, sg_maxmin_precision));
+  }
+
   Sys.variable_free_all();
 }
 
@@ -635,7 +733,7 @@ TEST_CASE("kernel::bmf Stress-tests", "[.kernel-bmf-stress]")
     for (int j = 0; j < N; j++) {
       lmm::Variable* rho = Sys.variable_new(nullptr, 1, -1, C);
       for (int i = 0; i < C; i++) {
-        Sys.expand_add(sys_cnst[i], rho, data[i * j + j]);
+        Sys.expand(sys_cnst[i], rho, data[i * j + j]);
       }
     }
     Sys.solve();
@@ -650,7 +748,7 @@ TEST_CASE("kernel::bmf Stress-tests", "[.kernel-bmf-stress]")
     for (int j = 0; j < N; j++) {
       for (int i = 0; i < C; i++) {
         lmm::Variable* rho = Sys.variable_new(nullptr, 1);
-        Sys.expand_add(sys_cnst[i], rho, data[i * j + j]);
+        Sys.expand(sys_cnst[i], rho, data[i * j + j]);
       }
     }
     Sys.solve();
@@ -716,4 +814,4 @@ TEST_CASE("kernel::AllocationGenerator Basic tests", "[kernel-bmf-allocation-gen
       i++;
     REQUIRE(i == 1 * 2 * 1);
   }
-}
\ No newline at end of file
+}