26 #ifndef GALOIS_GRAPHS_LC_MORPH_GRAPH_H
27 #define GALOIS_GRAPHS_LC_MORPH_GRAPH_H
29 #include <type_traits>
31 #include <boost/mpl/if.hpp>
34 #include "galois/config.h"
46 template <
typename NodeTy,
typename EdgeTy,
bool HasNoLockable =
false,
47 bool UseNumaAlloc =
false,
bool HasOutOfLineLockable =
false,
48 bool HasId =
false,
typename FileEdgeTy = EdgeTy>
50 :
private boost::noncopyable,
51 private internal::OutOfLineLockableFeature<HasOutOfLineLockable &&
54 template <
typename Graph>
63 template <
bool _has_
id>
66 HasOutOfLineLockable, _has_id, FileEdgeTy>;
73 template <
typename _node_data>
76 HasOutOfLineLockable, HasId, FileEdgeTy>;
83 template <
typename _edge_data>
86 HasOutOfLineLockable, HasId, FileEdgeTy>;
93 template <
typename _file_edge_data>
96 HasOutOfLineLockable, HasId, _file_edge_data>;
103 template <
bool _has_no_lockable>
106 HasOutOfLineLockable, HasId, FileEdgeTy>;
113 template <
bool _use_numa_alloc>
116 HasOutOfLineLockable, HasId, FileEdgeTy>;
123 template <
bool _has_out_of_line_lockable>
126 _has_out_of_line_lockable,
127 _has_out_of_line_lockable || HasId, FileEdgeTy>;
138 using EdgeInfo = internal::EdgeInfoBase<NodeInfo*, EdgeTy>;
143 internal::NodeInfoBaseTypes<NodeTy,
144 !HasNoLockable && !HasOutOfLineLockable>;
162 :
public internal::NodeInfoBase<NodeTy,
163 !HasNoLockable && !HasOutOfLineLockable> {
165 internal::NodeInfoBase<NodeTy, !HasNoLockable && !HasOutOfLineLockable>;
176 template <
typename... Args>
177 NodeInfo(Args&&... args) : Super(std::forward<Args>(args)...) {}
217 boost::transform_iterator<makeGraphNode, typename Nodes::iterator>;
220 boost::transform_iterator<makeGraphNode, typename Nodes::const_iterator>;
241 template <
bool _A1 = HasNoLockable,
bool _A2 = HasOutOfLineLockable>
243 typename std::enable_if<!_A1 && !_A2>::type* = 0) {
255 template <
bool _A1 = HasOutOfLineLockable,
bool _A2 = HasNoLockable>
257 typename std::enable_if<_A1 && !_A2>::type* = 0) {
258 this->outOfLineAcquire(
getId(N), mflag);
265 template <
bool _A1 = EdgeInfo::has_value,
270 typename std::enable_if<!_A1 || _A2>::type* = 0) {
271 if (EdgeInfo::has_value) {
287 template <
bool _A1 = EdgeInfo::has_value,
291 typename std::enable_if<_A1 && !_A2>::type* = 0) {
298 template <
bool _A1 = HasOutOfLineLockable,
bool _A2 = HasNoLockable>
300 typename std::enable_if<_A2>::type* = 0) {}
305 template <
bool _Enable = HasId>
322 if (EdgeInfo::has_value) {
323 while (edgeBegin != edgeEnd) {
324 edgeBegin->destroy();
389 for (
edge_iterator ii = N->edgeBegin, ee = N->edgeEnd; ii != ee; ++ii) {
409 return internal::make_no_deref_range(
edge_begin(N, mflag),
417 internal::EdgesIterator<LC_Morph_Graph>
419 return internal::EdgesIterator<LC_Morph_Graph>(*
this, N, mflag);
429 template <
typename... Args>
437 std::distance(local_edges->
begin, local_edges->
end) < nedges) {
442 local_edges =
reinterpret_cast<EdgeHolder*
>(block);
443 local_edges->
next = old;
446 block =
reinterpret_cast<char*
>(block) +
sizeof(
EdgeHolder);
448 if (!std::align(std::alignment_of_v<EdgeInfo>,
sizeof(
EdgeInfo), block,
454 local_edges->
end = local_edges->
begin;
456 if (std::distance(local_edges->
begin, local_edges->
end) < nedges) {
462 N->edgeBegin = N->edgeEnd = local_edges->
begin;
463 local_edges->
begin += nedges;
465 N->trueEdgeEnd = local_edges->
begin;
478 template <
typename... Args>
484 if (it == src->edgeEnd) {
486 it->construct(std::forward<Args>(args)...);
488 assert(src->edgeEnd <= src->trueEdgeEnd);
503 template <
typename... Args>
507 auto it = src->edgeEnd;
509 it->construct(std::forward<Args>(args)...);
511 assert(src->edgeEnd <= src->trueEdgeEnd);
525 assert(src->edgeBegin <= src->edgeEnd);
526 std::swap(*dst, *src->edgeEnd);
527 src->edgeEnd->destroy();
550 size_t numNodes = graph.
size();
554 this->outOfLineAllocateLocal(numNodes);
557 this->outOfLineAllocateInterleaved(numNodes);
576 LC_Morph_Graph::size_of_out_of_line::value,
602 LC_Morph_Graph::size_of_out_of_line::value,
boost::transform_iterator< makeGraphNode, typename Nodes::iterator > iterator
Iterator over nodes.
Definition: LC_Morph_Graph.h:217
void acquireNode(GraphNode N, MethodFlag mflag, typename std::enable_if<!_A1 &&!_A2 >::type *=0)
Acquire a node for the scope in which the function is called.
Definition: LC_Morph_Graph.h:242
EdgeTy edge_data_type
Type of edge data.
Definition: LC_Morph_Graph.h:206
Struct used to define the type of node data through the template parameter.
Definition: LC_Morph_Graph.h:74
typename NodeInfoTypes::reference node_data_reference
Reference type to node data.
Definition: LC_Morph_Graph.h:210
reference emplace(Args &&...args)
Thread safe bag insertion.
Definition: Bag.h:260
internal::EdgeInfoBase< NodeInfo *, EdgeTy > EdgeInfo
EdgeInfo keeps destination of edges.
Definition: LC_Morph_Graph.h:138
GraphNode createNode(int nedges, Args &&...args)
Creates a new node with a cap on the number of edges.
Definition: LC_Morph_Graph.h:430
edge_iterator edge_begin(GraphNode N)
Returns the index to the beginning of global node N's outgoing edges in the outgoing edges array...
Definition: FileGraph.cpp:641
Contains FileGraph and FileGraphWriter class declarations.
void constructEdgesFrom(FileGraph &graph, unsigned tid, unsigned total, const ReadGraphAuxData &aux)
Constructs the LCMorphGraph edges given a FileGraph to construct it from and pointers to already crea...
Definition: LC_Morph_Graph.h:598
NodeInfo * dst
Destination to compare with.
Definition: LC_Morph_Graph.h:192
iterator begin()
Definition: Bag.h:238
size_t size() const
Returns the number of nodes in the (sub)graph.
Definition: FileGraph.h:545
GraphNode getEdgeDst(edge_iterator ni)
Get the destination of an edge given an iterator to the edge.
Definition: LC_Morph_Graph.h:354
T value_type
Definition: LargeArray.h:60
boost::counting_iterator< uint64_t > iterator
uint64 boost counting iterator
Definition: FileGraph.h:408
Nodes nodes
Nodes in this graph.
Definition: LC_Morph_Graph.h:230
~LC_Morph_Graph()
Destructor.
Definition: LC_Morph_Graph.h:315
internal::EdgesIterator< LC_Morph_Graph > out_edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Returns an object with begin() and end() methods to iterate over the outgoing edges of N...
Definition: LC_Morph_Graph.h:418
GraphNode getEdgeDst(edge_iterator it)
Gets the destination of some edge.
Definition: FileGraph.cpp:669
local_iterator local_begin()
Return an iterator to the beginning of the local nodes of the graph.
Definition: LC_Morph_Graph.h:373
boost::counting_iterator< uint64_t > edge_iterator
Edge iterators (boost iterator)
Definition: FileGraph.h:248
Definition: Iterable.h:36
local_iterator local_begin()
Definition: Bag.h:243
EdgeInfo * end
End of memory for this block.
Definition: LC_Morph_Graph.h:152
FileEdgeTy file_edge_data_type
Type of edge data in file.
Definition: LC_Morph_Graph.h:204
iterator begin()
Returns an iterator to all the nodes in the graph.
Definition: LC_Morph_Graph.h:363
#define GALOIS_DIE(...)
Definition: gIO.h:96
bool shouldLock(const galois::MethodFlag g)
Helper function to decide if the conflict detection lock should be taken.
Definition: libgalois/include/galois/runtime/Context.h:189
void allocateLocal(size_type n)
Allocates using Thread Local memory policy.
Definition: LargeArray.h:220
Class that stores node info (e.g.
Definition: LC_Morph_Graph.h:161
boost::transform_iterator< makeGraphNode, typename Nodes::const_iterator > const_iterator
Constant iterator over nodes.
Definition: LC_Morph_Graph.h:220
Functor that returns pointers to NodeInfo objects given references.
Definition: LC_Morph_Graph.h:181
Struct used to define the UseNumaAlloc template parameter.
Definition: LC_Morph_Graph.h:114
Modify a LC_Graph to have in and out edges.
Definition: LC_InOut_Graph.h:39
EdgeInfo * begin
Beginning of memory for this block.
Definition: LC_Morph_Graph.h:150
runtime::iterable< NoDerefIterator< edge_iterator > > edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Return a range for edges of a node for use by C++ for_each loops.
Definition: LC_Morph_Graph.h:408
iterator end()
Definition: Bag.h:239
EdgeTy & reference
Definition: LazyObject.h:96
edge_iterator edge_end(GraphNode N, MethodFlag GALOIS_UNUSED(mflag)=MethodFlag::WRITE)
Return an iterator to the end of edges of a particular node.
Definition: LC_Morph_Graph.h:399
void allocateInterleaved(size_type n)
[allocatefunctions] Allocates interleaved across NUMA (memory) nodes.
Definition: LargeArray.h:206
Local computation graph that allows addition of nodes (but not removals) if the maximum degree of a n...
Definition: LC_Morph_Graph.h:49
Struct used to define the HasNoLockable template parameter.
Definition: LC_Morph_Graph.h:104
size_t getId(GraphNode N, typename std::enable_if< _Enable >::type *=0)
Get the ID of a graph node if they're enabled in the class.
Definition: LC_Morph_Graph.h:306
Struct used to define the type of file edge data through the template parameter.
Definition: LC_Morph_Graph.h:94
NodeInfo(Args &&...args)
Calls NodeInfoBase constructor.
Definition: LC_Morph_Graph.h:177
size_t pagePoolSize()
Definition: PagePool.cpp:50
void allocateFrom(FileGraph &graph, ReadGraphAuxData &aux)
Allocate memory for nodes given a file graph with a particular number of nodes.
Definition: LC_Morph_Graph.h:549
Definition: PerThreadStorage.h:88
edge_data_reference getEdgeData(edge_iterator ni, MethodFlag mflag=MethodFlag::UNPROTECTED)
Get edge data of an edge given an iterator to the edge.
Definition: LC_Morph_Graph.h:344
Linked list structure holding together blocks of memory that stores edges.
Definition: LC_Morph_Graph.h:148
local_iterator local_end()
Return an iterator to the end of the local nodes of the graph.
Definition: LC_Morph_Graph.h:378
edge_iterator edge_begin(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Return an iterator to the first edge of a particular node.
Definition: LC_Morph_Graph.h:385
void acquire(Lockable *lockable, galois::MethodFlag m)
Master function which handles conflict detection used to acquire a lockable thing.
Definition: libgalois/include/galois/runtime/Context.h:218
Large array of objects with proper specialization for void type and supporting various allocation and...
Definition: LargeArray.h:53
internal::NodeInfoBaseTypes< NodeTy,!HasNoLockable &&!HasOutOfLineLockable > NodeInfoTypes
Type of nodes.
Definition: LC_Morph_Graph.h:144
bool operator()(const EdgeInfo &edge)
Given an edge, check if the edge destination matches the node that this functor was constructed with...
Definition: LC_Morph_Graph.h:197
MethodFlag
What should the runtime do when executing a method.
Definition: MethodFlags.h:34
iterator local_iterator
Local iterator is just an iterator.
Definition: LC_Morph_Graph.h:222
NodeInfo * operator()(NodeInfo &data) const
Returns a pointer to the NodeInfo reference passed into this functor.
Definition: LC_Morph_Graph.h:183
void * pagePoolAlloc()
Low level page pool (individual pages, use largeMalloc for large blocks)
Definition: PagePool.cpp:41
EdgeTy & getEdgeData(GraphNode src, GraphNode dst)
Get edge data of an edge between 2 nodes.
Definition: FileGraph.h:241
Struct used to define the type of edge data through the template parameter.
Definition: LC_Morph_Graph.h:84
dst_equals(NodeInfo *d)
Constructor: takes a node to compare edge destinations with.
Definition: LC_Morph_Graph.h:194
void acquireNode(GraphNode, MethodFlag, typename std::enable_if< _A2 >::type *=0)
No-op acquire node when HasNoLockable is true.
Definition: LC_Morph_Graph.h:299
void constructNodesFrom(FileGraph &graph, unsigned tid, unsigned total, ReadGraphAuxData &aux)
Constructs the LCMorphGraph nodes given a FileGraph to construct it from.
Definition: LC_Morph_Graph.h:570
typename EdgeInfo::reference edge_data_reference
Reference type to edge data.
Definition: LC_Morph_Graph.h:212
GraphRange divideByNode(size_t nodeSize, size_t edgeSize, size_t id, size_t total)
Given a division and a total number of divisions, return a range for that particular division to work...
Definition: FileGraph.cpp:480
edge_iterator edge_end(GraphNode N)
Returns the index to the end of global node N's outgoing edges in the outgoing edges array...
Definition: FileGraph.cpp:655
void constructEdgeValue(FileGraph &graph, typename FileGraph::edge_iterator nn, GraphNode src, GraphNode dst, typename std::enable_if<!_A1||_A2 >::type *=0)
Given a FileGraph and an edge in it, add it to the LCMorphGraph.
Definition: LC_Morph_Graph.h:267
Functor: contains an operator to compare the destination of an edge with a particular node...
Definition: LC_Morph_Graph.h:190
node_data_reference getData(const GraphNode &N, MethodFlag mflag=MethodFlag::WRITE)
Get the data of a node N.
Definition: LC_Morph_Graph.h:334
galois::substrate::PerThreadStorage< EdgeHolder * > edgesL
Memory for edges in this graph (memory held in EdgeHolders)
Definition: LC_Morph_Graph.h:232
Graph that mmaps Galois gr files for access.
Definition: FileGraph.h:57
void acquireNode(GraphNode N, MethodFlag mflag, typename std::enable_if< _A1 &&!_A2 >::type *=0)
Acquire a node for the scope in which the function is called.
Definition: LC_Morph_Graph.h:256
edge_iterator addMultiEdge(GraphNode src, GraphNode dst, galois::MethodFlag mflag, Args &&...args)
Construct a new edge for a node.
Definition: LC_Morph_Graph.h:504
NodeInfo * GraphNode
A graph node is a NodeInfo object.
Definition: LC_Morph_Graph.h:202
void constructEdgeValue(FileGraph &, typename FileGraph::edge_iterator, GraphNode src, GraphNode dst, typename std::enable_if< _A1 &&!_A2 >::type *=0)
Given a FileGraph and an edge in it, add it to the LCMorphGraph.
Definition: LC_Morph_Graph.h:289
InputIterator find_if(InputIterator first, InputIterator last, Predicate pred)
Definition: ParallelSTL.h:70
edge_iterator findEdge(GraphNode src, GraphNode dst, galois::MethodFlag mflag=MethodFlag::WRITE)
Finds an edge between 2 nodes and returns the iterator to it if it exists.
Definition: LC_Morph_Graph.h:533
Struct that allows activation of the HasId template parameter Example: using Graph = LC_Morph_Graph::...
Definition: LC_Morph_Graph.h:64
void removeEdge(GraphNode src, edge_iterator dst, galois::MethodFlag mflag=MethodFlag::WRITE)
Remove an edge from the graph.
Definition: LC_Morph_Graph.h:520
Iterator< NodeInfo > iterator
Definition: Bag.h:234
iterator end()
Returns the end of the node iterator. Not thread-safe.
Definition: LC_Morph_Graph.h:368
local_iterator local_end()
Definition: Bag.h:246
NodeTy node_data_type
Type of node data.
Definition: LC_Morph_Graph.h:208
Struct used to define the HasOutOfLineLockable template parameter.
Definition: LC_Morph_Graph.h:124
EdgeHolder * next
Pointer to another block of memory for edges (if it exists).
Definition: LC_Morph_Graph.h:154
const_iterator const_local_iterator
Const local iterator is just an const_iterator.
Definition: LC_Morph_Graph.h:224
EdgeInfo * edge_iterator
Iterator over EdgeInfo objects (edges)
Definition: LC_Morph_Graph.h:214
edge_iterator addEdge(GraphNode src, GraphNode dst, galois::MethodFlag mflag, Args &&...args)
Adds an edge if it doesn't already exist.
Definition: LC_Morph_Graph.h:479