#include "Lonestar/BoilerPlate.h"
static const char* name = "Count levels";
static const char* desc = "Computes the number of degree levels";
#define DEBUG false
namespace cll = llvm::cl;
static cll::opt<std::string>
inputFile(cll::Positional, cll::desc("<input graph>"), cll::Required);
static cll::opt<unsigned int> startNode("startNode",
cll::desc("Node to start search from"),
enum COLOR { WHITE, GRAY, BLACK };
struct LNode {
uint32_t dist;
COLOR color;
};
true>::type ::with_no_lockable<true>::type;
using GNode = Graph::GraphNode;
static const unsigned int DIST_INFINITY =
auto merge = [](Vec& lhs, Vec&& rhs) -> Vec& {
Vec v(std::move(rhs));
if (lhs.size() < v.size()) {
lhs.resize(v.size());
}
auto ll = lhs.begin();
for (auto ii = v.begin(), ei = v.end(); ii != ei; ++ii, ++ll) {
*ll += *ii;
}
return lhs;
};
auto identity = []() -> Vec { return Vec(); };
LNode srcdata = graph.getData(n);
if (srcdata.dist == DIST_INFINITY) {
return;
}
auto& vec = r.getLocal();
if (vec.size() <= srcdata.dist) {
vec.resize(srcdata.dist + 1);
}
vec[srcdata.dist] += 1;
});
return r.reduce();
}
void bfsSerial(Graph& graph, GNode source) {
LNode& sdata = graph.getData(source, flag);
sdata.dist = 0u;
sdata.color = GRAY;
std::queue<GNode> queue;
queue.push(source);
while (!queue.empty()) {
GNode curr = queue.front();
sdata = graph.getData(curr, flag);
queue.pop();
for (auto e : graph.edges(curr)) {
GNode dst = graph.getEdgeDst(e);
LNode& ddata = graph.getData(dst);
if (ddata.color == WHITE) {
ddata.color = GRAY;
ddata.dist = sdata.dist + 1;
queue.push(dst);
}
}
sdata.color = BLACK;
}
}
int main(int argc, char** argv) {
LonestarStart(argc, argv, name, desc, nullptr, &inputFile);
OT.start();
Graph graph;
std::cout << "Read " << graph.size() << " nodes, " << graph.sizeEdges()
<< " edges\n";
galois::preAlloc(5 * numThreads +
galois::reportPageAlloc("MeminfoPre");
[&](const GNode& src) {
LNode& sdata = graph.getData(src);
sdata.color = WHITE;
sdata.dist = DIST_INFINITY;
},
if (startNode >= graph.size()) {
std::cerr << "Source node index " << startNode
<< " is greater than the graph size" << graph.size()
<< ", failed to set source: " << startNode << "\n";
assert(0);
abort();
}
GNode source;
auto it = graph.begin();
std::advance(it, startNode.getValue());
source = *it;
bfsSerial(graph, source);
const auto& counts = countLevels(graph);
galois::reportPageAlloc("MeminfoPost");
#if DEBUG
for (auto n : graph) {
LNode& data = graph.getData(n);
std::cout << "Node: " << n << " BFS dist:" << data.dist << std::endl;
}
#endif
std::cout << "Number of BFS levels: " << counts.size() << "\n";
OT.stop();
return EXIT_SUCCESS;
}