Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LC_Adaptor_Graph.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_GRAPHS_LC_ADAPTOR_GRAPH_H
21 #define GALOIS_GRAPHS_LC_ADAPTOR_GRAPH_H
22 
23 #include "galois/config.h"
24 #include "galois/graphs/Details.h"
25 #include "galois/LargeArray.h"
26 
27 namespace galois {
28 namespace graphs {
29 
30 template <typename NodeTy, typename EdgeTy, typename DerivedTy,
31  typename GraphNodeTy, typename IteratorTy, typename EdgeIteratorTy,
32  bool HasNoLockable = false>
34  : private internal::OutOfLineLockableFeature<HasNoLockable>,
35  private internal::LocalIteratorFeature<false> {
36 public:
38  template <bool _has_no_lockable>
40  typedef LC_Adaptor_Graph<NodeTy, EdgeTy, DerivedTy, GraphNodeTy, IteratorTy,
41  EdgeIteratorTy, _has_no_lockable>
43  };
44 
45  typedef GraphNodeTy GraphNode;
46  typedef EdgeTy edge_data_type;
47  typedef NodeTy node_data_type;
50  typedef typename internal::NodeInfoBase<NodeTy, false>::reference
52  typedef EdgeIteratorTy edge_iterator;
53  typedef IteratorTy iterator;
56 
57 protected:
58  template <bool _A1 = HasNoLockable>
60  typename std::enable_if<!_A1>::type* = 0) {
61  this->outOfLineAcquire(getId(N), mflag);
62  }
63 
64  template <bool _A1 = HasNoLockable>
66  typename std::enable_if<_A1>::type* = 0) {}
67 
68  const DerivedTy& derived() const {
69  return *static_cast<const DerivedTy*>(this);
70  }
71 
72  DerivedTy& derived() { return *static_cast<DerivedTy*>(this); }
73 
74  size_t getId(GraphNode n) { return derived().get_id(n); }
75 
76 public:
78  MethodFlag mflag = MethodFlag::WRITE) {
79  // galois::runtime::checkWrite(mflag, false);
80  acquireNode(N, mflag);
81  return derived().get_data(N);
82  }
83 
86  MethodFlag GALOIS_UNUSED(mflag) = MethodFlag::UNPROTECTED) {
87  // galois::runtime::checkWrite(mflag, false);
88  return derived().get_edge_data(ni);
89  }
90 
91  GraphNode getEdgeDst(edge_iterator ni) { return derived().get_edge_dst(ni); }
92 
93  uint64_t size() const { return derived().get_size(); }
94  uint64_t sizeEdges() const { return derived().get_size_edges(); }
95 
96  iterator begin() const { return derived().get_begin(); }
97  iterator end() const { return derived().get_end(); }
99  return local_iterator(this->localBegin(size()));
100  }
101  local_iterator local_end() { return local_iterator(this->localEnd(size())); }
102 
104  acquireNode(N, mflag);
105  if (galois::runtime::shouldLock(mflag)) {
106  for (edge_iterator ii = derived().get_edge_begin(N),
107  ee = derived().get_edge_end(N);
108  ii != ee; ++ii) {
109  acquireNode(getEdgeDst(ii), mflag);
110  }
111  }
112  return derived().get_edge_begin(N);
113  }
114 
116  acquireNode(N, mflag);
117  return derived().get_edge_end(N);
118  }
119 
120  internal::EdgesIterator<LC_Adaptor_Graph>
122  return internal::EdgesIterator<LC_Adaptor_Graph>(*this, N, mflag);
123  }
124 };
125 
126 } // namespace graphs
127 } // namespace galois
128 
129 #endif
internal::EdgeInfoBase< void *, EdgeTy >::reference edge_data_reference
Definition: LC_Adaptor_Graph.h:49
internal::NodeInfoBase< NodeTy, false >::reference node_data_reference
Definition: LC_Adaptor_Graph.h:51
iterator const_iterator
Definition: LC_Adaptor_Graph.h:54
DerivedTy & derived()
Definition: LC_Adaptor_Graph.h:72
EdgeIteratorTy edge_iterator
Definition: LC_Adaptor_Graph.h:52
node_data_reference getData(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: LC_Adaptor_Graph.h:77
Definition: LC_Adaptor_Graph.h:33
LC_Adaptor_Graph< NodeTy, EdgeTy, DerivedTy, GraphNodeTy, IteratorTy, EdgeIteratorTy, _has_no_lockable > type
Definition: LC_Adaptor_Graph.h:42
void acquireNode(GraphNode N, MethodFlag mflag, typename std::enable_if<!_A1 >::type *=0)
Definition: LC_Adaptor_Graph.h:59
edge_data_reference getEdgeData(edge_iterator ni, MethodFlag GALOIS_UNUSED(mflag)=MethodFlag::UNPROTECTED)
Definition: LC_Adaptor_Graph.h:85
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
EdgeTy & reference
Definition: LazyObject.h:96
iterator begin() const
Definition: LC_Adaptor_Graph.h:96
uint64_t sizeEdges() const
Definition: LC_Adaptor_Graph.h:94
NodeTy node_data_type
Definition: LC_Adaptor_Graph.h:47
iterator end() const
Definition: LC_Adaptor_Graph.h:97
If true, do not use abstract locks in graph.
Definition: LC_Adaptor_Graph.h:39
MethodFlag
What should the runtime do when executing a method.
Definition: MethodFlags.h:34
IteratorTy iterator
Definition: LC_Adaptor_Graph.h:53
void acquireNode(GraphNode, MethodFlag, typename std::enable_if< _A1 >::type *=0)
Definition: LC_Adaptor_Graph.h:65
const DerivedTy & derived() const
Definition: LC_Adaptor_Graph.h:68
edge_iterator edge_begin(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: LC_Adaptor_Graph.h:103
GraphNode getEdgeDst(edge_iterator ni)
Definition: LC_Adaptor_Graph.h:91
internal::EdgesIterator< LC_Adaptor_Graph > out_edges(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: LC_Adaptor_Graph.h:121
iterator local_iterator
Definition: LC_Adaptor_Graph.h:55
uint64_t size() const
Definition: LC_Adaptor_Graph.h:93
local_iterator local_end()
Definition: LC_Adaptor_Graph.h:101
GraphNodeTy GraphNode
Definition: LC_Adaptor_Graph.h:45
size_t getId(GraphNode n)
Definition: LC_Adaptor_Graph.h:74
edge_iterator edge_end(GraphNode N, MethodFlag mflag=MethodFlag::WRITE)
Definition: LC_Adaptor_Graph.h:115
local_iterator local_begin()
Definition: LC_Adaptor_Graph.h:98
EdgeTy edge_data_type
Definition: LC_Adaptor_Graph.h:46