#include <iostream>
using GNode = Graph::GraphNode;
void initialize(Graph& g) {
[&](GNode n) { g.getData(n) = 0; }
);
};
int main(int argc, char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " filename num_threads" << std::endl;
return 1;
}
Graph g;
T.start();
for (auto n : g) {
auto& sum = g.getData(n);
sum = 0;
for (auto e : g.edges(n)) {
sum += g.getEdgeData(e);
}
}
T.stop();
initialize(g);
[&](GNode n, auto&) {
for (auto e : g.edges(n)) {
auto dst = g.getEdgeDst(e);
g.getData(dst) += g.getEdgeData(e);
}
},
);
auto sumEdgeWeightsAtomically = [&](GNode n) {
for (auto e : g.edges(n)) {
auto dst = g.getEdgeDst(e);
auto& dstData = g.getData(dst);
auto edgeWeight = g.getEdgeData(e);
__sync_fetch_and_add(&dstData, edgeWeight);
}
};
initialize(g);
sumEdgeWeightsAtomically
,
);
initialize(g);
[&](GNode n, auto&) { sumEdgeWeightsAtomically(n); }
,
,
return 0;
}