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"
35 namespace PARTITIONING
41 std::map<int, CoordinatedRecord<T>> record_map;
42 std::vector<std::atomic<int>> machines_load_edges;
43 std::vector<std::atomic<int>> machines_load_vertices;
52 int getMachineLoad(
int m);
53 void incrementMachineLoad(
int m,
Edge<T> &e);
56 std::vector<int> getMachines_load();
57 int getTotalReplicas();
59 std::set<int> getVertexIds();
61 void incrementMachineLoadVertices(
int m);
62 std::vector<int> getMachines_loadVertices();
68 for (
int i = 0; i < GLOBALS.numberOfPartition; i++)
70 machines_load_edges.push_back(std::atomic<int>(0));
71 machines_load_vertices.push_back(std::atomic<int>(0));
76 CoordinatedPartitionState<T>::~CoordinatedPartitionState()
80 Record<T> &CoordinatedPartitionState<T>::getRecord(
int x)
82 if (record_map.find(x) == record_map.end())
84 record_map[x] = CoordinatedRecord<T>();
86 return record_map.at(x);
89 int CoordinatedPartitionState<T>::getMachineLoad(
int m)
91 return machines_load_edges.at(m);
94 void CoordinatedPartitionState<T>::incrementMachineLoad(
int m, Edge<T> &e)
96 machines_load_edges[m] = machines_load_edges[m] + 1;
97 int new_value = machines_load_edges.at(m);
98 if (new_value > MAX_LOAD)
100 MAX_LOAD = new_value;
103 template <
typename T>
104 int CoordinatedPartitionState<T>::getMinLoad()
106 int MIN_LOAD = std::numeric_limits<int>::max();
107 auto machines_load_edges_it = machines_load_edges.begin();
108 for (machines_load_edges_it; machines_load_edges_it != machines_load_edges.end(); ++machines_load_edges_it)
110 int loadi = *machines_load_edges_it;
111 if (loadi < MIN_LOAD)
118 template <
typename T>
119 int CoordinatedPartitionState<T>::getMaxLoad()
123 template <
typename T>
124 std::vector<int> CoordinatedPartitionState<T>::getMachines_load()
126 std::vector<int> result;
127 for (
int i = 0; i < machines_load_edges.size(); i++)
129 result.push_back(machines_load_edges[i]);
133 template <
typename T>
134 int CoordinatedPartitionState<T>::getTotalReplicas()
138 auto record_map_it = record_map.begin();
139 for (record_map_it; record_map_it != record_map.end(); ++record_map_it)
141 int r = record_map_it->second.getReplicas();
153 template <
typename T>
154 int CoordinatedPartitionState<T>::getNumVertices()
156 return record_map.size();
158 template <
typename T>
159 std::set<int> CoordinatedPartitionState<T>::getVertexIds()
162 std::set<int> result;
163 auto record_map_it = record_map.begin();
164 for (record_map_it; record_map_it != record_map.end(); ++record_map_it)
166 result.insert(record_map_it->first);
170 template <
typename T>
171 void CoordinatedPartitionState<T>::incrementMachineLoadVertices(
int m)
173 machines_load_vertices[m] = machines_load_vertices[m] + 1;
175 template <
typename T>
176 std::vector<int> CoordinatedPartitionState<T>::getMachines_loadVertices()
178 std::vector<int> result;
179 for (
int i = 0; i < machines_load_vertices.size(); i++)
181 result.push_back(machines_load_vertices.at(i));
Definition: CoordinatedPartitionState.hpp:39
Definition: Globals.hpp:32
Definition: PartitionState.hpp:31
Definition: Record.hpp:29