Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flow_control_manager.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/net/flow_control_manager.hpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2015 Emanuel J√∂bstl <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #pragma once
12 #ifndef THRILL_NET_FLOW_CONTROL_MANAGER_HEADER
13 #define THRILL_NET_FLOW_CONTROL_MANAGER_HEADER
14 
15 #include <thrill/common/config.hpp>
18 #include <thrill/net/group.hpp>
19 
20 #include <string>
21 #include <vector>
22 
23 namespace thrill {
24 namespace net {
25 
26 //! \addtogroup net_layer
27 //! \{
28 
30 {
31 private:
32  //! The shared barrier used to synchronize between worker threads on this
33  //! node.
35 
36  //! The flow control channels associated with this node.
37  std::vector<FlowControlChannel> channels_;
38 
39  //! Thread local data structure: aligned such that no cache line is shared.
41 
42  //! Array of thread local data, one for each thread.
43  std::vector<LocalData> shmem_;
44 
45  //! Host-global generation counter
46  std::atomic<size_t> generation_ { 0 };
47 
48 public:
49  /*!
50  * Initializes a certain count of flow control channels.
51  *
52  * \param group The net group to use for initialization.
53  * \param local_worker_count The count of threads to spawn flow channels for.
54  */
55  FlowControlChannelManager(Group& group, size_t local_worker_count)
56  : barrier_(local_worker_count),
57  shmem_(local_worker_count) {
58  assert(shmem_.size() == local_worker_count);
59  channels_.reserve(local_worker_count);
60  for (size_t i = 0; i < local_worker_count; i++) {
61  channels_.emplace_back(group, i, local_worker_count,
62  barrier_, shmem_.data(), generation_);
63  }
64  }
65 
66  /*!
67  * \brief Gets all flow control channels for all threads.
68  * \return A flow channel for each thread.
69  */
70  std::vector<FlowControlChannel>& GetFlowControlChannels() {
71  return channels_;
72  }
73 
74  /*!
75  * \brief Gets the flow control channel for a certain thread.
76  * \return The flow control channel for a certain thread.
77  */
79  return channels_[thread_id];
80  }
81 };
82 
83 //! \}
84 
85 } // namespace net
86 } // namespace thrill
87 
88 #endif // !THRILL_NET_FLOW_CONTROL_MANAGER_HEADER
89 
90 /******************************************************************************/
FlowControlChannelManager(Group &group, size_t local_worker_count)
Initializes a certain count of flow control channels.
std::atomic< size_t > generation_
Host-global generation counter.
std::vector< FlowControlChannel > & GetFlowControlChannels()
Gets all flow control channels for all threads.
FlowControlChannel & GetFlowControlChannel(size_t thread_id)
Gets the flow control channel for a certain thread.
Provides a blocking collection for communication.
std::vector< FlowControlChannel > channels_
The flow control channels associated with this node.
A network Group is a collection of enumerated communication links, which provides point-to-point comm...
Definition: group.hpp:47
std::vector< LocalData > shmem_
Array of thread local data, one for each thread.
Implements a cyclic barrier using atomics and a spin lock that can be used to synchronize threads...