diff --git a/tc.cc b/tc.cc index 210e258..6368601 100644 --- a/tc.cc +++ b/tc.cc @@ -12,11 +12,37 @@ #include "pvector.h" -using namespace std; +/* +GAP Benchmark Suite +Kernel: Triangle Counting (TC) +Author: Scott Beamer + +Will count the number of triangles (cliques of size 3) + +Requires input graph: + - to be undirected + - no duplicate edges (or else will be counted as multiple triangles) + - neighborhoods are sorted by vertex identifiers + +Other than symmetrizing, the rest of the requirements are done by SquishCSR +during graph building. +This implementation reduces the search space by counting each triangle only +once. A naive implementation will count the same triangle six times because +each of the three vertices (u, v, w) will count it in both ways. To count +a triangle only once, this implementation only counts a triangle if u > v > w. +Once the remaining unexamined neighbors identifiers get too big, it can break +out of the loop, but this requires that the neighbors to be sorted. + +Another optimization this implementation has is to relabel the vertices by +degree. This is beneficial if the average degree is high enough and if the +degree distribution is sufficiently non-uniform. To decide whether or not +to relabel the graph, we use the heuristic in WorthRelabelling. +*/ + + +using namespace std; -// assumes neighborhoods are sorted, no self loops, no duplicate edges -// counts triangles only once by ordering u>v>w size_t OrderedCount(const Graph &g) { size_t total = 0; #pragma omp parallel for reduction(+ : total) schedule(dynamic)