Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make the factor callbacks private in NetworkModelFactors
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 22:53:48 +0000 (00:53 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 23 Oct 2022 22:53:48 +0000 (00:53 +0200)
src/kernel/resource/NetworkModelFactors.cpp
src/kernel/resource/NetworkModelFactors.hpp
src/surf/network_cm02.cpp

index 52e8ba0..6641350 100644 (file)
@@ -24,7 +24,17 @@ static config::Flag<std::string> cfg_bandwidth_factor_str(
     "network/bandwidth-factor", std::initializer_list<const char*>{"smpi/bw-factor"},
     "Correction factor to apply to the provided bandwidth (default value overridden by network model)", "1.0");
 
-#if 0
+double NetworkModelFactors::get_bandwidth_factor()
+{
+  xbt_assert(not bw_factor_cb_,
+             "Cannot access the global bandwidth factor since a callback is used. Please go for the advanced API.");
+
+  if (not cfg_bandwidth_factor.is_initialized())
+    cfg_bandwidth_factor.parse(cfg_bandwidth_factor_str.get());
+
+  return cfg_bandwidth_factor(0);
+}
+
 double NetworkModelFactors::get_latency_factor()
 {
   xbt_assert(not lat_factor_cb_,
@@ -36,6 +46,7 @@ double NetworkModelFactors::get_latency_factor()
   return cfg_latency_factor(0);
 }
 
+#if 0
 double NetworkModelFactors::get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
                                                const std::vector<s4u::Link*>& links,
                                                const std::unordered_set<s4u::NetZone*>& netzones)
@@ -48,16 +59,6 @@ double NetworkModelFactors::get_latency_factor(double size, const s4u::Host* src
 
   return cfg_latency_factor(size);
 }
-double NetworkModelFactors::get_bandwidth_factor()
-{
-  xbt_assert(not bw_factor_cb_,
-             "Cannot access the global bandwidth factor since a callback is used. Please go for the advanced API.");
-
-  if (not cfg_bandwidth_factor.is_initialized())
-    cfg_bandwidth_factor.parse(cfg_bandwidth_factor_str.get());
-
-  return cfg_bandwidth_factor(0);
-}
 
 double NetworkModelFactors::get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
                                                  const std::vector<s4u::Link*>& links,
@@ -73,15 +74,25 @@ double NetworkModelFactors::get_bandwidth_factor(double size, const s4u::Host* s
 }
 #endif
 
-double NetworkModelFactors::get_latency_factor(double size)
+double NetworkModelFactors::get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
+                                               const std::vector<s4u::Link*>& links,
+                                               const std::unordered_set<s4u::NetZone*>& netzones)
 {
+  if (lat_factor_cb_)
+    return lat_factor_cb_(size, src, dst, links, netzones);
+
   if (not cfg_latency_factor.is_initialized()) // lazy initiaization to avoid initialization fiasco
     cfg_latency_factor.parse(cfg_latency_factor_str.get());
 
   return cfg_latency_factor(size);
 }
-double NetworkModelFactors::get_bandwidth_factor(double size)
+double NetworkModelFactors::get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
+                                                 const std::vector<s4u::Link*>& links,
+                                                 const std::unordered_set<s4u::NetZone*>& netzones)
 {
+  if (bw_factor_cb_)
+    return bw_factor_cb_(size, src, dst, links, netzones);
+
   if (not cfg_bandwidth_factor.is_initialized())
     cfg_bandwidth_factor.parse(cfg_bandwidth_factor_str.get());
 
index 8dcb751..de3aea1 100644 (file)
@@ -22,7 +22,6 @@ class XBT_PUBLIC NetworkModelFactors {
                                  const std::vector<s4u::Link*>& links,
                                  const std::unordered_set<s4u::NetZone*>& netzones);
 
-protected:
   std::function<NetworkFactorCb> lat_factor_cb_;
   std::function<NetworkFactorCb> bw_factor_cb_;
 
@@ -32,22 +31,25 @@ public:
    * @details Depending on the model, the effective latency when sending a message might be different from the
    * theoretical latency of the link, in function of the message size. In order to account for this, this function gets
    * this factor.
-   *
-   * @param size The size of the message.
-   * @return The latency factor.
    */
-  double get_latency_factor(double size = 0);
+  double get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
+                            const std::vector<s4u::Link*>& links, const std::unordered_set<s4u::NetZone*>& netzones);
+
+  /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
+  double get_latency_factor();
 
   /**
    * @brief Get the right multiplicative factor for the bandwidth.
+   *
    * @details Depending on the model, the effective bandwidth when sending a message might be different from the
    * theoretical bandwidth of the link, in function of the message size. In order to account for this, this function
    * gets this factor.
-   *
-   * @param size The size of the message.
-   * @return The bandwidth factor.
    */
-  double get_bandwidth_factor(double size = 0);
+  double get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
+                              const std::vector<s4u::Link*>& links, const std::unordered_set<s4u::NetZone*>& netzones);
+
+  /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
+  double get_bandwidth_factor();
 
   /**
    * @brief Callback to set the bandwidth and latency factors used in a communication
@@ -68,6 +70,9 @@ public:
 
   /** @brief Configure the bandwidth factor callback */
   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb);
+
+  /** Returns whether a callback was set for latency-factor OR bandwidth-factor */
+  bool has_network_factor_cb() { return lat_factor_cb_ || bw_factor_cb_; }
 };
 
 } // namespace simgrid::kernel::resource
index 87b6cdb..8e7a837 100644 (file)
@@ -334,18 +334,14 @@ void NetworkCm02Model::comm_action_set_bounds(const s4u::Host* src, const s4u::H
   std::unordered_set<s4u::NetZone*> s4u_netzones;
 
   /* transform data to user structures if necessary */
-  if (lat_factor_cb_ || bw_factor_cb_) {
+  if (has_network_factor_cb()) {
     std::for_each(route.begin(), route.end(),
                   [&s4u_route](StandardLinkImpl* l) { s4u_route.push_back(l->get_iface()); });
     std::for_each(netzones.begin(), netzones.end(),
                   [&s4u_netzones](kernel::routing::NetZoneImpl* n) { s4u_netzones.insert(n->get_iface()); });
   }
-  double bw_factor;
-  if (bw_factor_cb_) {
-    bw_factor = bw_factor_cb_(size, src, dst, s4u_route, s4u_netzones);
-  } else {
-    bw_factor = get_bandwidth_factor(size);
-  }
+
+  double bw_factor = get_bandwidth_factor(size, src, dst, s4u_route, s4u_netzones);
   xbt_assert(bw_factor != 0, "Invalid param for comm %s -> %s. Bandwidth factor cannot be 0", src->get_cname(),
              dst->get_cname());
   action->set_rate_factor(bw_factor);
@@ -369,11 +365,7 @@ void NetworkCm02Model::comm_action_set_bounds(const s4u::Host* src, const s4u::H
   action->set_user_bound(bandwidth_bound);
 
   action->lat_current_ = action->latency_;
-  if (lat_factor_cb_) {
-    action->latency_ *= lat_factor_cb_(size, src, dst, s4u_route, s4u_netzones);
-  } else {
-    action->latency_ *= get_latency_factor(size);
-  }
+  action->latency_ *= get_latency_factor(size, src, dst, s4u_route, s4u_netzones);
 }
 
 void NetworkCm02Model::comm_action_set_variable(NetworkCm02Action* action, const std::vector<StandardLinkImpl*>& route,