Skip to content

Commit

Permalink
improve performance of triangle counting (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
meyerzinn authored Apr 4, 2024
1 parent d6ef773 commit 05f73d4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
8 changes: 3 additions & 5 deletions include/scea/algo/tc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ class TriangleCounting : public Algo {

galois::do_all(galois::iterate((uint64_t)0, g.size()),
[&](uint64_t const& v0) {
g.sort_edges(v0);
g.for_each_edge(v0, [&](uint64_t const& v1) {
if (v0 >= v1)
return;
g.for_each_edge(v1, [&](uint64_t const& v2) {
// Check (v0, v2) exists?
if (v1 >= v2)
return;
g.for_each_edge(v0, [&](uint64_t const& v0_neighbor) {
if (v0_neighbor == v2)
numTriangles += 1;
return;
});
if (g.find_edge_sorted(v0, v2))
numTriangles += 1;
});
});
});
Expand Down
8 changes: 8 additions & 0 deletions include/scea/graph/adj.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class AdjGraph : public MutableGraph {
for (auto const& dst : edges[src])
callback(dst);
}

void sort_edges(uint64_t src) {
std::sort(edges[src].begin(), edges[src].end());
}

bool find_edge_sorted(uint64_t src, uint64_t dst) {
return std::binary_search(edges[src].begin(), edges[src].end(), dst);
}
};

} // namespace scea::graph
5 changes: 5 additions & 0 deletions include/scea/graph/csr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class LC_CSR : public MutableGraph {
for (auto const& edge : m_graph->edges(src))
callback(m_graph->getEdgeDst(edge));
}

void sort_edges(uint64_t src) override { m_graph->sortEdgesByDst(src); }
bool find_edge_sorted(uint64_t src, uint64_t dst) override {
return m_graph->findEdgeSortedByDst(src, dst) != m_graph->edge_end(src);
}
};

} // namespace scea::graph
6 changes: 6 additions & 0 deletions include/scea/graph/lscsr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class LS_CSR : public MutableGraph {
for (auto const& edge : graph.edges(src))
callback(graph.getEdgeDst(edge));
}

void sort_edges(uint64_t src) override { graph.sortEdges(src); }

bool find_edge_sorted(uint64_t src, uint64_t dst) override {
return graph.findEdgeSorted(src, dst);
}
};

} // namespace scea::graph
9 changes: 9 additions & 0 deletions include/scea/graph/morph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class MorphGraph : public MutableGraph {
for (auto const& edge : graph.edges(vertices[src]))
callback(graph.getData(graph.getEdgeDst(edge)));
}

void sort_edges(uint64_t src) override {
graph.sortEdgesByDst(vertices[src]);
}

bool find_edge_sorted(uint64_t src, uint64_t dst) override {
return graph.findEdgeSortedByDst(vertices[src], vertices[dst]) !=
graph.edge_end(vertices[src]);
}
};

} // namespace scea::graph
2 changes: 2 additions & 0 deletions include/scea/graph/mutable_graph_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class MutableGraph {
virtual void post_ingest() = 0;
virtual void for_each_edge(uint64_t src,
std::function<void(uint64_t const&)> callback) = 0;
virtual void sort_edges(uint64_t src) = 0;
virtual bool find_edge_sorted(uint64_t src, uint64_t dst) = 0;
};

} // namespace scea::graph

0 comments on commit 05f73d4

Please sign in to comment.