20 #ifndef GALOIS_WORKLIST_STABLEITERATOR_H
21 #define GALOIS_WORKLIST_STABLEITERATOR_H
23 #include "galois/config.h"
38 template <
bool Steal = false,
typename Container = PerSocketChunkFIFO<>,
39 typename Iterator =
int*>
45 template <
typename _T>
53 template <
typename _iterator>
58 template <
bool _steal>
63 template <
typename _container>
80 unsigned int nextVictim;
81 unsigned int numStealFailures;
83 void populateSteal() {
84 if (Steal && localBegin != localEnd) {
85 shared_state& s = stealState.
data;
87 s.stealEnd = localEnd;
89 if (s.stealBegin != s.stealEnd)
96 substrate::PerThreadStorage<state> TLDS;
99 bool doSteal(state& dst, state& src,
bool wait) {
100 shared_state& s = src.stealState.data;
104 }
else if (!s.stealLock.try_lock()) {
107 if (s.stealBegin != s.stealEnd) {
108 dst.localBegin = s.stealBegin;
109 s.stealBegin = dst.localEnd =
111 s.stealAvail = s.stealBegin != s.stealEnd;
113 s.stealLock.unlock();
115 return dst.localBegin != dst.localEnd;
121 if (doSteal(data, data,
true))
122 return *data.localBegin++;
124 if (doSteal(data, *TLDS.
getRemote(data.nextVictim),
false)) {
127 data.populateSteal();
128 return *data.localBegin++;
131 ++data.numStealFailures;
139 template <
typename RangeTy>
142 auto lp = r.local_pair();
143 data.localBegin = lp.first;
144 data.localEnd = lp.second;
146 data.numStealFailures = 0;
147 data.populateSteal();
153 if (data.localBegin != data.localEnd)
154 return *data.localBegin++;
158 if ((item = pop_steal(data)))
160 if ((item = inner.pop()))
163 return pop_steal(data);
169 template <
typename Iter>
Definition: StableIterator.h:59
StableIterator< Steal, _container, Iterator > type
Definition: StableIterator.h:65
T * getLocal()
Definition: PerThreadStorage.h:128
std::iterator_traits< Iterator >::value_type value_type
Definition: StableIterator.h:41
Galois version of boost::optional.
Definition: optional.h:34
StableIterator< _steal, Container, Iterator > type
Definition: StableIterator.h:60
Iterator iterator
Definition: StableIterator.h:42
static unsigned getTID()
Definition: ThreadPool.h:204
void push(Iter b, Iter e)
Definition: StableIterator.h:170
unsigned int activeThreads
Definition: Threads.cpp:26
#define GALOIS_WLCOMPILECHECK(name)
Definition: WLCompileCheck.h:26
Low-overhead worklist when initial range is not invalidated by the operator.
Definition: StableIterator.h:40
StableIterator< Steal, Container, _iterator > type
Definition: StableIterator.h:55
SimpleLock is a spinlock.
Definition: SimpleLock.h:36
void push_initial(const RangeTy &r)
push initial range onto the queue called with the same b and e on each thread
Definition: StableIterator.h:140
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:149
void push(const value_type &val)
Definition: StableIterator.h:167
galois::optional< value_type > pop()
pop a value from the queue.
Definition: StableIterator.h:151
T value_type
Definition: Executor_ParaMeter.h:111
Definition: StableIterator.h:54
T data
Definition: CacheLineStorage.h:33
IterTy split_range(IterTy b, IterTy e)
Finds the midpoint of a range.
Definition: gstl.h:232
Definition: StableIterator.h:64