"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_,
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)
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,
}
#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());
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_;
* @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
/** @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
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);
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,