Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Arie Slobbe committed Jun 9, 2015
2 parents 9dc30ef + 0a43497 commit 10298bd
Show file tree
Hide file tree
Showing 13 changed files with 1,055 additions and 271 deletions.
6 changes: 3 additions & 3 deletions networkit/cpp/coarsening/ParallelPartitionCoarsening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::pair<Graph, std::vector<node> > ParallelPartitionCoarsening::run(const Grap

// iterate over edges of G and create edges in coarse graph or update edge and node weights in Gcon
DEBUG("create edges in coarse graphs");
GraphBuilder b(nextNodeId, true, false, true);
GraphBuilder b(nextNodeId, true, false);
#pragma omp parallel for schedule(guided)
for (node su = 0; su < nextNodeId; su++) {
std::map<index, edgeweight> outEdges;
Expand All @@ -136,11 +136,11 @@ std::pair<Graph, std::vector<node> > ParallelPartitionCoarsening::run(const Grap
});
}
for (auto it : outEdges) {
b.addEdge(su, it.first, it.second);
b.addHalfEdge(su, it.first, it.second);
}
}

Gcombined = b.toGraph();
Gcombined = b.toGraph(false);
}

timer.stop();
Expand Down
40 changes: 32 additions & 8 deletions networkit/cpp/coarsening/test/CoarseningGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ TEST_F(CoarseningGTest, testParallelPartitionCoarseningOnRealGraph) {

EXPECT_EQ(Gseq.numberOfEdges(), Gpar.numberOfEdges()) << "sequential and parallel coarsening should produce the same number of edges";

Gseq.forNodes([&](node u){
EXPECT_EQ(Gseq.degree(u), Gpar.degree(u)) << "node degrees should be equal";
EXPECT_EQ(Gseq.weightedDegree(u), Gpar.weightedDegree(u)) << "Weighted degrees should be equal";
Gseq.forNodes([&](node u) {
EXPECT_EQ(Gseq.degree(u), Gpar.degree(u)) << "node degrees should be equal for node " << u;
EXPECT_EQ(Gseq.weightedDegree(u), Gpar.weightedDegree(u)) << "Weighted degrees should be equald for node " << u;
EXPECT_EQ(parResult.second[u], seqResult.second[u]) << "mapping is equal";
});

Expand All @@ -177,27 +177,51 @@ TEST_F(CoarseningGTest, testParallelPartitionCoarseningOnRealGraphWithGraphBuild

ParallelPartitionCoarsening parCoarsening(true);
auto parResult = parCoarsening.run(G, random);
Graph Gpar = parResult.first;
EXPECT_EQ(k, Gpar.numberOfNodes());

ParallelPartitionCoarsening seqCoarsening(false);
auto seqResult = seqCoarsening.run(G, random);
Graph Gseq = seqResult.first;
EXPECT_EQ(k, Gseq.numberOfNodes());

EXPECT_EQ(Gseq.numberOfEdges(), Gpar.numberOfEdges()) << "sequential and parallel coarsening should produce the same number of edges";

Gseq.forNodes([&](node u) {
EXPECT_EQ(Gseq.degree(u), Gpar.degree(u)) << "node degrees should be equal for node " << u;
EXPECT_EQ(Gseq.weightedDegree(u), Gpar.weightedDegree(u)) << "Weighted degrees should be equal for node " << u;
EXPECT_EQ(parResult.second[u], seqResult.second[u]) << "mapping is equal";
});
}

TEST_F(CoarseningGTest, testParallelPartitionCoarseningOnRealGraphWithGraphBuilderAndLoops) {
METISGraphReader reader;
Graph G = reader.read("input/celegans_metabolic.graph");
G.addEdge(0, 0);

ClusteringGenerator clusteringGen;
count k = 10; // number of clusters in random clustering
Partition random = clusteringGen.makeRandomClustering(G, k);

ParallelPartitionCoarsening parCoarsening(true);
auto parResult = parCoarsening.run(G, random);
Graph Gpar = parResult.first;
EXPECT_EQ(k, Gpar.numberOfNodes());

ParallelPartitionCoarsening seqCoarsening(false);
auto seqResult = seqCoarsening.run(G, random);
Graph Gseq = seqResult.first;
EXPECT_EQ(k, Gseq.numberOfNodes());

EXPECT_EQ(Gseq.numberOfEdges(), Gpar.numberOfEdges()) << "sequential and parallel coarsening should produce the same number of edges";

Gseq.forNodes([&](node u){
EXPECT_EQ(Gseq.degree(u), Gpar.degree(u)) << "node degrees should be equal";
EXPECT_EQ(Gseq.weightedDegree(u), Gpar.weightedDegree(u)) << "Weighted degrees should be equal";
Gseq.forNodes([&](node u) {
EXPECT_EQ(Gseq.degree(u), Gpar.degree(u)) << "node degrees should be equal for node " << u;
EXPECT_EQ(Gseq.weightedDegree(u), Gpar.weightedDegree(u)) << "Weighted degrees should be equal for node " << u;
EXPECT_EQ(parResult.second[u], seqResult.second[u]) << "mapping is equal";
});

}


} /* namespace NetworKit */

#endif /*NOGTEST */
6 changes: 2 additions & 4 deletions networkit/cpp/generators/ChungLuGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ Graph ChungLuGenerator::generate() {
double randVal = Aux::Random::probability();
/* Probability of edge (u, v): d(u)*d(v)/sum_deg */
if (randVal < double(seq[u] * seq[v]) / sum_deg) {
gB.addEdge(u, v);
gB.addHalfOutEdge(u, v);
}
});


return gB.toGraph();
return gB.toGraph(true,true);
}

} /* namespace NetworKit */
31 changes: 15 additions & 16 deletions networkit/cpp/generators/test/GeneratorsBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ TEST_F(GeneratorsBenchmark, benchmarkGraphBuilder) {
int tid = omp_get_thread_num();
double rdn = randomPerThread[tid]();
if (rdn <= p) {
builder.addEdge(u, v);
builder.addHalfEdge(u, v);
}
});
});
t2 = timeOnce([&]() {
G = builder.toGraph(false);
G = builder.toGraph(true);
});
m_actual = G.numberOfEdges();
EXPECT_NEAR(m_actual / (double) m_expected, 1.0, 0.1);
std::cout << "parallelForNodePairs + toGraphSequentiel:\t\t" << t1 << " + " << t2 << " = " << (t1 + t2) << " ms\n";
// printf("parallelForNodePairs + toGraphSequentiel:\t\t%" PRIu64 " + %" PRIu64 " = %" PRIu64 " ms\n", t1, t2, t1 + t2);

