20 #ifndef GALOIS_GRAPHS_OCGRAPH_H
21 #define GALOIS_GRAPHS_OCGRAPH_H
24 #include <type_traits>
26 #include <boost/iterator/counting_iterator.hpp>
27 #include <boost/utility.hpp>
29 #include "galois/config.h"
42 template <
typename Graph>
44 typedef typename Graph::segment_type segment_type;
69 return graph.getData(N, mflag);
74 return graph.getEdgeData(segment, ni, mflag);
78 return graph.getEdgeDst(segment, ni);
81 size_t size()
const {
return graph.size(); }
82 size_t sizeEdges()
const {
return graph.sizeEdges(); }
91 return graph.edge_begin(segment, N, mflag);
95 return graph.edge_end(segment, N, mflag);
100 return internal::make_no_deref_range(
edge_begin(N, mflag),
106 return edges(N, mflag);
111 return graph.getInEdgeData(segment, ni, mflag);
115 return graph.getInEdgeDst(segment, ni);
120 return graph.in_edge_begin(segment, N, mflag);
125 return graph.in_edge_end(segment, N, mflag);
128 internal::InEdgesIterator<BindSegmentGraph>
130 return internal::InEdgesIterator<BindSegmentGraph>(*
this, N, mflag);
142 typedef boost::counting_iterator<uint32_t>
iterator;
146 template <
typename EdgeTy>
153 typedef off64_t offset_t;
155 typedef off_t offset_t;
166 size_t m_sizeof_data;
169 void load(
int fd, offset_t offset,
size_t begin,
size_t len,
173 Block() : m_mapping(0) {}
175 char*
get(
size_t index)
const {
176 char* p = m_data + (m_sizeof_data * (index - m_begin));
177 assert(p < reinterpret_cast<char*>(m_mapping) + m_length);
178 assert(m_mapping <= p);
188 Segment() : loaded(false) {}
208 : masterMapping(0), masterFD(-1), numEdges(0), numNodes(0), outIdx(0) {}
213 size_t size()
const {
return numNodes; }
222 template <
typename EdgeTy>
225 typename std::enable_if<!std::is_same<void, EdgeTy>::value>::type* = 0) {
226 EdgeTy* p =
reinterpret_cast<EdgeTy*
>(s.edgeData.get(*it));
230 template <
typename EdgeTy>
233 typename std::enable_if<std::is_same<void, EdgeTy>::value>::type* = 0) {
238 uint32_t* p =
reinterpret_cast<uint32_t*
>(s.outs.get(*it));
254 void fromFile(
const std::string& fname);
259 template <
typename NodeTy,
typename EdgeTy,
bool HasNoLockable =
false,
261 bool HasOutOfLineLockable =
false>
263 :
private internal::LocalIteratorFeature<false>,
264 private internal::OutOfLineLockableFeature<HasOutOfLineLockable &&
267 template <
bool _has_
id>
272 template <
typename _node_data>
275 HasOutOfLineLockable>
279 template <
typename _edge_data>
282 HasOutOfLineLockable>
286 template <
bool _has_no_lockable>
289 HasOutOfLineLockable>
293 template <
bool _use_numa_alloc>
298 template <
bool _has_out_of_line_lockable>
301 _has_out_of_line_lockable>
308 typedef internal::NodeInfoBase<NodeTy,
309 !HasNoLockable && !HasOutOfLineLockable>
328 typedef typename OCFileGraph::template EdgeReference<EdgeTy>::type
339 template <
typename,
typename,
bool,
bool>
348 bool loaded()
const {
return out.loaded; }
350 explicit operator bool() {
return nodeBegin != nodeEnd; }
351 size_t size()
const {
return std::distance(nodeBegin, nodeEnd); }
353 return *nodeBegin <= n && n < *nodeEnd;
360 segment_type computeSegment(
size_t startNode,
size_t numEdges) {
367 std::advance(outStart, startNode);
368 if (outStart == outEnd) {
369 ret.nodeBegin = ret.nodeEnd =
iterator(0);
372 edge_offset_iterator outNext =
373 std::lower_bound(outStart + 1, outEnd, *outStart + numEdges);
374 ptrdiff_t outNodes = std::distance(outStart, outNext);
378 std::advance(inStart, startNode);
379 edge_offset_iterator inNext =
380 std::lower_bound(inStart + 1, inEnd, *inStart + numEdges);
381 ptrdiff_t inNodes = std::distance(inStart, inNext);
383 ptrdiff_t nodes =
std::min(outNodes, inNodes);
385 ret.nodeBegin =
iterator(startNode);
386 ret.nodeEnd =
iterator(startNode + nodes);
390 void load(segment_type& seg,
size_t sizeof_data) {
392 outGraph.
edge_end(seg.nodeEnd[-1]), sizeof_data);
393 if (inGraph != &outGraph)
395 inGraph->
edge_end(seg.nodeEnd[-1]), sizeof_data);
400 template <
bool _A1 = HasNoLockable,
bool _A2 = HasOutOfLineLockable>
402 typename std::enable_if<!_A1 && !_A2>::type* = 0) {
406 template <
bool _A1 = HasOutOfLineLockable,
bool _A2 = HasNoLockable>
408 typename std::enable_if<_A1 && !_A2>::type* = 0) {
412 template <
bool _A1 = HasOutOfLineLockable,
bool _A2 = HasNoLockable>
414 typename std::enable_if<_A2>::type* = 0) {}
419 outGraph.
unload(memorySegment->out);
420 if (inGraph != &outGraph)
421 inGraph->
unload(memorySegment->in);
437 return *memorySegment;
439 return computeSegment(0, edges);
446 return computeSegment(*cur.nodeEnd, edges);
461 if (inGraph != &outGraph)
471 NodeInfo& NI = nodeData[N];
472 acquireNode(N, mflag);
480 return outGraph.
getEdgeData<EdgeTy>(segment.out, ni);
487 size_t size()
const {
return numNodes; }
508 acquireNode(N, mflag);
512 acquireNode(outGraph.
getEdgeDst(segment.out, *ii), mflag);
520 acquireNode(N, mflag);
528 return inGraph->
getEdgeData<EdgeTy>(segment.in, ni);
537 acquireNode(N, mflag);
542 acquireNode(inGraph->
getEdgeDst(segment.in, ii), mflag);
550 acquireNode(N, mflag);
561 numNodes = outGraph.
size();
563 nodeData.
create(numNodes);
565 this->outOfLineAllocateInterleaved(numNodes);
566 for (
size_t i = 0; i < numNodes; ++i)
567 this->outOfLineConstructAt(i);
570 void createFrom(
const std::string& fname,
const std::string& transpose) {
573 numNodes = outGraph.
size();
574 if (numNodes != inGraphStorage.
size())
576 "graph does not have the same number of nodes as its transpose");
578 nodeData.
create(numNodes);
579 inGraph = &inGraphStorage;
580 this->outOfLineAllocateInterleaved(numNodes);
581 for (
size_t i = 0; i < numNodes; ++i)
582 this->outOfLineConstructAt(i);
586 template <
typename GraphTy,
typename... Args>
589 graph.createFrom(std::forward<Args>(args)...);
Definition: OCGraph.h:287
local_iterator local_begin() const
Definition: OCGraph.h:87
EdgeReference< EdgeTy >::type getEdgeData(const segment_type &, edge_iterator, typename std::enable_if< std::is_same< void, EdgeTy >::value >::type *=0)
Definition: OCGraph.h:231
void unload(segment_type &seg)
Definition: OCGraph.h:456
OCFileGraph::iterator iterator
Definition: OCGraph.h:333
edge_data_reference getEdgeData(edge_iterator ni, MethodFlag mflag=MethodFlag::UNPROTECTED)
Definition: OCGraph.h:72
Definition: OCGraph.h:280
size_t size() const
Definition: OCGraph.h:81
size_t sizeEdges() const
Definition: OCGraph.h:82
Definition: OCGraph.h:147
iterator end() const
Definition: OCGraph.h:212
NodeTy node_data_type
Definition: OCGraph.h:327
iterator begin() const
Definition: OCGraph.h:211
Graph::edge_iterator edge_iterator
Definition: OCGraph.h:60
Definition: OCGraph.h:257
EdgeTy edge_data_type
Definition: OCGraph.h:325
Single (uninitialized) object with specialization for void type.
Definition: LazyObject.h:71
iterator end() const
Definition: OCGraph.h:491
Graph::const_local_iterator const_local_iterator
Definition: OCGraph.h:65
size_t idFromNode(GraphNode N)
Definition: OCGraph.h:133
~OCImmutableEdgeGraph()
Definition: OCGraph.h:417
EdgeReference< EdgeTy >::type getEdgeData(const segment_type &s, edge_iterator it, typename std::enable_if<!std::is_same< void, EdgeTy >::value >::type *=0)
Definition: OCGraph.h:223
OCFileGraph::edge_iterator edge_iterator
Definition: OCGraph.h:331
NodeInfo::reference node_data_reference
Definition: OCGraph.h:330
Definition: OCGraph.h:273
OCImmutableEdgeGraph< _node_data, EdgeTy, HasNoLockable, HasOutOfLineLockable > type
Definition: OCGraph.h:276
void keepInMemory()
Definition: OCGraph.h:425
GraphNode getInEdgeDst(in_edge_iterator ni)
Definition: OCGraph.h:114
iterator end(const segment_type &cur)
Definition: OCGraph.h:466
Segment segment_type
Definition: OCGraph.h:205
OCImmutableEdgeGraph type
Definition: OCGraph.h:295
Definition: OCGraph.h:268
iterator end() const
Definition: OCGraph.h:85
edge_data_reference getInEdgeData(const segment_type &segment, edge_iterator ni, MethodFlag GALOIS_UNUSED(mflag)=MethodFlag::UNPROTECTED)
Definition: OCGraph.h:525
void setSegment(const segment_type &s)
Definition: OCGraph.h:53
void create(size_type n, Args &&...args)
Allocate and construct.
Definition: LargeArray.h:266
OCFileGraph::template EdgeReference< EdgeTy >::type edge_data_reference
Definition: OCGraph.h:329
void readGraphDispatch(GraphTy &graph, read_oc_immutable_edge_graph_tag, Args &&...args)
Definition: OCGraph.h:587
iterator begin() const
Definition: OCGraph.h:84
edge_data_type file_edge_data_type
Definition: OCGraph.h:326
Definition: Iterable.h:36
bool loaded() const
Returns true if segment has been loaded into memory.
Definition: OCGraph.h:348
node_data_reference getData(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:468
edge_offset_iterator edge_offset_end() const
Definition: OCGraph.h:220
#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
iterator begin(const segment_type &cur)
Definition: OCGraph.h:465
void createFrom(const std::string &fname)
Assumes that the graph is symmetric.
Definition: OCGraph.h:559
in_edge_iterator in_edge_begin(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:118
runtime::iterable< NoDerefIterator< edge_iterator > > edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:99
void unload(segment_type &s)
Definition: OCGraph.h:242
read_oc_immutable_edge_graph_tag read_tag
Definition: OCGraph.h:305
const_local_iterator local_begin() const
Definition: OCGraph.h:493
Galois version of boost::optional.
Definition: optional.h:34
size_t sizeEdges() const
Definition: OCGraph.h:488
in_edge_iterator in_edge_end(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:123
local_iterator const_local_iterator
Definition: OCGraph.h:336
OCImmutableEdgeGraph type
Definition: OCGraph.h:269
edge_offset_iterator edge_offset_begin() const
Definition: OCGraph.h:219
Graph::GraphNode GraphNode
Definition: OCGraph.h:55
size_t size() const
Definition: OCGraph.h:213
void createFrom(const std::string &fname, const std::string &transpose)
Definition: OCGraph.h:570
OCFileGraph()
Definition: OCGraph.h:207
void load(segment_type &s, edge_iterator begin, edge_iterator end, size_t sizeof_data)
Definition: OCFileGraph.cpp:105
edge_iterator edge_end(GraphNode n) const
Definition: OCGraph.h:218
Graph::iterator iterator
Definition: OCGraph.h:62
iterator const_iterator
Definition: OCGraph.h:334
size_t size() const
Definition: OCGraph.h:487
edge_data_reference getEdgeData(const segment_type &segment, edge_iterator ni, MethodFlag GALOIS_UNUSED(mflag)=MethodFlag::UNPROTECTED)
Definition: OCGraph.h:477
segment_type nextSegment(size_t edges)
Returns a segment starting from the beginning of the graph with either (1) some number of nodes with ...
Definition: OCGraph.h:435
void fromFile(const std::string &fname)
Definition: OCFileGraph.cpp:136
edge_iterator edge_begin(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:90
size_t size() const
Definition: OCGraph.h:351
local_iterator local_end()
Definition: OCGraph.h:502
Graph::local_iterator local_iterator
Definition: OCGraph.h:64
edge_iterator edge_end(const segment_type &, GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:518
boost::counting_iterator< uint64_t > edge_iterator
Definition: OCGraph.h:143
GraphNode getEdgeDst(const segment_type &segment, edge_iterator ni)
Definition: OCGraph.h:483
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
MethodFlag
What should the runtime do when executing a method.
Definition: MethodFlags.h:34
Graph::const_iterator const_iterator
Definition: OCGraph.h:63
iterator begin() const
Definition: OCGraph.h:490
OCImmutableEdgeGraph< NodeTy, EdgeTy, _has_no_lockable, HasOutOfLineLockable > type
Definition: OCGraph.h:290
GraphNode getInEdgeDst(const segment_type &segment, in_edge_iterator ni)
Definition: OCGraph.h:531
local_iterator local_begin()
Definition: OCGraph.h:499
Graph::in_edge_iterator in_edge_iterator
Definition: OCGraph.h:61
Definition: OCGraph.h:338
edge_data_reference getInEdgeData(edge_iterator ni, MethodFlag mflag=MethodFlag::UNPROTECTED)
Definition: OCGraph.h:110
const_local_iterator local_end() const
Definition: OCGraph.h:496
unsigned int node_data_type
Definition: EdgeHostDecls.h:34
Graph::node_data_type node_data_type
Definition: OCGraph.h:57
const Ty min(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:70
OCImmutableEdgeGraph< NodeTy, EdgeTy, HasNoLockable, _has_out_of_line_lockable > type
Definition: OCGraph.h:302
boost::counting_iterator< GraphNode > local_iterator
Definition: OCGraph.h:335
OCImmutableEdgeGraph< NodeTy, _edge_data, HasNoLockable, HasOutOfLineLockable > type
Definition: OCGraph.h:283
Like FileGraph but allows partial loading of the graph.
Definition: OCGraph.h:139
LazyObject< EdgeTy >::reference type
Definition: OCGraph.h:148
edge_iterator in_edge_iterator
Definition: OCGraph.h:332
edge_iterator edge_begin(const segment_type &segment, GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:506
GraphNode nodeFromId(size_t N)
Definition: OCGraph.h:556
size_t idFromNode(GraphNode N)
Definition: OCGraph.h:554
runtime::iterable< NoDerefIterator< edge_iterator > > out_edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:105
node_data_reference getData(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:67
boost::counting_iterator< uint32_t > iterator
Definition: OCGraph.h:142
Definition: OCGraph.h:262
GraphNode getEdgeDst(edge_iterator ni)
Definition: OCGraph.h:77
void load(segment_type &seg)
Definition: OCGraph.h:449
bool containsNode(size_t n) const
Definition: OCGraph.h:352
Graph::edge_data_reference edge_data_reference
Definition: OCGraph.h:58
edge_iterator edge_begin(GraphNode n) const
Definition: OCGraph.h:215
GraphNode nodeFromId(size_t N)
Definition: OCGraph.h:135
GraphNode getEdgeDst(const segment_type &s, edge_iterator it)
Definition: OCGraph.h:237
Graph::edge_data_type edge_data_type
Definition: OCGraph.h:56
uint32_t GraphNode
Definition: OCGraph.h:141
Binds the segment parameter of an out-of-core graph so that it can be used in place of a non out-of-c...
Definition: OCGraph.h:43
int tt_is_segmented
Definition: OCGraph.h:322
unsigned edge_data_type
Definition: EdgeHostDecls.h:35
Definition: OCGraph.h:299
edge_iterator edge_end(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:94
~OCFileGraph()
Definition: OCFileGraph.cpp:59
OCFileGraph::GraphNode GraphNode
Definition: OCGraph.h:324
size_t sizeEdges() const
Definition: OCGraph.h:214
local_iterator local_end() const
Definition: OCGraph.h:88
in_edge_iterator in_edge_begin(const segment_type &segment, GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:535
internal::InEdgesIterator< BindSegmentGraph > in_edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:129
uint64_t * edge_offset_iterator
Definition: OCGraph.h:144
Graph::node_data_reference node_data_reference
Definition: OCGraph.h:59
BindSegmentGraph(Graph &g)
Definition: OCGraph.h:50
in_edge_iterator in_edge_end(const segment_type &, GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: OCGraph.h:548
segment_type nextSegment(const segment_type &cur, size_t edges)
Returns the next segment after cur.
Definition: OCGraph.h:445
BindSegmentGraph(Graph &g, segment_type s)
Definition: OCGraph.h:51
Definition: OCGraph.h:294