Skip to content

Commit

Permalink
[all] add flag (-l) to control intra-trial logging verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
sbeamer committed Sep 29, 2023
1 parent d48e9b5 commit 1642dcf
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 27 deletions.
19 changes: 12 additions & 7 deletions src/bc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void PBFS(const Graph &g, NodeID source, pvector<CountT> &path_counts,


pvector<ScoreT> Brandes(const Graph &g, SourcePicker<Graph> &sp,
NodeID num_iters) {
NodeID num_iters, bool logging_enabled = false) {
Timer t;
t.Start();
pvector<ScoreT> scores(g.num_nodes(), 0);
Expand All @@ -102,19 +102,22 @@ pvector<ScoreT> Brandes(const Graph &g, SourcePicker<Graph> &sp,
vector<SlidingQueue<NodeID>::iterator> depth_index;
SlidingQueue<NodeID> queue(g.num_nodes());
t.Stop();
PrintStep("a", t.Seconds());
if (logging_enabled)
PrintStep("a", t.Seconds());
const NodeID* g_out_start = g.out_neigh(0).begin();
for (NodeID iter=0; iter < num_iters; iter++) {
NodeID source = sp.PickNext();
cout << "source: " << source << endl;
if (logging_enabled)
PrintStep("Source", static_cast<int64_t>(source));
t.Start();
path_counts.fill(0);
depth_index.resize(0);
queue.reset();
succ.reset();
PBFS(g, source, path_counts, succ, depth_index, queue);
t.Stop();
PrintStep("b", t.Seconds());
if (logging_enabled)
PrintStep("b", t.Seconds());
pvector<ScoreT> deltas(g.num_nodes(), 0);
t.Start();
for (int d=depth_index.size()-2; d >= 0; d--) {
Expand All @@ -132,7 +135,8 @@ pvector<ScoreT> Brandes(const Graph &g, SourcePicker<Graph> &sp,
}
}
t.Stop();
PrintStep("p", t.Seconds());
if (logging_enabled)
PrintStep("p", t.Seconds());
}
// normalize scores
ScoreT biggest_score = 0;
Expand Down Expand Up @@ -235,8 +239,9 @@ int main(int argc, char* argv[]) {
Builder b(cli);
Graph g = b.MakeGraph();
SourcePicker<Graph> sp(g, cli.start_vertex());
auto BCBound =
[&sp, &cli] (const Graph &g) { return Brandes(g, sp, cli.num_iters()); };
auto BCBound = [&sp, &cli] (const Graph &g) {
return Brandes(g, sp, cli.num_iters(), cli.logging_en());
};
SourcePicker<Graph> vsp(g, cli.start_vertex());
auto VerifierBound = [&vsp, &cli] (const Graph &g,
const pvector<ScoreT> &scores) {
Expand Down
17 changes: 10 additions & 7 deletions src/cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void Compress(const Graph &g, pvector<NodeID>& comp) {


NodeID SampleFrequentElement(const pvector<NodeID>& comp,
bool logging_enabled = false,
int64_t num_samples = 1024) {
std::unordered_map<NodeID, int> sample_counts(32);
using kvp_type = std::unordered_map<NodeID, int>::value_type;
Expand All @@ -83,15 +84,17 @@ NodeID SampleFrequentElement(const pvector<NodeID>& comp,
sample_counts.begin(), sample_counts.end(),
[](const kvp_type& a, const kvp_type& b) { return a.second < b.second; });
float frac_of_graph = static_cast<float>(most_frequent->second) / num_samples;
std::cout
<< "Skipping largest intermediate component (ID: " << most_frequent->first
<< ", approx. " << static_cast<int>(frac_of_graph * 100)
<< "% of the graph)" << std::endl;
if (logging_enabled)
std::cout
<< "Skipping largest intermediate component (ID: " << most_frequent->first
<< ", approx. " << static_cast<int>(frac_of_graph * 100)
<< "% of the graph)" << std::endl;
return most_frequent->first;
}


pvector<NodeID> Afforest(const Graph &g, int32_t neighbor_rounds = 2) {
pvector<NodeID> Afforest(const Graph &g, bool logging_enabled = false,
int32_t neighbor_rounds = 2) {
pvector<NodeID> comp(g.num_nodes());

// Initialize each node to a single-node self-pointing tree
Expand All @@ -115,7 +118,7 @@ pvector<NodeID> Afforest(const Graph &g, int32_t neighbor_rounds = 2) {

// Sample 'comp' to find the most frequent element -- due to prior
// compression, this value represents the largest intermediate component
NodeID c = SampleFrequentElement(comp);
NodeID c = SampleFrequentElement(comp, logging_enabled);

// Final 'link' phase over remaining edges (excluding largest component)
if (!g.directed()) {
Expand Down Expand Up @@ -221,7 +224,7 @@ int main(int argc, char* argv[]) {
return -1;
Builder b(cli);
Graph g = b.MakeGraph();
auto CCBound = [](const Graph& gr){ return Afforest(gr); };
auto CCBound = [&cli](const Graph& gr){ return Afforest(gr, cli.logging_en()); };
BenchmarkKernel(cli, g, CCBound, PrintCompStats, CCVerifier);
return 0;
}
6 changes: 5 additions & 1 deletion src/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,16 @@ class CLApp : public CLBase {
int num_trials_ = 16;
int64_t start_vertex_ = -1;
bool do_verify_ = false;
bool enable_logging_ = false;

public:
CLApp(int argc, char** argv, std::string name) : CLBase(argc, argv, name) {
get_args_ += "an:r:v";
get_args_ += "an:r:vl";
AddHelpLine('a', "", "output analysis of last run", "false");
AddHelpLine('n', "n", "perform n trials", std::to_string(num_trials_));
AddHelpLine('r', "node", "start from node r", "rand");
AddHelpLine('v', "", "verify the output of each run", "false");
AddHelpLine('l', "", "log performance within each trial", "false");
}

void HandleArg(signed char opt, char* opt_arg) override {
Expand All @@ -132,6 +134,7 @@ class CLApp : public CLBase {
case 'n': num_trials_ = atoi(opt_arg); break;
case 'r': start_vertex_ = atol(opt_arg); break;
case 'v': do_verify_ = true; break;
case 'l': enable_logging_ = true; break;
default: CLBase::HandleArg(opt, opt_arg);
}
}
Expand All @@ -140,6 +143,7 @@ class CLApp : public CLBase {
int num_trials() const { return num_trials_; }
int64_t start_vertex() const { return start_vertex_; }
bool do_verify() const { return do_verify_; }
bool logging_en() const { return enable_logging_; }
};


Expand Down
9 changes: 5 additions & 4 deletions src/pr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ typedef float ScoreT;
const float kDamp = 0.85;


pvector<ScoreT> PageRankPullGS(const Graph &g, int max_iters,
double epsilon = 0) {
pvector<ScoreT> PageRankPullGS(const Graph &g, int max_iters, double epsilon=0,
bool logging_enabled = false) {
const ScoreT init_score = 1.0f / g.num_nodes();
const ScoreT base_score = (1.0f - kDamp) / g.num_nodes();
pvector<ScoreT> scores(g.num_nodes(), init_score);
Expand All @@ -52,7 +52,8 @@ pvector<ScoreT> PageRankPullGS(const Graph &g, int max_iters,
error += fabs(scores[u] - old_score);
outgoing_contrib[u] = scores[u] / g.out_degree(u);
}
PrintStep(iter, error);
if (logging_enabled)
PrintStep(iter, error);
if (error < epsilon)
break;
}
Expand Down Expand Up @@ -101,7 +102,7 @@ int main(int argc, char* argv[]) {
Builder b(cli);
Graph g = b.MakeGraph();
auto PRBound = [&cli] (const Graph &g) {
return PageRankPullGS(g, cli.max_iters(), cli.tolerance());
return PageRankPullGS(g, cli.max_iters(), cli.tolerance(), cli.logging_en());
};
auto VerifierBound = [&cli] (const Graph &g, const pvector<ScoreT> &scores) {
return PRVerifier(g, scores, cli.tolerance());
Expand Down
9 changes: 5 additions & 4 deletions src/pr_spmv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ using namespace std;
typedef float ScoreT;
const float kDamp = 0.85;

pvector<ScoreT> PageRankPull(const Graph &g, int max_iters,
double epsilon = 0) {
pvector<ScoreT> PageRankPull(const Graph &g, int max_iters, double epsilon = 0,
bool logging_enabled = false) {
const ScoreT init_score = 1.0f / g.num_nodes();
const ScoreT base_score = (1.0f - kDamp) / g.num_nodes();
pvector<ScoreT> scores(g.num_nodes(), init_score);
Expand All @@ -52,7 +52,8 @@ pvector<ScoreT> PageRankPull(const Graph &g, int max_iters,
scores[u] = base_score + kDamp * incoming_total;
error += fabs(scores[u] - old_score);
}
PrintStep(iter, error);
if (logging_enabled)
PrintStep(iter, error);
if (error < epsilon)
break;
}
Expand Down Expand Up @@ -101,7 +102,7 @@ int main(int argc, char* argv[]) {
Builder b(cli);
Graph g = b.MakeGraph();
auto PRBound = [&cli] (const Graph &g) {
return PageRankPull(g, cli.max_iters(), cli.tolerance());
return PageRankPull(g, cli.max_iters(), cli.tolerance(), cli.logging_en());
};
auto VerifierBound = [&cli] (const Graph &g, const pvector<ScoreT> &scores) {
return PRVerifier(g, scores, cli.tolerance());
Expand Down
11 changes: 7 additions & 4 deletions src/sssp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void RelaxEdges(const WGraph &g, NodeID u, WeightT delta,
}
}

pvector<WeightT> DeltaStep(const WGraph &g, NodeID source, WeightT delta) {
pvector<WeightT> DeltaStep(const WGraph &g, NodeID source, WeightT delta,
bool logging_enabled = false) {
Timer t;
pvector<WeightT> dist(g.num_nodes(), kDistInf);
dist[source] = 0;
Expand Down Expand Up @@ -128,7 +129,8 @@ pvector<WeightT> DeltaStep(const WGraph &g, NodeID source, WeightT delta) {
#pragma omp single nowait
{
t.Stop();
PrintStep(curr_bin_index, t.Millisecs(), curr_frontier_tail);
if (logging_enabled)
PrintStep(curr_bin_index, t.Millisecs(), curr_frontier_tail);
t.Start();
curr_bin_index = kMaxBin;
curr_frontier_tail = 0;
Expand All @@ -144,7 +146,8 @@ pvector<WeightT> DeltaStep(const WGraph &g, NodeID source, WeightT delta) {
#pragma omp barrier
}
#pragma omp single
cout << "took " << iter << " iterations" << endl;
if (logging_enabled)
cout << "took " << iter << " iterations" << endl;
}
return dist;
}
Expand Down Expand Up @@ -199,7 +202,7 @@ int main(int argc, char* argv[]) {
WGraph g = b.MakeGraph();
SourcePicker<WGraph> sp(g, cli.start_vertex());
auto SSSPBound = [&sp, &cli] (const WGraph &g) {
return DeltaStep(g, sp.PickNext(), cli.delta());
return DeltaStep(g, sp.PickNext(), cli.delta(), cli.logging_en());
};
SourcePicker<WGraph> vsp(g, cli.start_vertex());
auto VerifierBound = [&vsp] (const WGraph &g, const pvector<WeightT> &dist) {
Expand Down

0 comments on commit 1642dcf

Please sign in to comment.