// fully parallel way
m_actual = 0;
Expand All @@ -72,29 +71,29 @@ TEST_F(GeneratorsBenchmark, benchmarkGraphBuilder) {
int tid = omp_get_thread_num();
double rdn = randomPerThread[tid]();
if (rdn <= p) {
builder.addEdge(u, v);
builder.addHalfEdge(u, v);
}
});
});
t2 = timeOnce([&]() {
G = builder.toGraph();
G = builder.toGraph(true, false);
});
m_actual = G.numberOfEdges();
EXPECT_NEAR(m_actual / (double) m_expected, 1.0, 0.1);
std::cout << "parallelForNodePairs + toGraphParallel:\t\t" << t1 << " + " << t2 << " = " << (t1 + t2) << " ms\n";

// old way
// t1 = timeOnce([&]() {
// G = Graph(n);
// G.forNodePairs([&](node u, node v) {
// if (randomPerThread[0]() <= p) {
// G.addEdge(u, v);
// }
// });
// });
// m_actual = G.numberOfEdges();
// EXPECT_NEAR(m_actual / (double) m_expected, 1.0, 0.1);
// std::cout << "forNodePairs + Graph.addEdge:\t\t\t\t" << t1 << " ms\n";
t1 = timeOnce([&]() {
G = Graph(n);
G.forNodePairs([&](node u, node v) {
if (randomPerThread[0]() <= p) {
G.addEdge(u, v);
}
});
});
m_actual = G.numberOfEdges();
EXPECT_NEAR(m_actual / (double) m_expected, 1.0, 0.1);
std::cout << "forNodePairs + Graph.addEdge:\t\t\t\t" << t1 << " ms\n";
}

TEST_F(GeneratorsBenchmark, benchmarkBarabasiAlbertGenerator) {
Expand Down
Loading

0 comments on commit 10298bd

Please sign in to comment.