Skip to content

Commit af51a72

Browse files
committed
Polish
1 parent 5b5771d commit af51a72

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

src/neighbor_partitioner.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ void NeighborPartitioner::read_remaining()
101101
}
102102
}
103103

104+
size_t NeighborPartitioner::count_mirrors()
105+
{
106+
size_t result = 0;
107+
rep (i, p)
108+
result += is_boundarys[i].count();
109+
return result;
110+
}
111+
104112
void NeighborPartitioner::split()
105113
{
106114
LOG(INFO) << "partition `" << basefilename << "'";
@@ -120,8 +128,11 @@ void NeighborPartitioner::split()
120128
while (occupied[bucket] < local_capacity) {
121129
vid_t d, vid;
122130
if (!min_heap.get_min(d, vid)) {
123-
if (!get_free_vertex(vid))
131+
if (!get_free_vertex(vid)) {
132+
LOG(INFO) << "partition " << bucket
133+
<< " stop: no free vertices";
124134
break;
135+
}
125136
d = adj_out[vid].size() + adj_in[vid].size();
126137
} else {
127138
min_heap.remove(vid);
@@ -133,18 +144,17 @@ void NeighborPartitioner::split()
133144
min_heap.clear();
134145
compute_timer.stop();
135146
}
136-
DLOG(INFO) << "last partition";
137147
bucket = p - 1;
148+
DLOG(INFO) << "start partition " << bucket;
138149
read_timer.start();
139150
read_remaining();
140151
read_timer.stop();
152+
LOG(INFO) << "expected edges in each partition: " << num_edges / p;
141153
rep (i, p)
142154
DLOG(INFO) << "edges in partition " << i << ": " << occupied[i];
143155
size_t max_occupied = *std::max_element(occupied.begin(), occupied.end());
144156
LOG(INFO) << "balance: " << (double)max_occupied / ((double)num_edges / p);
145-
size_t total_mirrors = 0;
146-
rep (i, p)
147-
total_mirrors += is_boundarys[i].count();
157+
size_t total_mirrors = count_mirrors();
148158
LOG(INFO) << "total mirrors: " << total_mirrors;
149159
LOG(INFO) << "replication factor: " << (double)total_mirrors / num_vertices;
150160
LOG(INFO) << "time used for graph input and construction: " << read_timer.get_time();

src/neighbor_partitioner.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ class NeighborPartitioner
7979
degrees[to]--;
8080
}
8181

82-
size_t erase(std::vector<vid_t> &neighbors, vid_t v)
82+
size_t erase(std::vector<vid_t> &neighbors, const vid_t &v)
8383
{
8484
size_t count = 0;
8585
for (size_t i = 0; i < neighbors.size(); )
8686
if (neighbors[i] == v) {
87-
std::swap(neighbors[i], neighbors[neighbors.size() - 1]);
87+
std::swap(neighbors[i], neighbors.back());
8888
neighbors.pop_back();
8989
count++;
9090
} else
@@ -113,14 +113,14 @@ class NeighborPartitioner
113113
sample_size--;
114114
assign_edge(bucket, direction ? vid : adj[i], direction ? adj[i] : vid);
115115
min_heap.decrease_key(vid);
116-
std::swap(adj[i], adj[adj.size() - 1]);
116+
std::swap(adj[i], adj.back());
117117
adj.pop_back();
118118
} else if (is_boundary[adj[i]] && occupied[bucket] < local_capacity) {
119119
sample_size--;
120120
assign_edge(bucket, direction ? vid : adj[i], direction ? adj[i] : vid);
121121
min_heap.decrease_key(vid);
122122
min_heap.decrease_key(adj[i], erase(adj_r[adj[i]], vid));
123-
std::swap(adj[i], adj[adj.size() - 1]);
123+
std::swap(adj[i], adj.back());
124124
adj.pop_back();
125125
} else
126126
i++;
@@ -158,15 +158,14 @@ class NeighborPartitioner
158158
is_cores[bucket][vid])) {
159159
vid = (vid + ++count) % num_vertices;
160160
}
161-
if (count == num_vertices) {
162-
DLOG(INFO) << "no free vertices";
161+
if (count == num_vertices)
163162
return false;
164-
}
165163
return true;
166164
}
167165

168166
void read_more();
169167
void read_remaining();
168+
size_t count_mirrors();
170169

171170
public:
172171
NeighborPartitioner(std::string basefilename);

0 commit comments

Comments
 (0)