Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
round_robin.h
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Distributed under BSD 3-Clause license. *
3  * Copyright by The HDF Group. *
4  * Copyright by the Illinois Institute of Technology. *
5  * All rights reserved. *
6  * *
7  * This file is part of Hermes. The full Hermes copyright notice, including *
8  * terms governing use, modification, and redistribution, is contained in *
9  * the COPYING file, which can be found at the top directory. If you do not *
10  * have access to the file, you may request a copy from help@hdfgroup.org. *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 #ifndef HERMES_SRC_DPE_ROUND_ROBIN_H_
14 #define HERMES_SRC_DPE_ROUND_ROBIN_H_
15 
16 #include <map>
17 
18 #include "data_placement_engine.h"
19 
20 namespace hermes {
21 
22 using api::Status;
23 
25 class RoundRobin : public DPE {
26  private:
27  static inline int current_device_index_{};
28  static std::vector<DeviceID> devices_;
29  std::mutex device_index_mutex_;
31  public:
32  RoundRobin() : DPE(PlacementPolicy::kRoundRobin) {
33  device_index_mutex_.lock();
34  }
35  ~RoundRobin() { device_index_mutex_.unlock(); }
36 
37  Status Placement(const std::vector<size_t> &blob_sizes,
38  const std::vector<u64> &node_state,
39  const std::vector<TargetID> &targets,
40  const api::Context &ctx,
41  std::vector<PlacementSchema> &output);
42 
44  size_t GetNumDevices() const;
45 
47  int GetCurrentDeviceIndex() const;
48 
50  DeviceID GetDeviceByIndex(int i) const;
51 
53  void SetCurrentDeviceIndex(int new_device_index);
54 
56  static void InitDevices(hermes::Config *config,
57  std::shared_ptr<api::Hermes> result);
59  static void InitDevices(int count, int start_val = 0);
60 
61  private:
65  Status AddSchema(size_t index, std::vector<u64> &node_state,
66  const std::vector<size_t> &blob_sizes,
67  const std::vector<TargetID> &targets,
68  PlacementSchema &output);
69 };
70 
71 } // namespace hermes
72 
73 #endif // HERMES_SRC_DPE_ROUND_ROBIN_H_
Definition: hermes_status.h:80
Definition: data_placement_engine.h:35
Definition: round_robin.h:25
Status AddSchema(size_t index, std::vector< u64 > &node_state, const std::vector< size_t > &blob_sizes, const std::vector< TargetID > &targets, PlacementSchema &output)
Definition: round_robin.cc:59
Status Placement(const std::vector< size_t > &blob_sizes, const std::vector< u64 > &node_state, const std::vector< TargetID > &targets, const api::Context &ctx, std::vector< PlacementSchema > &output)
Definition: round_robin.cc:101
static std::vector< DeviceID > devices_
Definition: round_robin.h:28
int GetCurrentDeviceIndex() const
Definition: round_robin.cc:51
static void InitDevices(hermes::Config *config, std::shared_ptr< api::Hermes > result)
Definition: round_robin.cc:27
DeviceID GetDeviceByIndex(int i) const
Definition: round_robin.cc:47
size_t GetNumDevices() const
Definition: round_robin.cc:43
void SetCurrentDeviceIndex(int new_device_index)
Definition: round_robin.cc:55
std::mutex device_index_mutex_
Definition: round_robin.h:29
static int current_device_index_
Definition: round_robin.h:27
Definition: adapter_utils.cc:35
u16 DeviceID
Definition: hermes_types.h:51
std::vector< std::pair< size_t, TargetID > > PlacementSchema
Definition: hermes_types.h:226
Definition: hermes_types.h:258