Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Concatenate nested namespaces (sonar).
[simgrid.git] / src / surf / network_ib.hpp
1 /* Copyright (c) 2014-2022. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SURF_NETWORK_IB_HPP_
8 #define SURF_NETWORK_IB_HPP_
9
10 #include "src/surf/network_smpi.hpp"
11 #include "xbt/base.h"
12
13 #include <map>
14 #include <vector>
15
16 namespace simgrid::kernel::resource {
17
18 class XBT_PRIVATE IBNode;
19
20 struct XBT_PRIVATE ActiveComm {
21   IBNode* destination   = nullptr;
22   NetworkAction* action = nullptr;
23   double init_rate      = -1;
24 };
25
26 class IBNode {
27 public:
28   int id_;
29   // store related links, to ease computation of the penalties
30   std::vector<ActiveComm*> active_comms_up_;
31   // store the number of comms received from each node
32   std::map<IBNode*, int> active_comms_down_;
33   // number of comms the node is receiving
34   int nb_active_comms_down_ = 0;
35   explicit IBNode(int id) : id_(id){};
36 };
37
38 class XBT_PRIVATE NetworkIBModel : public NetworkSmpiModel {
39   std::unordered_map<std::string, IBNode> active_nodes;
40   std::unordered_map<NetworkAction*, std::pair<IBNode*, IBNode*>> active_comms;
41
42   double Bs_;
43   double Be_;
44   double ys_;
45   void update_IB_factors_rec(IBNode* root, std::vector<bool>& updatedlist) const;
46   void compute_IB_factors(IBNode* root) const;
47
48 public:
49   explicit NetworkIBModel(const std::string& name);
50   NetworkIBModel(const NetworkIBModel&) = delete;
51   NetworkIBModel& operator=(const NetworkIBModel&) = delete;
52   void update_IB_factors(NetworkAction* action, IBNode* from, IBNode* to, int remove) const;
53
54   static void IB_create_host_callback(s4u::Host const& host);
55   static void IB_action_state_changed_callback(NetworkAction& action, Action::State /*previous*/);
56   static void IB_comm_start_callback(const activity::CommImpl& comm);
57 };
58 } // namespace simgrid::kernel::resource
59 #endif