Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / kernel / resource / models / network_ib.hpp
1 /* Copyright (c) 2014-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_MODEL_NETWORK_IB_HPP_
7 #define SIMGRID_MODEL_NETWORK_IB_HPP_
8
9 #include "src/kernel/resource/models/network_cm02.hpp"
10
11 #include <map>
12 #include <vector>
13
14 namespace simgrid::kernel::resource {
15
16 class XBT_PRIVATE IBNode;
17
18 struct XBT_PRIVATE ActiveComm {
19   IBNode* destination   = nullptr;
20   NetworkAction* action = nullptr;
21   double init_rate      = -1;
22 };
23
24 class IBNode {
25 public:
26   int id_;
27   // store related links, to ease computation of the penalties
28   std::vector<ActiveComm*> active_comms_up_;
29   // store the number of comms received from each node
30   std::map<IBNode*, int> active_comms_down_;
31   // number of comms the node is receiving
32   int nb_active_comms_down_ = 0;
33   explicit IBNode(int id) : id_(id){};
34 };
35
36 class XBT_PRIVATE NetworkIBModel : public NetworkCm02Model {
37   std::unordered_map<std::string, IBNode> active_nodes;
38   std::unordered_map<NetworkAction*, std::pair<IBNode*, IBNode*>> active_comms;
39
40   double Bs_;
41   double Be_;
42   double ys_;
43   void update_IB_factors_rec(IBNode* root, std::vector<bool>& updatedlist) const;
44   void compute_IB_factors(IBNode* root) const;
45
46 public:
47   explicit NetworkIBModel(const std::string& name);
48   NetworkIBModel(const NetworkIBModel&)            = delete;
49   NetworkIBModel& operator=(const NetworkIBModel&) = delete;
50   void update_IB_factors(NetworkAction* action, IBNode* from, IBNode* to, bool remove) const;
51
52   static void IB_create_host_callback(s4u::Host const& host);
53   static void IB_action_state_changed_callback(NetworkAction& action, Action::State /*previous*/);
54   static void IB_comm_start_callback(const s4u::Comm& comm);
55 };
56 } // namespace simgrid::kernel::resource
57 #endif