Skip to content

Commit

Permalink
Run clang-format -style=google -i
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhulipala committed Jan 9, 2022
1 parent 140939f commit a0409ba
Show file tree
Hide file tree
Showing 284 changed files with 14,642 additions and 12,682 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ double DensestSubgraph_runner(Graph& G, commandLine P) {
std::cout << "### ------------------------------------" << std::endl;
assert(P.getOption("-s"));

timer t; t.start();
timer t;
t.start();
WorkEfficientDensestSubgraph(G, eps);
double tt = t.stop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ namespace gbbs {
template <class Graph>
double WorkEfficientDensestSubgraph(Graph& G, double epsilon = 0.001) {
const size_t n = G.n;
auto em = hist_table<uintE, uintE>(std::make_tuple(UINT_E_MAX, 0), (size_t)G.m / 50);

double density_multiplier = (1+epsilon); // note that this is not (2+eps), since the density we compute includes edges in both directions already.

auto D = sequence<uintE>::from_function(n, [&](size_t i) { return G.get_vertex(i).out_degree(); });
// auto vertices_remaining = sequence<uintE>(n, [&] (size_t i) { return i; });
auto vertices_remaining = parlay::delayed_seq<uintE>(n, [&] (size_t i) { return i; });
auto em = hist_table<uintE, uintE>(std::make_tuple(UINT_E_MAX, 0),
(size_t)G.m / 50);

double density_multiplier =
(1 + epsilon); // note that this is not (2+eps), since the density we
// compute includes edges in both directions already.

auto D = sequence<uintE>::from_function(
n, [&](size_t i) { return G.get_vertex(i).out_degree(); });
// auto vertices_remaining = sequence<uintE>(n, [&] (size_t i) { return i;
// });
auto vertices_remaining =
parlay::delayed_seq<uintE>(n, [&](size_t i) { return i; });
auto alive = sequence<bool>::from_function(n, [&](size_t i) { return true; });

size_t round = 1;
Expand All @@ -47,41 +53,43 @@ double WorkEfficientDensestSubgraph(Graph& G, double epsilon = 0.001) {
{
size_t edges_remaining = G.m;
// Update density
double current_density = ((double)edges_remaining) / ((double)vertices_remaining.size());
double target_density = (density_multiplier*((double)edges_remaining)) / ((double)vertices_remaining.size());
debug(std::cout << "Target density on round " << round << " is " << target_density << " erm = " << edges_remaining << " vrm = " << vertices_remaining.size() << std::endl;
std::cout << "Current density on round " << round << " is " << current_density << std::endl;);
double current_density =
((double)edges_remaining) / ((double)vertices_remaining.size());
double target_density = (density_multiplier * ((double)edges_remaining)) /
((double)vertices_remaining.size());
debug(std::cout << "Target density on round " << round << " is "
<< target_density << " erm = " << edges_remaining
<< " vrm = " << vertices_remaining.size() << std::endl;
std::cout << "Current density on round " << round << " is "
<< current_density << std::endl;);
if (current_density > max_density) {
max_density = current_density;
}

auto keep_seq = parlay::delayed_seq<bool>(n, [&] (size_t i) {
return !(D[i] <= target_density);
});
auto keep_seq = parlay::delayed_seq<bool>(
n, [&](size_t i) { return !(D[i] <= target_density); });

auto splits = parlay::split_two(vertices_remaining, keep_seq);
A = std::move(splits.first);
size_t num_removed = splits.second;
debug(std::cout << "removing " << num_removed << " vertices" << std::endl;);

auto removed = sequence<uintE>::uninitialized(num_removed);
parallel_for(0, num_removed, [&] (size_t i) {
parallel_for(0, num_removed, [&](size_t i) {
auto v = A[i];
removed[i] = v;
alive[v] = false;
});
auto vs = vertexSubset(n, std::move(removed));

auto cond_f = [&] (const uintE& u) {
return alive[u];
};
auto cond_f = [&](const uintE& u) { return alive[u]; };

auto apply_f = [&](const std::tuple<uintE, uintE>& p)
-> const std::optional<std::tuple<uintE, uintE> > {
uintE v = std::get<0>(p), edgesRemoved = std::get<1>(p);
D[v] -= edgesRemoved;
return std::nullopt;
};
uintE v = std::get<0>(p), edgesRemoved = std::get<1>(p);
D[v] -= edgesRemoved;
return std::nullopt;
};

nghCount(G, vs, cond_f, apply_f, em, no_output);

Expand All @@ -91,35 +99,42 @@ double WorkEfficientDensestSubgraph(Graph& G, double epsilon = 0.001) {
}

while (num_vertices_remaining > 0) {
auto vtxs_remaining = A.cut(remaining_offset, remaining_offset + num_vertices_remaining);
auto vtxs_remaining =
A.cut(remaining_offset, remaining_offset + num_vertices_remaining);

auto degree_f = [&] (size_t i) {
auto degree_f = [&](size_t i) {
uintE v = vtxs_remaining[i];
return static_cast<size_t>(D[v]);
};
auto degree_seq = parlay::delayed_seq<size_t>(vtxs_remaining.size(), degree_f);
auto degree_seq =
parlay::delayed_seq<size_t>(vtxs_remaining.size(), degree_f);
long edges_remaining = parlay::reduce(degree_seq);

// Update density
double current_density = ((double)edges_remaining) / ((double)vtxs_remaining.size());
double target_density = (density_multiplier*((double)edges_remaining)) / ((double)vtxs_remaining.size());
debug(std::cout << "Target density on round " << round << " is " << target_density << " erm = " << edges_remaining << " vrm = " << vtxs_remaining.size() << std::endl;
std::cout << "Current density on round " << round << " is " << current_density << std::endl;);
double current_density =
((double)edges_remaining) / ((double)vtxs_remaining.size());
double target_density = (density_multiplier * ((double)edges_remaining)) /
((double)vtxs_remaining.size());
debug(std::cout << "Target density on round " << round << " is "
<< target_density << " erm = " << edges_remaining
<< " vrm = " << vtxs_remaining.size() << std::endl;
std::cout << "Current density on round " << round << " is "
<< current_density << std::endl;);
if (current_density > max_density) {
max_density = current_density;
}

auto keep_seq = parlay::delayed_seq<bool>(vtxs_remaining.size(), [&] (size_t i) {
return !(D[vtxs_remaining[i]] <= target_density);
});
auto keep_seq = parlay::delayed_seq<bool>(
vtxs_remaining.size(),
[&](size_t i) { return !(D[vtxs_remaining[i]] <= target_density); });

auto split_vtxs_m = parlay::split_two(vtxs_remaining, keep_seq);
A = std::move(split_vtxs_m.first);
size_t num_removed = split_vtxs_m.second;
debug(std::cout << "removing " << num_removed << " vertices" << std::endl;);

auto removed = sequence<uintE>::uninitialized(num_removed);
parallel_for(0, num_removed, [&] (size_t i) {
parallel_for(0, num_removed, [&](size_t i) {
auto v = A[i];
alive[v] = false;
removed[i] = v;
Expand All @@ -130,22 +145,21 @@ double WorkEfficientDensestSubgraph(Graph& G, double epsilon = 0.001) {
if (num_vertices_remaining > 0) {
auto apply_f = [&](const std::tuple<uintE, uintE>& p)
-> const std::optional<std::tuple<uintE, uintE> > {
uintE v = std::get<0>(p), edgesRemoved = std::get<1>(p);
D[v] -= edgesRemoved;
return std::nullopt;
};

auto cond_f = [&] (const uintE& u) {
return alive[u];
};
uintE v = std::get<0>(p), edgesRemoved = std::get<1>(p);
D[v] -= edgesRemoved;
return std::nullopt;
};

auto cond_f = [&](const uintE& u) { return alive[u]; };
nghCount(G, vs, cond_f, apply_f, em, no_output);
}

round++;
remaining_offset = num_removed;
}

std::cout << "### Density of (2(1+\eps))-Densest Subgraph is: " << max_density << std::endl;
std::cout << "### Density of (2(1+\eps))-Densest Subgraph is: " << max_density
<< std::endl;
return max_density;
}
} // namespace gbbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ double DensestSubgraph_runner(Graph& G, commandLine P) {
std::cout << "### ------------------------------------" << std::endl;
assert(P.getOption("-s"));

timer t; t.start();
timer t;
t.start();
CharikarAppxDensestSubgraph(G);
double tt = t.stop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

#pragma once

#include "gbbs/gbbs.h"
#include "benchmarks/KCore/JulienneDBS17/KCore.h"
#include "gbbs/gbbs.h"

namespace gbbs {

Expand All @@ -33,7 +33,8 @@ namespace gbbs {
template <class Graph>
double CharikarAppxDensestSubgraph(Graph& GA) {
// deg_ord = degeneracy_order(GA)
// ## Now, density check for graph after removing each vertex, in the peeling-order.
// ## Now, density check for graph after removing each vertex, in the
// peeling-order.
// Let S = stores 2*#edges to vertices > in degeneracy order. Note that 2* is
// needed since higher-ordered vertices don't have the edge to us.
//
Expand All @@ -46,37 +47,39 @@ double CharikarAppxDensestSubgraph(Graph& GA) {
auto degeneracy_order = DegeneracyOrder(GA);
auto vtx_to_position = sequence<uintE>(n);

parallel_for(0, n, [&] (size_t i) {
parallel_for(0, n, [&](size_t i) {
uintE v = degeneracy_order.A[i];
vtx_to_position[v] = i;
});

auto density_above = sequence<size_t>(n);

parallel_for(0, n, 1, [&] (size_t i) {
parallel_for(0, n, 1, [&](size_t i) {
uintE pos_u = vtx_to_position[i];
auto vtx_f = [&] (const uintE& u, const uintE& v, const W& wgh) {
auto vtx_f = [&](const uintE& u, const uintE& v, const W& wgh) {
uintE pos_v = vtx_to_position[v];
return pos_u < pos_v;
};
density_above[pos_u] = 2*GA.get_vertex(i).out_neighbors().count(vtx_f);
density_above[pos_u] = 2 * GA.get_vertex(i).out_neighbors().count(vtx_f);
});

auto density_rev = parlay::make_slice(density_above.rbegin(), density_above.rend());
auto density_rev =
parlay::make_slice(density_above.rbegin(), density_above.rend());
size_t total_edges = parlay::scan_inplace(density_rev);
if (total_edges != GA.m) {
std::cout << "Assert failed: total_edges should be " << GA.m << " but is: " <<
total_edges << std::endl;
std::cout << "Assert failed: total_edges should be " << GA.m
<< " but is: " << total_edges << std::endl;
exit(0);
}

auto density_seq = parlay::delayed_seq<double>(n, [&] (size_t i) {
auto density_seq = parlay::delayed_seq<double>(n, [&](size_t i) {
size_t dens = density_above[i];
size_t rem = n - i;
return static_cast<double>(dens) / static_cast<double>(rem);
});
double max_density = parlay::reduce_max(density_seq);
std::cout << "### Density of 2-Densest Subgraph is: " << max_density << std::endl;
std::cout << "### Density of 2-Densest Subgraph is: " << max_density
<< std::endl;
return max_density;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ double SetCover_runner(Graph& G, commandLine P) {
std::cout << "### Params: -nb (num_buckets) = " << num_buckets << std::endl;
std::cout << "### ------------------------------------" << std::endl;

timer t; t.start();
timer t;
t.start();
auto cover = SetCover(G, num_buckets);
cover.del();
double tt = t.stop();
Expand Down
55 changes: 31 additions & 24 deletions benchmarks/ApproximateSetCover/MANISBPT11/ApproximateSetCover.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ struct Visit_Elms {

} // namespace sc


// Try implementing version with priority array.
// Question is how much does log(..) cost, each time when we unpack?

Expand All @@ -66,12 +65,16 @@ struct Visit_Elms {
template <class Graph>
inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
using W = typename Graph::weight_type;
timer it; it.start();
auto Elms = sequence<uintE>::from_function(G.n, [&](size_t i) { return UINT_E_MAX; });
timer it;
it.start();
auto Elms =
sequence<uintE>::from_function(G.n, [&](size_t i) { return UINT_E_MAX; });
auto get_bucket_clamped = [&](size_t deg) -> uintE {
return (deg == 0) ? UINT_E_MAX : (uintE)floor(sc::x * log((double)deg));
};
auto D = sequence<uintE>::from_function(G.n, [&](size_t i) { return get_bucket_clamped(G.get_vertex(i).out_degree()); });
auto D = sequence<uintE>::from_function(G.n, [&](size_t i) {
return get_bucket_clamped(G.get_vertex(i).out_degree());
});
auto b = make_vertex_buckets(G.n, D, decreasing, num_buckets);

auto perm = sequence<uintE>::uninitialized(G.n);
Expand All @@ -81,7 +84,8 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
size_t rounds = 0;
gbbs::dyn_arr<uintE> cover = gbbs::dyn_arr<uintE>();
auto r = parlay::random();
it.stop(); it.next("initialization time");
it.stop();
it.next("initialization time");
while (true) {
nbt.start();
auto bkt = b.next_bucket();
Expand All @@ -97,7 +101,9 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
auto pack_predicate = [&](const uintE& u, const uintE& ngh, const W& wgh) {
return Elms[ngh] != sc::COVERED;
};
auto pack_apply = [&](uintE v, size_t ct) { D[v] = get_bucket_clamped(ct); };
auto pack_apply = [&](uintE v, size_t ct) {
D[v] = get_bucket_clamped(ct);
};
auto packed_vtxs = srcPack(G, active, pack_predicate, pack_edges);
vertexMap(packed_vtxs, pack_apply);
packt.stop();
Expand All @@ -107,24 +113,24 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
auto above_threshold = [&](const uintE& v, const uintE& deg) {
return deg >= threshold;
};
//auto still_active = vertexFilter_sparse(packed_vtxs, above_threshold);
// auto still_active = vertexFilter_sparse(packed_vtxs, above_threshold);
auto still_active = vertexFilter(packed_vtxs, above_threshold, no_dense);

permt.start();
// Update the permutation for the sets that are active in this round.
still_active.toSparse();
auto P = parlay::random_permutation<uintE>(still_active.size(), r);
parallel_for(0, still_active.size(), kDefaultGranularity, [&] (size_t i) {
uintE v = still_active.vtx(i);
uintE pv = P[i];
perm[v] = pv;
});
parallel_for(0, still_active.size(), kDefaultGranularity, [&](size_t i) {
uintE v = still_active.vtx(i);
uintE pv = P[i];
perm[v] = pv;
});
P.clear();
permt.stop();

debug(std::cout << "Round = " << rounds << " bkt = " << cur_bkt
<< " active = " << active.size()
<< " stillactive = " << still_active.size() << "\n";);
<< " active = " << active.size()
<< " stillactive = " << still_active.size() << "\n";);

emt.start();
// 2. sets -> elements (write_min to acquire neighboring elements)
Expand All @@ -142,11 +148,13 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
};
auto activeAndCts = srcCount(G, still_active, won_ngh_f);
vertexMap(activeAndCts, threshold_f);
auto inCover =
vertexFilter(activeAndCts, [&](const uintE& v, const uintE& numWon) {
//vertexFilter_sparse(activeAndCts, [&](const uintE& v, const uintE& numWon) {
return numWon >= low_threshold;
}, no_dense);
auto inCover = vertexFilter(activeAndCts,
[&](const uintE& v, const uintE& numWon) {
// vertexFilter_sparse(activeAndCts, [&](const
// uintE& v, const uintE& numWon) {
return numWon >= low_threshold;
},
no_dense);
cover.copyInF([&](uintE i) { return inCover.vtx(i); }, inCover.size());

// 4. sets -> elements (Sets that joined the cover mark their neighboring
Expand All @@ -160,8 +168,7 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
}
return false;
};
edgeMap(G, still_active,
EdgeMap_F<W, decltype(reset_f)>(reset_f), -1,
edgeMap(G, still_active, EdgeMap_F<W, decltype(reset_f)>(reset_f), -1,
no_output | dense_forward);
emt.stop();

Expand All @@ -172,9 +179,9 @@ inline gbbs::dyn_arr<uintE> SetCover(Graph& G, size_t num_buckets = 512) {
const uintE v = active.vtx(i);
const uintE v_bkt = D[v];
uintE bucket = UINT_E_MAX;
if (!(v_bkt == UINT_E_MAX))
bucket = b.get_bucket(v_bkt);
return std::optional<std::tuple<uintE, uintE>>(std::make_tuple(v, bucket));
if (!(v_bkt == UINT_E_MAX)) bucket = b.get_bucket(v_bkt);
return std::optional<std::tuple<uintE, uintE>>(
std::make_tuple(v, bucket));
};
debug(std::cout << "cover.size = " << cover.size << "\n");
b.update_buckets(f, active.size());
Expand Down
Loading

0 comments on commit a0409ba

Please sign in to comment.