Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Polishing last merged bits.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 23 Oct 2020 12:37:52 +0000 (14:37 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 23 Oct 2020 12:37:52 +0000 (14:37 +0200)
src/kernel/resource/profile/Profile.cpp
src/kernel/resource/profile/Profile_test.cpp
src/kernel/resource/profile/StochasticDatedValue.hpp

index 478c0c4..587a063 100644 (file)
@@ -29,8 +29,8 @@ Profile::Profile()
   /* Add the first fake event storing the time at which the trace begins */
   DatedValue val(0, -1);
   StochasticDatedValue stoval(0, -1);
-  event_list.push_back(val);
-  stochastic_event_list.push_back(stoval);
+  event_list.emplace_back(val);
+  stochastic_event_list.emplace_back(stoval);
 }
 Profile::~Profile() = default;
 
@@ -48,8 +48,8 @@ Event* Profile::schedule(FutureEvtSet* fes, resource::Resource* resource)
 
   fes_ = fes;
   fes_->add_event(0.0 /* start time */, event);
-  if (stochastic > 0) {
-    xbt_assert((event->idx < stochastic_event_list.size()), "Your profile should have at least one stochastic event!");
+  if (stochastic) {
+    xbt_assert(event->idx < stochastic_event_list.size(), "Your profile should have at least one stochastic event!");
     futureDV = stochastic_event_list.at(event->idx).get_datedvalue();
   }
 
@@ -78,15 +78,14 @@ DatedValue Profile::next(Event* event)
     DatedValue dateVal = futureDV;
     if (event->idx < stochastic_event_list.size() - 1) {
       event->idx++;
-    } else if (stochasticloop > 0) { /* We have reached the last element and we have to loop. */
+    } else if (stochasticloop) { /* We have reached the last element and we have to loop. */
       event->idx = 1;
     } else {
       event->free_me = true; /* We have reached the last element, but we don't need to loop. */
     }
 
-    if (event->free_me == false) { // In the case there is an element, we draw the next event
-      StochasticDatedValue stodateVal = stochastic_event_list.at(event->idx);
-      futureDV                        = stochastic_event_list.at(event->idx).get_datedvalue();
+    if (not event->free_me) { // In the case there is an element, we draw the next event
+      futureDV = stochastic_event_list.at(event->idx).get_datedvalue();
       fes_->add_event(event_date + futureDV.date_, event);
     }
     return dateVal;
@@ -183,7 +182,7 @@ Profile* Profile::from_string(const std::string& name, const std::string& input,
         stochevent.value_params = {std::atof(splittedval[i + 1].c_str()), std::atof(splittedval[i + 2].c_str())};
       }
 
-      profile->stochastic_event_list.push_back(stochevent);
+      profile->stochastic_event_list.emplace_back(stochevent);
     } else {
       XBT_ATTRIB_UNUSED int res = sscanf(val.c_str(), "%lg  %lg\n", &event.date_, &event.value_);
       xbt_assert(res == 2, "%s:%d: Syntax error in trace\n%s", name.c_str(), linecount, input.c_str());
@@ -193,7 +192,7 @@ Profile* Profile::from_string(const std::string& name, const std::string& input,
                  last_event->date_, event.date_, input.c_str());
       last_event->date_ = event.date_ - last_event->date_;
 
-      profile->event_list.push_back(event);
+      profile->event_list.emplace_back(event);
       last_event = &(profile->event_list.back());
     }
   }
index 8bb95a8..0d2d72b 100644 (file)
@@ -158,9 +158,9 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
                                                                                    "DET 0 UNIF 10 20");
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
-                                                                  simgrid::kernel::profile::Dist_Unif, {10, 20}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1)); // The initial fake event
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
+                                                                     simgrid::kernel::profile::Dist_Unif, {10, 20}));
 
     REQUIRE(want == got);
   }
@@ -174,15 +174,15 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
                                                                                    "DET 5 UNIF 5 25");
 
     std::vector<simgrid::kernel::profile::StochasticDatedValue> want;
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(0, -1));
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
-                                                                  simgrid::kernel::profile::Dist_Det, {4}));
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10},
-                                                                  simgrid::kernel::profile::Dist_Det, {3}));
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20},
-                                                                  simgrid::kernel::profile::Dist_Norm, {25, 10}));
-    want.push_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5},
-                                                                  simgrid::kernel::profile::Dist_Unif, {5, 25}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(0, -1));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {0},
+                                                                     simgrid::kernel::profile::Dist_Det, {4}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Norm, {25, 10},
+                                                                     simgrid::kernel::profile::Dist_Det, {3}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Unif, {10, 20},
+                                                                     simgrid::kernel::profile::Dist_Norm, {25, 10}));
+    want.emplace_back(simgrid::kernel::profile::StochasticDatedValue(simgrid::kernel::profile::Dist_Det, {5},
+                                                                     simgrid::kernel::profile::Dist_Unif, {5, 25}));
 
     REQUIRE(want == got);
   }
@@ -197,8 +197,8 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
 
     std::vector<simgrid::kernel::profile::DatedValue> want;
     // The following values were drawn using the XBT_RNG_xbt method /outside/ the testcase.
-    want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683));
-    want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772));
 
     REQUIRE(want == got);
   }
@@ -215,10 +215,10 @@ TEST_CASE("kernel::profile: Resource profiles, defining the external load", "ker
     // In this case, the main use of the last stochastic event is to set when the first event takes place.
 
     std::vector<simgrid::kernel::profile::DatedValue> want;
-    want.push_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683));
-    want.push_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772));
-    want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 0));
-    want.push_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 10.39759496468994726115));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(0, 19.29616086867082813683));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(2.32719992449416279712, 20.16807234800742065772));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 0));
+    want.emplace_back(simgrid::kernel::profile::DatedValue(3.51111873684917075167, 10.39759496468994726115));
 
     REQUIRE(want == got);
   }
index d0b29b2..29bc989 100644 (file)
@@ -30,7 +30,8 @@ public:
       : date_law(Dist_Det), date_params({d}), value_law(Dist_Det), value_params({v})
   {
   }
-  explicit StochasticDatedValue(Distribution dl, std::vector<double> dp, Distribution vl, std::vector<double> vp)
+  explicit StochasticDatedValue(Distribution dl, const std::vector<double>& dp, Distribution vl,
+                                const std::vector<double>& vp)
       : date_law(dl), date_params(dp), value_law(vl), value_params(vp)
   {
   }