20 #ifndef GALOIS_GRAPHS_DETAILS_H
21 #define GALOIS_GRAPHS_DETAILS_H
24 #include <boost/mpl/if.hpp>
26 #include "galois/config.h"
37 namespace galois::graphs {
46 namespace galois::graphs::internal {
48 template <
typename,
typename,
typename,
typename,
typename>
49 struct EdgeSortReference;
52 namespace galois::graphs {
55 template <
typename GraphNode,
typename EdgeTy>
57 template <
typename,
typename,
typename,
typename,
typename>
70 template <
typename ER>
72 ref.initialize(*
this);
78 namespace galois::graphs::internal {
80 template <
bool Enable>
81 class LocalIteratorFeature {
82 typedef std::pair<uint64_t, uint64_t> Range;
83 substrate::PerThreadStorage<Range> localIterators;
86 uint64_t localBegin(uint64_t numNodes)
const {
87 return std::min(localIterators.getLocal()->first, numNodes);
90 uint64_t localEnd(uint64_t numNodes)
const {
91 return std::min(localIterators.getLocal()->second, numNodes);
94 void setLocalRange(uint64_t begin, uint64_t end) {
95 Range& r = *localIterators.getLocal();
102 struct LocalIteratorFeature<false> {
103 uint64_t localBegin(uint64_t numNodes)
const {
106 uint64_t begin = (numNodes + num - 1) / num *
id;
110 uint64_t localEnd(uint64_t numNodes)
const {
113 uint64_t end = (numNodes + num - 1) / num * (
id + 1);
117 void setLocalRange(uint64_t, uint64_t) {}
121 template <
typename GraphNode,
typename EdgeIndex,
typename EdgeDst,
122 typename EdgeData,
typename GraphNodeConverter>
123 struct EdgeSortReference {
124 typedef typename EdgeData::raw_value_type EdgeTy;
129 EdgeSortReference(EdgeIndex x, EdgeDst* dsts, EdgeData* data)
130 : at(x), edgeDst(dsts), edgeData(data) {}
136 EdgeSortReference(EdgeSortReference
const& x) {
139 edgeData = x.edgeData;
142 EdgeSortReference operator=(
const EdgeSortValue<GraphNode, EdgeTy>& x) {
143 edgeDst->set(at, x.rawDst);
144 edgeData->set(at, x.get());
148 EdgeSortReference operator=(
const EdgeSortReference& x) {
149 edgeDst->set(at, edgeDst->at(x.at));
150 edgeData->set(at, edgeData->at(x.at));
154 EdgeSortValue<GraphNode, EdgeTy> operator*()
const {
155 return EdgeSortValue<GraphNode, EdgeTy>(
156 GraphNodeConverter()(edgeDst->at(at)), edgeDst->at(at),
160 void initialize(EdgeSortValue<GraphNode, EdgeTy>& value)
const {
168 template <
typename EdgeSortValueTy,
typename CompTy>
169 struct EdgeSortCompWrapper {
172 EdgeSortCompWrapper(
const CompTy& c) : comp(c) {}
173 bool operator()(
const EdgeSortValueTy& a,
const EdgeSortValueTy& b)
const {
174 return comp(a.get(), b.get());
179 template <
typename T>
198 template <
typename GraphNode,
typename EdgeIndex,
typename EdgeDst,
199 typename EdgeData,
typename GraphNodeConverter = Identity>
200 class EdgeSortIterator
201 :
public boost::iterator_facade<
202 EdgeSortIterator<GraphNode, EdgeIndex, EdgeDst, EdgeData,
204 EdgeSortValue<GraphNode, typename EdgeData::raw_value_type>,
205 boost::random_access_traversal_tag,
206 EdgeSortReference<GraphNode, EdgeIndex, EdgeDst, EdgeData,
207 GraphNodeConverter>> {
208 typedef EdgeSortIterator<GraphNode, EdgeIndex, EdgeDst, EdgeData,
211 typedef EdgeSortReference<GraphNode, EdgeIndex, EdgeDst, EdgeData,
220 EdgeSortIterator() : at(0) {}
221 EdgeSortIterator(EdgeIndex x, EdgeDst* dsts, EdgeData* data)
222 : at(x), edgeDst(dsts), edgeData(data) {}
225 friend class boost::iterator_core_access;
227 bool equal(
const Self& other)
const {
return at == other.at; }
228 Reference dereference()
const {
return Reference(at, edgeDst, edgeData); }
229 ptrdiff_t distance_to(
const Self& other)
const {
230 return other.at - (ptrdiff_t)at;
232 void increment() { ++at; }
233 void decrement() { --at; }
234 void advance(ptrdiff_t n) { at += n; }
237 template <
typename IdTy>
242 IdTy& getId() {
return id; }
243 void setId(
size_t n) {
id = n; }
247 class IntrusiveId<void> {
249 char getId() {
return 0; }
250 void setId(
size_t) {}
257 template <
typename NodeTy,
bool HasLockable>
258 struct NodeInfoBaseTypes {
259 typedef NodeTy& reference;
262 template <
bool HasLockable>
263 struct NodeInfoBaseTypes<void, HasLockable> {
264 typedef void* reference;
268 template <
typename NodeTy,
bool HasLockable>
270 :
public boost::mpl::if_c<HasLockable, galois::runtime::Lockable,
272 public NodeInfoBaseTypes<NodeTy, HasLockable> {
276 template <
typename... Args>
277 NodeInfoBase(Args&&... args) : data(std::forward<Args>(args)...) {}
279 typename NodeInfoBase::reference getData() {
return data; }
282 template <
bool HasLockable>
283 struct NodeInfoBase<void, HasLockable>
284 :
public boost::mpl::if_c<HasLockable, galois::runtime::Lockable,
286 public NodeInfoBaseTypes<void, HasLockable> {
287 typename NodeInfoBase::reference getData() {
return 0; }
290 template <
bool Enable>
291 class OutOfLineLockableFeature {
292 typedef NodeInfoBase<void, true> OutOfLineLock;
293 LargeArray<OutOfLineLock> outOfLineLocks;
296 struct size_of_out_of_line {
297 static const size_t value =
sizeof(OutOfLineLock);
300 void outOfLineAcquire(
size_t n,
MethodFlag mflag) {
303 void outOfLineAllocateLocal(
size_t numNodes) {
304 outOfLineLocks.allocateLocal(numNodes);
306 void outOfLineAllocateInterleaved(
size_t numNodes) {
307 outOfLineLocks.allocateInterleaved(numNodes);
309 void outOfLineAllocateBlocked(
size_t numNodes) {
310 outOfLineLocks.allocateBlocked(numNodes);
312 void outOfLineAllocateFloating(
size_t numNodes) {
313 outOfLineLocks.allocateFloating(numNodes);
316 template <
typename RangeArrayType>
317 void outOfLineAllocateSpecified(
size_t n, RangeArrayType threadRanges) {
318 outOfLineLocks.allocateSpecified(n, threadRanges);
321 void outOfLineConstructAt(
size_t n) { outOfLineLocks.constructAt(n); }
325 class OutOfLineLockableFeature<false> {
327 struct size_of_out_of_line {
328 static const size_t value = 0;
331 void outOfLineAllocateLocal(
size_t) {}
332 void outOfLineAllocateInterleaved(
size_t) {}
333 void outOfLineAllocateBlocked(
size_t) {}
334 void outOfLineAllocateFloating(
size_t) {}
335 void outOfLineConstructAt(
size_t) {}
336 template <
typename RangeArrayType>
337 void outOfLineAllocateSpecified(
size_t, RangeArrayType) {}
341 template <
typename NodeInfoPtrTy,
typename EdgeTy>
342 struct EdgeInfoBase :
public LazyObject<EdgeTy> {
350 template <
typename GraphTy>
351 class EdgesIterator {
352 typename GraphTy::edge_iterator ii, ee;
355 typedef NoDerefIterator<typename GraphTy::edge_iterator> iterator;
357 EdgesIterator(GraphTy& g,
typename GraphTy::GraphNode n,
MethodFlag f)
358 : ii(g.edge_begin(n, f)), ee(g.edge_end(n, f)) {}
359 EdgesIterator(
typename GraphTy::edge_iterator _ii,
360 typename GraphTy::edge_iterator _ee)
361 : ii(_ii), ee(_ee) {}
367 template <
typename ItTy>
368 runtime::iterable<NoDerefIterator<ItTy>> make_no_deref_range(ItTy ii, ItTy ee) {
377 template <
typename GraphTy>
378 class InEdgesIterator {
380 typename GraphTy::GraphNode n;
384 typedef NoDerefIterator<typename GraphTy::in_edge_iterator> iterator;
386 InEdgesIterator(GraphTy& g,
typename GraphTy::GraphNode n,
MethodFlag f)
387 : g(g), n(n), flag(f) {}
393 template <
typename GraphTy>
394 class EdgesWithNoFlagIterator {
396 typename GraphTy::GraphNode n;
399 typedef NoDerefIterator<typename GraphTy::edge_iterator> iterator;
401 EdgesWithNoFlagIterator(GraphTy& g,
typename GraphTy::GraphNode n)
408 template <
typename A,
typename B,
typename C,
typename D,
typename E>
409 void swap(EdgeSortReference<A, B, C, D, E> a,
410 EdgeSortReference<A, B, C, D, E> b) {
unsigned int getActiveThreads() noexcept
Returns the number of threads in use.
Definition: Threads.cpp:37
StrictObject< EdgeTy > Super
Definition: Details.h:64
Single object with specialization for void type.
Definition: LazyObject.h:37
friend struct internal::EdgeSortReference
Definition: Details.h:58
EdgeTy value_type
Definition: LazyObject.h:41
static unsigned getTID()
Definition: ThreadPool.h:204
Proxy object for internal EdgeSortReference.
Definition: Details.h:56
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
GraphNode dst
Definition: Details.h:63
void operator()(void)
Definition: Executor_ParaMeter.h:417
const Ty min(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:70
NoDerefIterator< Iterator > make_no_deref_iterator(Iterator it)
Convenience function to create NoDerefIterator.
Definition: NoDerefIterator.h:48
EdgeSortValue(const ER &ref)
Definition: Details.h:71
EdgeSortValue(GraphNode d, GraphNode rd, const value_type &v)
Definition: Details.h:67
Super::value_type value_type
Definition: Details.h:65