Thrill  0.1
manager.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/net/manager.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015 Emanuel Jöbstl <[email protected]>
7  * Copyright (C) 2015-2016 Timo Bingmann <[email protected]>
8  *
9  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
10  ******************************************************************************/
11 
12 #pragma once
13 #ifndef THRILL_NET_MANAGER_HEADER
14 #define THRILL_NET_MANAGER_HEADER
15 
19 #include <thrill/net/group.hpp>
20 
21 #include <array>
22 #include <chrono>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace thrill {
28 namespace net {
29 
30 //! \addtogroup net_layer
31 //! \{
32 
33 struct Traffic {
34  //! transmitted bytes
35  size_t tx;
36  //! received bytes
37  size_t rx;
38  //! both transmitted and received bytes
39  size_t total() const { return tx + rx; }
40  //! constructor
41  Traffic(size_t tx, size_t rx) : tx(tx), rx(rx) { }
42  //! formatting: print total
43  friend std::ostream& operator << (std::ostream& os, const Traffic& t);
44 };
45 
46 /*!
47  * Initializes communication channels, manages communication channels and
48  * handles errors.
49  *
50  * \details This class is responsible for initializing the three net::Groups for
51  * the major network components, SystemControl, FlowControl and DataManagement,
52  */
53 class Manager final : public common::ProfileTask
54 {
55  static constexpr bool debug = false;
56 
57 public:
58  /*!
59  * The count of net::Groups to initialize.
60  */
61  static constexpr size_t kGroupCount = 2;
62 
63  size_t my_host_rank() const {
64  return groups_[0]->my_host_rank();
65  }
66 
67  size_t num_hosts() const {
68  return groups_[0]->num_hosts();
69  }
70 
71  //! non-copyable: delete copy-constructor
72  Manager(const Manager&) = delete;
73  //! non-copyable: delete assignment operator
74  Manager& operator = (const Manager&) = delete;
75 
76  //! Construct Manager from already initialized net::Groups.
77  Manager(std::array<GroupPtr, kGroupCount>&& groups,
78  common::JsonLogger& logger) noexcept;
79 
80  //! Construct Manager from already initialized net::Groups.
81  Manager(std::vector<GroupPtr>&& groups,
82  common::JsonLogger& logger) noexcept;
83 
84  //! Returns the net::Group for the flow control channel.
86  return *groups_[0];
87  }
88 
89  //! Returns the net::Group for the data manager.
91  return *groups_[1];
92  }
93 
94  void Close();
95 
96  //! calculate overall traffic for final stats
97  net::Traffic Traffic() const;
98 
99  //! \name Methods for ProfileTask
100  //! \{
101 
102  void RunTask(const std::chrono::steady_clock::time_point& tp) final;
103 
104  //! \}
105 
106 private:
107  //! The Groups initialized and managed by this Manager.
108  std::array<GroupPtr, kGroupCount> groups_;
109 
110  //! JsonLogger for statistics output
112 
113  //! last time statistics where outputted
114  std::chrono::steady_clock::time_point tp_last_;
115 };
116 
117 //! \}
118 
119 } // namespace net
120 } // namespace thrill
121 
122 #endif // !THRILL_NET_MANAGER_HEADER
123 
124 /******************************************************************************/
Group & GetDataGroup()
Returns the net::Group for the data manager.
Definition: manager.hpp:90
common::JsonLogger & logger_
JsonLogger for statistics output.
Definition: manager.hpp:111
size_t my_host_rank() const
Definition: manager.hpp:63
Traffic(size_t tx, size_t rx)
constructor
Definition: manager.hpp:41
size_t num_hosts() const
Definition: manager.hpp:67
friend std::ostream & operator<<(std::ostream &os, const Traffic &t)
formatting: print total
Definition: group.cpp:43
size_t total() const
both transmitted and received bytes
Definition: manager.hpp:39
Group & GetFlowGroup()
Returns the net::Group for the flow control channel.
Definition: manager.hpp:85
static constexpr bool debug
A network Group is a collection of enumerated communication links, which provides point-to-point comm...
Definition: group.hpp:47
JsonLogger is a receiver of JSON output objects for logging.
Definition: json_logger.hpp:69
size_t rx
received bytes
Definition: manager.hpp:37
Initializes communication channels, manages communication channels and handles errors.
Definition: manager.hpp:53
std::array< GroupPtr, kGroupCount > groups_
The Groups initialized and managed by this Manager.
Definition: manager.hpp:108
std::chrono::steady_clock::time_point tp_last_
last time statistics where outputted
Definition: manager.hpp:114
size_t tx
transmitted bytes
Definition: manager.hpp:35