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"
36 namespace PARTITIONING
42 std::map<int, CoordinatedRecord<T>> record_map;
43 std::vector<int> machines_load_edges;
44 std::vector<int> machines_load_vertices;
45 PartitionMap<T> partition_map;
48 std::mutex* machines_load_edges_mutex;
49 std::mutex* machines_load_vertices_mutex;
56 int getMachineLoad(
int m);
57 void incrementMachineLoad(
int m,
const Edge<T> *e);
60 std::vector<int> getMachines_load();
61 int getTotalReplicas();
63 std::set<int> getVertexIds();
65 void incrementMachineLoadVertices(
int m);
66 std::vector<int> getMachines_loadVertices();
67 PartitionMap<T> getPartitionMap();
72 machines_load_edges_mutex =
new std::mutex();
73 machines_load_vertices_mutex =
new std::mutex();
75 for (
int i = 0; i < GLOBALS.numberOfPartition; i++)
77 machines_load_edges.push_back(0);
78 machines_load_vertices.push_back(0);
84 CoordinatedPartitionState<T>::~CoordinatedPartitionState()
95 Record<T> &CoordinatedPartitionState<T>::getRecord(
int x)
97 if (record_map.find(x) == record_map.end())
99 std::cout <<
"Record " << x <<
" not found" << std::endl;
100 record_map[x] = CoordinatedRecord<T>();
102 std::cout <<
"Return Record " << x << std::endl;
103 return record_map.at(x);
105 template <
typename T>
106 int CoordinatedPartitionState<T>::getMachineLoad(
int m)
108 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
109 return machines_load_edges.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);
124 template <
typename T>
125 int CoordinatedPartitionState<T>::getMinLoad()
127 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
128 int MIN_LOAD = std::numeric_limits<int>::max();
129 auto machines_load_edges_it = machines_load_edges.begin();
130 for (machines_load_edges_it; machines_load_edges_it != machines_load_edges.end(); ++machines_load_edges_it)
132 int loadi = *machines_load_edges_it;
133 if (loadi < MIN_LOAD)
140 template <
typename T>
141 int CoordinatedPartitionState<T>::getMaxLoad()
145 template <
typename T>
146 std::vector<int> CoordinatedPartitionState<T>::getMachines_load()
148 std::lock_guard<std::mutex> lock(*machines_load_edges_mutex);
149 std::vector<int> result;
150 for (
int i = 0; i < machines_load_edges.size(); i++)
152 result.push_back(machines_load_edges[i]);
156 template <
typename T>
157 int CoordinatedPartitionState<T>::getTotalReplicas()
161 auto record_map_it = record_map.begin();
162 for (record_map_it; record_map_it != record_map.end(); ++record_map_it)
164 int r = record_map_it->second.getReplicas();
176 template <
typename T>
177 int CoordinatedPartitionState<T>::getNumVertices()
179 return record_map.size();
181 template <
typename T>
182 std::set<int> CoordinatedPartitionState<T>::getVertexIds()
185 std::set<int> result;
186 auto record_map_it = record_map.begin();
187 for (record_map_it; record_map_it != record_map.end(); ++record_map_it)
189 result.insert(record_map_it->first);
193 template <
typename T>
194 void CoordinatedPartitionState<T>::incrementMachineLoadVertices(
int m)
196 std::lock_guard<std::mutex> lock(*machines_load_vertices_mutex);
197 machines_load_vertices[m] = machines_load_vertices[m] + 1;
199 template <
typename T>
200 std::vector<int> CoordinatedPartitionState<T>::getMachines_loadVertices()
202 std::lock_guard<std::mutex> lock(*machines_load_vertices_mutex);
203 std::vector<int> result;
204 for (
int i = 0; i < machines_load_vertices.size(); i++)
206 result.push_back(machines_load_vertices.at(i));
212 PartitionMap<T> CoordinatedPartitionState<T>::getPartitionMap()
214 return partition_map;
Definition: CoordinatedPartitionState.hpp:40
Definition: Globals.hpp:32
Definition: PartitionState.hpp:33
Definition: Partition.hpp:41
Definition: Record.hpp:31