20 #ifndef __CXXGRAPH_PARTITIONING_COORDINATEDPARTITIONSTATE_H__
21 #define __CXXGRAPH_PARTITIONING_COORDINATEDPARTITIONSTATE_H__
26 #include "Edge/Edge.hpp"
27 #include "Partitioning/Utility/Globals.hpp"
28 #include "PartitionState.hpp"
29 #include "CoordinatedRecord.hpp"
37 namespace PARTITIONING
43 std::map<int, std::shared_ptr<CoordinatedRecord<T>>> record_map;
44 std::vector<int> machines_load_edges;
45 std::vector<int> machines_load_vertices;
46 PartitionMap<T> partition_map;
49 std::shared_ptr<std::mutex> machines_load_edges_mutex =
nullptr;
50 std::shared_ptr<std::mutex> machines_load_vertices_mutex =
nullptr;
51 std::shared_ptr<std::mutex> record_map_mutex =
nullptr;
57 std::shared_ptr<Record<T>> getRecord(
int x);
58 int getMachineLoad(
int m);
59 int getMachineLoadVertices(
int m);
60 void incrementMachineLoad(
int m,
const Edge<T> *e);
63 std::vector<int> getMachines_load();
64 int getTotalReplicas();
66 std::set<int> getVertexIds();
68 void incrementMachineLoadVertices(
int m);
69 std::vector<int> getMachines_loadVertices();
70 const PartitionMap<T> &getPartitionMap();
75 for (
int i = 0; i < GLOBALS.numberOfPartition; ++i)
77 machines_load_edges.push_back(0);
78 machines_load_vertices.push_back(0);
79 partition_map[i] = std::make_shared<PARTITIONING::Partition<T>>(i);
84 CoordinatedPartitionState<T>::~CoordinatedPartitionState()
88 std::shared_ptr<Record<T>> CoordinatedPartitionState<T>::getRecord(
int x)
90 std::lock_guard<std::mutex> lock(*record_map_mutex);
91 if (record_map.find(x) == record_map.end())
93 record_map[x] = std::make_shared<CoordinatedRecord<T>>();
95 return record_map.at(x);
99 int CoordinatedPartitionState<T>::getMachineLoad(
int m)
101 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
102 return machines_load_edges.at(m);
105 template <
typename T>
106 int CoordinatedPartitionState<T>::getMachineLoadVertices(
int m)
108 std::lock_guard<std::mutex> lock(*machines_load_vertices_mutex);
109 return machines_load_vertices.at(m);
111 template <
typename T>
112 void CoordinatedPartitionState<T>::incrementMachineLoad(
int m,
const Edge<T> *e)
114 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
115 machines_load_edges[m] = machines_load_edges[m] + 1;
116 int new_value = machines_load_edges.at(m);
117 if (new_value > MAX_LOAD)
119 MAX_LOAD = new_value;
121 partition_map[m]->addEdge(e);
123 template <
typename T>
124 int CoordinatedPartitionState<T>::getMinLoad()
126 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
127 int MIN_LOAD = std::numeric_limits<int>::max();
128 for (
const auto &machines_load_edges_it : machines_load_edges)
130 int loadi = machines_load_edges_it;
131 if (loadi < MIN_LOAD)
138 template <
typename T>
139 int CoordinatedPartitionState<T>::getMaxLoad()
143 template <
typename T>
144 std::vector<int> CoordinatedPartitionState<T>::getMachines_load()
146 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
147 std::vector<int> result;
148 for (
const auto &machines_load_edges_it : machines_load_edges)
150 result.push_back(machines_load_edges_it);
154 template <
typename T>
155 int CoordinatedPartitionState<T>::getTotalReplicas()
158 std::lock_guard<std::mutex> lock(*record_map_mutex);
160 for (
const auto &record_map_it : record_map)
162 int r = record_map_it.second->getReplicas();
174 template <
typename T>
175 int CoordinatedPartitionState<T>::getNumVertices()
177 std::lock_guard<std::mutex> lock(*record_map_mutex);
178 return record_map.size();
180 template <
typename T>
181 std::set<int> CoordinatedPartitionState<T>::getVertexIds()
183 std::lock_guard<std::mutex> lock(*record_map_mutex);
185 std::set<int> result;
186 for (
const auto &record_map_it : record_map)
188 result.insert(record_map_it.first);
192 template <
typename T>
193 void CoordinatedPartitionState<T>::incrementMachineLoadVertices(
int m)
195 std::lock_guard<std::mutex> lock(*machines_load_vertices_mutex);
196 machines_load_vertices[m] = machines_load_vertices[m] + 1;
198 template <
typename T>
199 std::vector<int> CoordinatedPartitionState<T>::getMachines_loadVertices()
201 std::lock_guard<std::mutex> lock(*machines_load_vertices_mutex);
202 std::vector<int> result;
203 for (
const auto &machines_load_vertices_it : machines_load_vertices)
205 result.push_back(machines_load_vertices_it);
210 template <
typename T>
211 const PartitionMap<T> &CoordinatedPartitionState<T>::getPartitionMap()
213 return partition_map;
Definition: CoordinatedPartitionState.hpp:41
Definition: Globals.hpp:32
Definition: PartitionState.hpp:33