27 #ifndef _GALOIS_DIST_HGRAPH_H_
28 #define _GALOIS_DIST_HGRAPH_H_
30 #include <unordered_map>
63 template <
typename NodeTy,
typename EdgeTy>
67 constexpr
static const char*
const GRNAME =
"dGraph";
98 std::vector<std::pair<uint64_t, uint64_t>>
gid2host;
111 std::vector<uint32_t> allNodesRanges;
113 std::vector<uint32_t> masterRanges;
116 std::vector<uint32_t> withEdgeRanges;
118 std::vector<uint32_t> allNodesRangesIn;
120 std::vector<uint32_t> masterRangesIn;
127 std::vector<NodeRangeType> specificRanges;
129 std::vector<NodeRangeType> specificRangesIn;
136 static_cast<uint32_t>(
155 template <
typename GraphNode,
typename ET>
180 const std::vector<unsigned>& scalefactor,
181 unsigned DecomposeFactor = 1) {
182 uint64_t numNodes_to_divide = g.
size();
183 if (scalefactor.empty() || (
numHosts * DecomposeFactor == 1)) {
184 for (
unsigned i = 0; i <
numHosts * DecomposeFactor; ++i)
191 assert(scalefactor.size() ==
numHosts);
193 unsigned numBlocks = 0;
195 for (
unsigned i = 0; i <
numHosts; ++i) {
196 numBlocks += scalefactor[i];
199 std::vector<std::pair<uint64_t, uint64_t>> blocks;
200 for (
unsigned i = 0; i < numBlocks; ++i) {
205 std::vector<unsigned> prefixSums;
206 prefixSums.push_back(0);
208 for (
unsigned i = 1; i <
numHosts; ++i) {
209 prefixSums.push_back(prefixSums[i - 1] + scalefactor[i - 1]);
212 for (
unsigned i = 0; i <
numHosts; ++i) {
213 unsigned firstBlock = prefixSums[i];
214 unsigned lastBlock = prefixSums[i] + scalefactor[i] - 1;
216 std::make_pair(blocks[firstBlock].first, blocks[lastBlock].second));
236 const std::vector<unsigned>& scalefactor,
238 unsigned DecomposeFactor = 1) {
239 if (edgeWeight == 0) {
245 gid2host.resize(numHosts * DecomposeFactor);
246 for (
unsigned d = 0; d < DecomposeFactor; ++d) {
247 auto r = g.
divideByNode(0, edgeWeight, (
id + d * numHosts),
248 numHosts * DecomposeFactor, scalefactor);
249 gid2host[
id + d * numHosts].first = *(r.first.first);
250 gid2host[
id + d * numHosts].second = *(r.first.second);
253 for (
unsigned h = 0; h < numHosts; ++h) {
258 for (
unsigned d = 0; d < DecomposeFactor; ++d) {
259 galois::runtime::gSerialize(b, gid2host[
id + d * numHosts]);
264 unsigned received = 1;
265 while (received < numHosts) {
270 assert(p->first !=
id);
272 for (
unsigned d = 0; d < DecomposeFactor; ++d) {
277 increment_evilPhase();
280 for (
unsigned h = 0; h < numHosts; h++) {
282 assert(gid2host[h].first == 0);
283 }
else if (h == numHosts - 1) {
284 assert(gid2host[h].first == gid2host[h - 1].second);
285 assert(gid2host[h].second == g.
size());
287 assert(gid2host[h].first == gid2host[h - 1].second);
288 assert(gid2host[h].second == gid2host[h + 1].first);
311 void computeMastersBalancedNodesAndEdges(
313 uint32_t nodeWeight, uint32_t edgeWeight,
unsigned) {
314 if (nodeWeight == 0) {
317 if (edgeWeight == 0) {
322 gid2host.resize(numHosts);
323 auto r = g.
divideByNode(nodeWeight, edgeWeight,
id, numHosts, scalefactor);
324 gid2host[id].first = *r.first.first;
325 gid2host[id].second = *r.first.second;
326 for (
unsigned h = 0; h < numHosts; ++h) {
330 galois::runtime::gSerialize(b, gid2host[
id]);
334 unsigned received = 1;
335 while (received < numHosts) {
340 assert(p->first !=
id);
345 increment_evilPhase();
366 const std::vector<unsigned>& scalefactor,
367 uint32_t nodeWeight = 0, uint32_t edgeWeight = 0,
368 unsigned DecomposeFactor = 1) {
373 uint64_t numNodes_to_divide = g.
size();
376 switch (masters_distribution) {
378 computeMastersBlockedNodes(g, scalefactor, DecomposeFactor);
381 computeMastersBalancedNodesAndEdges(g, scalefactor, nodeWeight,
382 edgeWeight, DecomposeFactor);
386 computeMastersBalancedEdges(g, scalefactor, edgeWeight, DecomposeFactor);
392 galois::runtime::reportStatCond_Tmax<MORE_DIST_STATS>(
393 GRNAME,
"MasterDistTime", timer.
get());
396 "[",
id,
"] Master distribution time : ", timer.
get_usec() / 1000000.0f,
399 return numNodes_to_divide;
406 std::ifstream mappings(filename);
409 unsigned timesToRead =
id + 1;
411 for (
unsigned i = 0; i < timesToRead; i++) {
412 std::getline(mappings, curLine);
415 std::vector<char> modifyLine(curLine.begin(), curLine.end());
416 char* tokenizedString = modifyLine.data();
418 token = strtok(tokenizedString,
" ");
421 for (
unsigned i = 0; i < 6; i++) {
422 token = strtok(NULL,
" ");
424 std::string left(token);
427 for (
unsigned i = 0; i < 3; i++) {
428 token = strtok(NULL,
" ");
430 std::string right(token);
432 gid2host.resize(numHosts);
433 gid2host[id].first = std::stoul(left);
434 gid2host[id].second = std::stoul(right) + 1;
436 ", Right: ", gid2host[
id].second,
"\n");
443 for (
unsigned h = 0; h < numHosts; ++h) {
447 galois::runtime::gSerialize(b, gid2host[
id]);
451 unsigned received = 1;
452 while (received < numHosts) {
457 assert(p->first !=
id);
462 increment_evilPhase();
465 for (
unsigned h = 0; h < numHosts; h++) {
468 }
else if (h == numHosts - 1) {
470 gid2host[h].first,
" ", gid2host[h - 1].second);
475 gid2host[h].first,
" ", gid2host[h - 1].second);
477 gid2host[h].second,
" ", gid2host[h + 1].first);
482 uint32_t
G2L(uint64_t gid)
const {
483 assert(isLocal(gid));
484 return globalToLocalMap.at(gid);
487 uint64_t
L2G(uint32_t lid)
const {
return localToGlobalVector[lid]; }
508 : transposed(false), id(host), numHosts(numHosts) {
509 mirrorNodes.resize(numHosts);
521 std::vector<std::pair<uint32_t, uint32_t>> mirrorRangesVector;
524 if (numOwned != numNodes) {
525 assert(numOwned < numNodes);
526 mirrorRangesVector.push_back(std::make_pair(numOwned, numNodes));
528 return mirrorRangesVector;
535 virtual unsigned getHostID(uint64_t)
const = 0;
538 virtual bool isOwned(uint64_t)
const = 0;
541 virtual bool isLocal(uint64_t)
const = 0;
546 virtual bool is_vertex_cut()
const = 0;
551 return std::make_pair(0u, 0u);
562 inline uint64_t
getGID(
const uint32_t nodeID)
const {
return L2G(nodeID); }
570 inline uint32_t
getLID(
const uint64_t nodeID)
const {
return G2L(nodeID); }
582 auto& r = graph.getData(N, mflag);
593 inline typename GraphTy::edge_data_reference
596 auto& r = graph.getEdgeData(ni, mflag);
637 return galois::graphs::internal::make_no_deref_range(edge_begin(N),
646 inline size_t size()
const {
return graph.size(); }
653 inline size_t sizeEdges()
const {
return graph.sizeEdges(); }
691 assert(specificRanges.size() == 3);
692 return specificRanges[0];
702 assert(specificRanges.size() == 3);
703 return specificRanges[1];
714 assert(specificRanges.size() == 3);
715 return specificRanges[2];
738 assert(masterRanges.size() == 0);
742 if (beginMaster == 0 && (beginMaster + numOwned) == size()) {
743 masterRanges = allNodesRanges;
744 }
else if (beginMaster == 0 &&
745 (beginMaster + numOwned) == numNodesWithEdges &&
746 withEdgeRanges.size() != 0) {
747 masterRanges = withEdgeRanges;
752 beginMaster + numOwned, 0);
764 assert(withEdgeRanges.size() == 0);
768 if (numNodesWithEdges == size()) {
769 withEdgeRanges = allNodesRanges;
770 }
else if (beginMaster == 0 &&
771 (beginMaster + numOwned) == numNodesWithEdges &&
772 masterRanges.size() != 0) {
773 withEdgeRanges = masterRanges;
786 assert(specificRanges.size() == 0);
791 assert(allNodesRanges.size() != 0);
792 assert(masterRanges.size() != 0);
793 assert(withEdgeRanges.size() != 0);
797 boost::counting_iterator<size_t>(0),
798 boost::counting_iterator<size_t>(size()), allNodesRanges.data()));
802 boost::counting_iterator<size_t>(beginMaster),
803 boost::counting_iterator<size_t>(beginMaster + numOwned),
804 masterRanges.data()));
808 boost::counting_iterator<size_t>(0),
809 boost::counting_iterator<size_t>(numNodesWithEdges),
810 withEdgeRanges.data()));
812 assert(specificRanges.size() == 3);
859 template <
typename NodeTy,
typename EdgeTy>
864 #endif //_GALOIS_DIST_HGRAPH_H
size_t sizeEdges() const
Gets number of edges on this (local) graph.
Definition: DistributedGraph.h:653
void deallocate()
Deallocates underlying LC CSR Graph.
Definition: DistributedGraph.h:841
uint64_t get() const
Definition: Timer.cpp:29
uint64_t numGlobalEdges
Total edges in the global unpartitioned graph.
Definition: DistributedGraph.h:80
uint32_t getHostID()
Gets this host's ID.
Definition: Network.cpp:41
void increment_evilPhase()
Increments evilPhase, a phase counter used by communication.
Definition: DistributedGraph.h:133
A simple timer.
Definition: Timer.h:31
void start()
Definition: Timer.cpp:25
std::pair< IterTy, IterTy > block_range(IterTy b, IterTy e, unsigned id, unsigned num)
Returns a continuous block from the range based on the number of divisions and the id of the block re...
Definition: gstl.h:244
uint64_t getGID(const uint32_t nodeID) const
Converts a local node id into a global node id.
Definition: DistributedGraph.h:562
uint64_t numGlobalNodes
Total nodes in the global unpartitioned graph.
Definition: DistributedGraph.h:79
const uint32_t numHosts
Total number of machines.
Definition: DistributedGraph.h:85
typename GraphTy::edge_iterator edge_iterator
iterator type over edges
Definition: DistributedGraph.h:499
uint32_t getLID(const uint64_t nodeID) const
Converts a global node id into a local node id.
Definition: DistributedGraph.h:570
used to sort edges in the sort edges function
Definition: DistributedGraph.h:156
auto divideByNode(size_t nodeWeight, size_t edgeWeight, size_t id, size_t total, std::vector< unsigned > scaleFactor=std::vector< unsigned >()) -> GraphRange
Returns 2 ranges (one for nodes, one for edges) for a particular division.
Definition: OfflineGraph.h:324
size_t numMasters() const
Gets number of nodes on this (local) graph.
Definition: DistributedGraph.h:660
Buffer for serialization of data.
Definition: Serialize.h:56
GraphNode getEdgeDst(edge_iterator ni)
Gets edge destination of edge ni.
Definition: DistributedGraph.h:606
uint64_t num_bytes_read()
Definition: OfflineGraph.h:258
void gDebug(Args &&...GALOIS_USED_ONLY_IN_DEBUG(args))
Prints a debug string from a sequence of things; prints nothing if NDEBUG is defined.
Definition: gIO.h:72
Definition: Iterable.h:36
Contains the DynamicBitSet class and most of its implementation.
typename GraphTy::iterator iterator
iterator type over nodes
Definition: DistributedGraph.h:495
void sortEdgesByDestination()
Sort the underlying LC_CSR_Graph by ID (destinations) It sorts edges of the nodes by destination...
Definition: DistributedGraph.h:850
size_t size() const
Gets number of nodes on this (local) graph.
Definition: DistributedGraph.h:646
void gDeserialize(DeSerializeBuffer &buf, T1 &&t1, Args &&...args)
Deserialize data in a buffer into a series of objects.
Definition: Serialize.h:1032
SpecificRange< IterTy > makeSpecificRange(IterTy begin, IterTy end, const uint32_t *thread_ranges)
Creates a SpecificRange object.
Definition: Range.h:219
const char * loopname
Definition: Executor_ParaMeter.h:145
#define GALOIS_DIE(...)
Definition: gIO.h:96
void read_local_graph_from_file(std::string)
Read the local LC_CSR graph from the file on a disk.
Definition: DistributedGraph.h:834
uint64_t numEdges
Num edges in this graph in total.
Definition: DistributedGraph.h:82
std::vector< std::vector< size_t > > & getMirrorNodes()
Definition: DistributedGraph.h:531
iterator const_iterator
Definition: LC_CSR_Graph.h:155
uint32_t G2L(uint64_t gid) const
Definition: DistributedGraph.h:482
const NodeRangeType & allNodesRange() const
Returns a range object that encapsulates all nodes of the graph.
Definition: DistributedGraph.h:690
std::vector< uint32_t > determineUnitRangesFromGraph(GraphTy &graph, uint32_t unitsToSplit, uint32_t nodeAlpha=0)
Determines node division ranges for all nodes in a graph and returns it in an offset vector...
Definition: GraphHelpers.h:403
size_t globalSizeEdges() const
Gets number of edges on the global unpartitioned graph.
Definition: DistributedGraph.h:683
void determineThreadRanges()
Uses a pre-computed prefix sum to determine division of nodes among threads.
Definition: DistributedGraph.h:725
std::vector< std::pair< uint32_t, uint32_t > > getMirrorRanges() const
Return a vector of pairs denoting mirror node ranges.
Definition: DistributedGraph.h:520
edge_iterator edge_begin(GraphNode N)
Gets the first edge of some node.
Definition: DistributedGraph.h:614
bool isTransposed()
Definition: DistributedGraph.h:554
#define GALOIS_ASSERT(cond,...)
Like assert but unconditionally executed.
Definition: gIO.h:102
void edgesEqualMasters()
Specific range editor: makes the range for edges equivalent to the range for masters.
Definition: DistributedGraph.h:819
typename GraphTy::const_iterator const_iterator
constant iterator type over nodes
Definition: DistributedGraph.h:497
std::vector< std::vector< size_t > > mirrorNodes
Mirror nodes from different hosts. For reduce.
Definition: DistributedGraph.h:100
EdgeTy EdgeType
Expose EdgeTy to other classes.
Definition: DistributedGraph.h:493
std::vector< std::pair< uint64_t, uint64_t > > gid2host
Information that converts host to range of nodes that host reads.
Definition: DistributedGraph.h:98
const NodeRangeType & masterNodesRange() const
Returns a range object that encapsulates only master nodes in this graph.
Definition: DistributedGraph.h:701
const Ty max(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:40
virtual std::pair< unsigned, unsigned > cartesianGrid() const
Returns Cartesian split (if it exists, else returns pair of 0s.
Definition: DistributedGraph.h:550
size_t getNumNodesWithEdges() const
Gets number of nodes with edges (may include nodes without edges) on this (local) graph...
Definition: DistributedGraph.h:669
galois::runtime::iterable< galois::NoDerefIterator< edge_iterator > > edges(GraphNode N)
Returns an iterable object over the edges of a particular node in the graph.
Definition: DistributedGraph.h:636
Definition: OfflineGraph.h:63
Contains declaration of DistStatManager, which reports runtime statistics of a distributed applicatio...
MASTERS_DISTRIBUTION
Enums specifying how masters are to be distributed among hosts.
Definition: DistributedGraph.h:48
bool transposed
Marks if the graph is transposed or not.
Definition: DistributedGraph.h:76
typename GraphTy::GraphNode GraphNode
Type representing a node in this graph.
Definition: DistributedGraph.h:491
void determineThreadRangesMaster()
Determines the thread ranges for master nodes only and saves them to the object.
Definition: DistributedGraph.h:736
void gPrint(Args &&...args)
Prints a sequence of things.
Definition: gIO.h:47
Proxy object for internal EdgeSortReference.
Definition: Details.h:56
edge_iterator edge_end(GraphNode N)
Gets the end edge boundary of some node.
Definition: DistributedGraph.h:625
unsigned evilPhasePlus1()
Returns evilPhase + 1, handling loop around as necessary.
Definition: DistributedGraph.h:144
unsigned int activeThreads
Definition: Threads.cpp:26
NetworkInterface & getSystemNetworkInterface()
Get the network interface.
Definition: Network.cpp:131
MethodFlag
What should the runtime do when executing a method.
Definition: MethodFlags.h:34
GraphNode dst
Definition: Details.h:63
boost::counting_iterator< typename EdgeIndData::value_type > edge_iterator
Definition: LC_CSR_Graph.h:153
SpecificRange is a range type where a threads range is specified by an an int array that tells you wh...
Definition: Range.h:122
size_t globalSize() const
Gets number of nodes on the global unpartitioned graph.
Definition: DistributedGraph.h:676
uint32_t numNodes
Num nodes in this graph in total.
Definition: DistributedGraph.h:81
balance nodes and edges
Definition: DistributedGraph.h:54
void save_local_graph_to_file(std::string)
Write the local LC_CSR graph to the file on a disk.
Definition: DistributedGraph.h:827
bool operator()(const galois::graphs::EdgeSortValue< GraphNode, ET > &e1, const galois::graphs::EdgeSortValue< GraphNode, ET > &e2) const
Definition: DistributedGraph.h:158
uint32_t numOwned
Number of nodes owned (masters) by this host.
Definition: DistributedGraph.h:89
void do_all(const RangeFunc &rangeMaker, FunctionTy &&fn, const Args &...args)
Standard do-all loop.
Definition: Loops.h:71
uint32_t numNodesWithEdges
Number of nodes (masters + mirrors) that have outgoing edges.
Definition: DistributedGraph.h:94
uint64_t L2G(uint32_t lid) const
Definition: DistributedGraph.h:487
uint64_t computeMasters(MASTERS_DISTRIBUTION masters_distribution, galois::graphs::OfflineGraph &g, const std::vector< unsigned > &scalefactor, uint32_t nodeWeight=0, uint32_t edgeWeight=0, unsigned DecomposeFactor=1)
Wrapper call that will call into more specific compute masters functions that compute masters based o...
Definition: DistributedGraph.h:364
void initializeSpecificRanges()
Initializes the 3 range objects that a user can access to iterate over the graph in different ways...
Definition: DistributedGraph.h:785
void reset_seek_counters()
Definition: OfflineGraph.h:264
const NodeRangeType & allNodesWithEdgesRange() const
Returns a range object that encapsulates master nodes and nodes with edges in this graph...
Definition: DistributedGraph.h:713
size_t size() const
Definition: OfflineGraph.h:271
void readersFromFile(galois::graphs::OfflineGraph &g, std::string filename)
reader assignment from a file corresponds to master assignment if using an edge cut ...
Definition: DistributedGraph.h:404
std::unordered_map< uint64_t, uint32_t > globalToLocalMap
LID = globalToLocalMap[GID].
Definition: DistributedGraph.h:105
void stop()
Definition: Timer.cpp:27
uint32_t evilPhase
Variable that keeps track of which network send/recv phase a program is currently on...
Definition: Network.cpp:36
Base DistGraph class that all distributed graphs extend from.
Definition: DistributedGraph.h:64
auto iterate(C &cont)
Definition: Range.h:323
DistGraph(unsigned host, unsigned numHosts)
Constructor for DistGraph.
Definition: DistributedGraph.h:507
NodeTy & getData(GraphNode N, galois::MethodFlag mflag=galois::MethodFlag::UNPROTECTED)
Get data of a node.
Definition: DistributedGraph.h:580
uint64_t num_seeks()
Definition: OfflineGraph.h:252
std::vector< uint64_t > localToGlobalVector
GID = localToGlobalVector[LID].
Definition: DistributedGraph.h:103
const unsigned id
ID of the machine.
Definition: DistributedGraph.h:84
Contains the implementation of BufferedGraph.
size_t sizeEdges() const
Definition: OfflineGraph.h:272
std::vector< uint32_t > determineUnitRangesFromPrefixSum(uint32_t unitsToSplit, VectorTy &edgePrefixSum, uint32_t nodeAlpha=0)
Uses the divideByNode function (which is binary search based) to divide nodes among units using a pro...
Definition: GraphHelpers.h:484
balance nodes
Definition: DistributedGraph.h:50
uint32_t GraphNode
Definition: LC_CSR_Graph.h:146
GraphTy graph
The internal graph used by DistGraph to represent the graph.
Definition: DistributedGraph.h:73
uint64_t get_usec() const
Definition: Timer.cpp:34
boost::counting_iterator< typename EdgeDst::value_type > iterator
Definition: LC_CSR_Graph.h:154
void determineThreadRangesWithEdges()
Determines the thread ranges for nodes with edges only and saves them to the object.
Definition: DistributedGraph.h:762
GraphTy::edge_data_reference getEdgeData(edge_iterator ni, galois::MethodFlag mflag=galois::MethodFlag::UNPROTECTED)
Get the edge data for a particular edge in the graph.
Definition: DistributedGraph.h:594
uint32_t beginMaster
Local id of the beginning of master nodes.
Definition: DistributedGraph.h:91
balance edges
Definition: DistributedGraph.h:52