Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / resource / NetworkModelFactors.hpp
1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_KERNEL_RESOURCE_NETWORKMODELFACTORS_HPP
7 #define SIMGRID_KERNEL_RESOURCE_NETWORKMODELFACTORS_HPP
8
9 #include "src/kernel/resource/FactorSet.hpp"
10 #include "src/simgrid/sg_config.hpp"
11 #include "xbt/asserts.h"
12 #include <simgrid/forward.h>
13
14 #include <unordered_set>
15 #include <vector>
16
17 namespace simgrid::kernel::resource {
18
19 /** This Trait of NetworkModel is in charge of handling the network factors (bw and lat) */
20
21 class XBT_PUBLIC NetworkModelFactors {
22   static FactorSet cfg_latency_factor;
23   static FactorSet cfg_bandwidth_factor;
24
25   using NetworkFactorCb = double(double size, const s4u::Host* src, const s4u::Host* dst,
26                                  const std::vector<s4u::Link*>& links,
27                                  const std::unordered_set<s4u::NetZone*>& netzones);
28
29   std::function<NetworkFactorCb> lat_factor_cb_;
30   std::function<NetworkFactorCb> bw_factor_cb_;
31
32 public:
33   /**
34    * @brief Get the right multiplicative factor for the latency.
35    * @details Depending on the model, the effective latency when sending a message might be different from the
36    * theoretical latency of the link, in function of the message size. In order to account for this, this function gets
37    * this factor.
38    */
39   double get_latency_factor(double size, const s4u::Host* src, const s4u::Host* dst,
40                             const std::vector<s4u::Link*>& links,
41                             const std::unordered_set<s4u::NetZone*>& netzones) const;
42
43   /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
44   double get_latency_factor() const;
45
46   /**
47    * @brief Get the right multiplicative factor for the bandwidth.
48    *
49    * @details Depending on the model, the effective bandwidth when sending a message might be different from the
50    * theoretical bandwidth of the link, in function of the message size. In order to account for this, this function
51    * gets this factor.
52    */
53   double get_bandwidth_factor(double size, const s4u::Host* src, const s4u::Host* dst,
54                               const std::vector<s4u::Link*>& links,
55                               const std::unordered_set<s4u::NetZone*>& netzones) const;
56
57   /** Get the right multiplicative factor for the bandwidth (only if no callback was defined) */
58   double get_bandwidth_factor() const;
59
60   /**
61    * @brief Callback to set the bandwidth and latency factors used in a communication
62    *
63    * This callback offers more flexibility when setting the network factors.
64    * It is an alternative to SimGrid's configs, such as network/latency-factors
65    * and network/bandwidth-factors.
66    *
67    * @param size Communication size in bytes
68    * @param src Source host
69    * @param dst Destination host
70    * @param links Vectors with the links used in this comm
71    * @param netzones Set with NetZones involved in the comm
72    * @return Multiply factor
73    */
74   /** @brief Configure the latency factor callback */
75   void set_lat_factor_cb(const std::function<NetworkFactorCb>& cb);
76
77   /** @brief Configure the bandwidth factor callback */
78   void set_bw_factor_cb(const std::function<NetworkFactorCb>& cb);
79
80   /** Returns whether a callback was set for latency-factor OR bandwidth-factor */
81   bool has_network_factor_cb() const { return lat_factor_cb_ || bw_factor_cb_; }
82 };
83
84 } // namespace simgrid::kernel::resource
85
86 #endif /* SIMGRID_KERNEL_RESOURCE_NETWORKMODELFACTORS_HPP */