Logo AND Algorithmique Numérique Distribuée

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