Skip to content

Commit 55cda69

Browse files
committed
Polish partitioning
1 parent d20d784 commit 55cda69

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

src/neighbor_partitioner.hpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class MinHeap {
6868
}
6969

7070
void decrease_key(KeyType key, ValueType d = 1) {
71+
if (d == 0) return;
7172
auto it = key2idx.find(key);
7273
CHECK(it != key2idx.end()) << "key not found";
7374
IdxType cur = it->second;
@@ -148,7 +149,6 @@ class NeighborPartitioner
148149
<< ", num_edges: " << num_edges;
149150

150151
assigned_edges = 0;
151-
average_degree = (double)num_edges * 2 / num_vertices;
152152
max_sample_size = num_vertices * 4;
153153
sample_size = 0;
154154
capacity = (double)num_edges / p + 1;
@@ -176,13 +176,14 @@ class NeighborPartitioner
176176
}
177177

178178
rep (i, bucket) {
179-
if (is_cores[i][e.first] || is_cores[i][e.second]) {
180-
is_boundarys[i][e.first] = true;
181-
is_boundarys[i][e.second] = true;
182-
if (occupied[i] < capacity) {
183-
assign_edge(i, e.first, e.second);
184-
return false;
185-
}
179+
if ((is_cores[i][e.first] || is_cores[i][e.second]) &&
180+
occupied[i] < capacity) {
181+
if (is_cores[i][e.second])
182+
is_boundarys[i][e.first] = true;
183+
else
184+
is_boundarys[i][e.second] = true;
185+
assign_edge(i, e.first, e.second);
186+
return false;
186187
}
187188
}
188189

@@ -230,7 +231,6 @@ class NeighborPartitioner
230231
}
231232

232233
void add_boundary(vid_t vid) {
233-
if (occupied[bucket] >= capacity) return;
234234
std::vector<bool> &is_core = is_cores[bucket];
235235
std::vector<bool> &is_boundary = is_boundarys[bucket];
236236
if (is_boundary[vid]) return;
@@ -247,7 +247,6 @@ class NeighborPartitioner
247247
sample_size--;
248248
assign_edge(bucket, direction ? vid : *it, direction ? *it : vid);
249249
min_heap.decrease_key(vid);
250-
adj_r[*it].erase(vid);
251250
it = adj[vid].erase(it);
252251
} else if (is_boundary[*it]) {
253252
sample_size--;
@@ -261,20 +260,23 @@ class NeighborPartitioner
261260
}
262261
}
263262

264-
void occupy_vertex(vid_t vid)
263+
void occupy_vertex(vid_t vid, vid_t d)
265264
{
266-
std::vector<bool> &is_core = is_cores[bucket];
265+
CHECK(!is_cores[bucket][vid]) << "add " << vid << " to core again";
266+
is_cores[bucket][vid] = true;
267267

268-
CHECK(!is_core[vid]) << "add " << vid << " to core again";
269-
is_core[vid] = true;
268+
if (d == 0)
269+
return;
270270

271271
for (auto& w : adj_out[vid]) {
272272
add_boundary(w);
273273
}
274+
adj_out[vid].clear();
274275

275276
for (auto& w : adj_in[vid]) {
276277
add_boundary(w);
277278
}
279+
adj_in[vid].clear();
278280
}
279281

280282
void split()
@@ -290,27 +292,28 @@ class NeighborPartitioner
290292
for (bucket = 0; bucket < p - 1; bucket++) {
291293
DLOG(INFO) << "start partition " << bucket;
292294
read_more();
295+
average_degree = 2 * (double)sample_size / num_vertices;
293296
while (occupied[bucket] < capacity) {
294-
vid_t d = -1, vid;
297+
vid_t d, vid;
295298
if (!min_heap.get_min(d, vid)) {
296299
vid = dis(gen);
297300
int count = 0;
298301
while (count < num_vertices &&
299-
(degrees[vid] > average_degree ||
302+
(adj_out[vid].size() + adj_in[vid].size() == 0 ||
303+
adj_out[vid].size() + adj_in[vid].size() > 2 * average_degree ||
300304
is_cores[bucket][vid])) {
301305
vid = (vid + ++count) % num_vertices;
302306
}
303307
if (count == num_vertices)
304308
break;
305309
is_boundarys[bucket][vid] = true;
310+
d = adj_out[vid].size() + adj_in[vid].size();
306311
} else {
307312
min_heap.remove(vid);
308-
CHECK_EQ(d, adj_out[vid].size() + adj_in[vid].size())
309-
<< "heap value: " << d << ", real degree: "
310-
<< adj_out[vid].size() + adj_in[vid].size();
313+
CHECK_EQ(d, adj_out[vid].size() + adj_in[vid].size());
311314
}
312315

313-
occupy_vertex(vid);
316+
occupy_vertex(vid, d);
314317
}
315318
min_heap.clear();
316319
}

0 commit comments

Comments
 (0)