20 #ifndef GALOIS_RUNTIME_EXECUTOR_FOREACH_H
21 #define GALOIS_RUNTIME_EXECUTOR_FOREACH_H
28 #include "galois/config.h"
51 template <
typename value_type>
65 void basicPolicy(
const Item& item) {
67 unsigned socket = tp.getSocket();
68 queues.getRemote(tp.getLeaderForSocket(socket / 2))->
push(item);
75 void doublePolicy(
const Item& item) {
76 int retries = item.retries - 1;
77 if ((retries & 1) == 1) {
78 queues.getLocal()->push(item);
87 unsigned next = leader + (tid - leader) / 2;
88 queues.getRemote(next)->push(item);
90 queues.getRemote(tp.getLeaderForSocket(socket / 2))->
push(item);
98 void boundedPolicy(
const Item& item) {
99 int retries = item.retries - 1;
101 queues.getLocal()->push(item);
108 unsigned leader = tp.getLeaderForSocket(socket);
109 if (retries < 5 && tid != leader) {
110 unsigned next = leader + (tid - leader) / 2;
111 queues.getRemote(next)->push(item);
113 queues.getRemote(tp.getLeaderForSocket(socket / 2))->
push(item);
120 void eagerPolicy(
const Item& item) { queues.getLocal()->push(item); }
132 Item item = {val, 1};
133 queues.getLocal()->push(item);
137 Item newitem = {item.val, item.retries + 1};
139 basicPolicy(newitem);
141 doublePolicy(newitem);
149 template <
class WorkListTy,
class FunctionTy,
typename ArgsTy>
152 static constexpr
bool needStats = galois::internal::NeedStats<ArgsTy>::value;
153 static constexpr
bool needsPush = !has_trait<no_pushes_tag, ArgsTy>();
154 static constexpr
bool needsAborts = !has_trait<no_conflicts_tag, ArgsTy>();
155 static constexpr
bool needsPia = has_trait<per_iter_alloc_tag, ArgsTy>();
156 static constexpr
bool needsBreak = has_trait<parallel_break_tag, ArgsTy>();
158 needStats && has_trait<more_stats_tag, ArgsTy>();
181 template <
typename WL>
210 wl.push(pb.begin(), pb.end());
221 template <
typename Item>
247 bool didWork =
false;
248 while ((p =
wl.pop())) {
255 template <
unsigned int limit,
typename WL>
257 #ifdef GALOIS_USE_LONGJMP_ABORT
259 while ((!limit || s.
num < limit) && (s.
item = lwl.pop())) {
267 #elif defined(GALOIS_USE_EXCEPTION_ABORT)
269 while ((!limit || s.
num < limit) && (s.
item = lwl.pop())) {
280 template <
unsigned int limit,
typename WL>
283 runQueueDispatch<limit>(tld, lwl, s);
289 return runQueue<0>(tld, *
aborted.getQueue());
293 wl.push(x.begin(), x.end());
299 template <
typename WL>
301 -> decltype(
wl.empty(), bool()) {
305 template <
bool couldAbort,
bool isLeader>
318 std::placeholders::_1));
322 bool didWork =
false;
326 constexpr
int __NUM = (
needsBreak || isLeader) ? 64 : 0;
327 bool b = runQueue<__NUM>(tld,
wl);
328 didWork = b || didWork;
332 didWork = b || didWork;
336 didWork = b || didWork;
341 substrate::asmPause();
365 template <
typename... WArgsTy>
373 template <
typename WArgsTy,
size_t... Is>
375 std::index_sequence<Is...>)
378 template <
typename WArgsTy>
380 std::index_sequence<>)
386 std::make_index_sequence<std::tuple_size<decltype(
387 get_trait_value<wl_tag>(args).args)>::value>{}) {}
389 template <
typename RangeTy>
390 void init(
const RangeTy&) {}
392 template <
typename RangeTy>
397 wl.push_initial(range);
406 if (couldAbort && isLeader)
408 else if (couldAbort && !isLeader)
410 else if (!couldAbort && isLeader)
417 template <
typename WLTy>
419 std::declval<
typename WLTy::template with_iterator<int*>::type>(),
bool()) {
428 template <
typename WLTy,
typename IterTy,
typename Enable =
void>
433 template <
typename WLTy,
typename IterTy>
435 typename std::enable_if<has_with_iterator<WLTy>(0)>
::type> {
436 typedef typename WLTy::template with_iterator<IterTy>::type
type;
440 template <
typename RangeTy,
typename FunctionTy,
typename ArgsTy>
441 void for_each_impl(
const RangeTy& range, FunctionTy&& fn,
const ArgsTy& args) {
446 type ::template retype<value_type>
453 FuncRefType fn_ref = fn;
454 WorkTy W(fn_ref, args);
457 activeThreads, [&W, &range]() { W.initThread(range); }, std::ref(barrier),
465 template <
typename RangeTy,
typename FunctionTy,
typename TupleTy>
466 void for_each_gen(
const RangeTy& r, FunctionTy&& fn,
const TupleTy& tpl) {
467 static_assert(!has_trait<char*, TupleTy>(),
"old loopname");
468 static_assert(!has_trait<char const*, TupleTy>(),
"old loopname");
469 static_assert(!has_trait<bool, TupleTy>(),
"old steal");
473 auto xtpl = std::tuple_cat(
475 std::make_tuple(wl<defaultWL>())));
477 constexpr
bool TIME_IT = has_trait<loopname_tag, decltype(xtpl)>();
ForEachExecutor(T1, FunctionTy f, const ArgsTy &args, const WArgsTy &, std::index_sequence<>)
Definition: Executor_ForEach.h:379
Definition: Executor_ForEach.h:362
unsigned cancelIteration()
Definition: Context.cpp:92
ForEachExecutor(T2, FunctionTy f, const ArgsTy &args, WArgsTy...wargs)
Definition: Executor_ForEach.h:366
virtual void initializeThread()=0
Initializes the per-thread state.
virtual void localTermination(bool workHappened)=0
Process termination locally.
ForEachExecutor(FunctionTy f, const ArgsTy &args)
Definition: Executor_ForEach.h:384
Definition: LoopStatistics.h:31
FunctionTy function
Definition: Executor_ForEach.h:165
PushBufferTy & getPushBuffer()
Definition: UserContextAccess.h:38
ThreadPool & getThreadPool(void)
return a reference to system thread pool
Definition: ThreadPool.cpp:259
void run(unsigned num, Args &&...args)
execute work on all threads a simple wrapper for run
Definition: ThreadPool.h:142
void go()
Definition: Executor_ForEach.h:306
void setThreadContext(SimpleRuntimeContext *n)
used by the parallel code to set up conflict detection per thread
Definition: Context.cpp:31
GALOIS_ATTRIBUTE_NOINLINE bool handleAborts(ThreadLocalData &tld)
Definition: Executor_ForEach.h:288
static unsigned getLeader()
Definition: ThreadPool.h:206
void stop()
Definition: ThreadTimer.h:61
static constexpr bool MORE_STATS
Definition: Executor_ForEach.h:157
void for_each_impl(const RangeTy &range, FunctionTy &&fn, const ArgsTy &args)
Definition: Executor_ForEach.h:441
static constexpr bool needsAborts
Definition: Executor_ForEach.h:154
thread_local std::jmp_buf execFrame
Definition: Context.cpp:29
ThreadLocalData(FunctionTy fn, const char *ln)
Definition: Executor_ForEach.h:175
bool globalTermination() const
Returns whether global termination is detected.
Definition: Termination.h:72
substrate::Barrier & getBarrier(unsigned activeThreads)
Have a pre-instantiated barrier available for use.
Definition: Substrate.cpp:24
void init(const RangeTy &range)
Definition: Executor_ParaMeter.h:409
WLTy type
Definition: Executor_ForEach.h:430
size_t size() const
Definition: gdeque.h:348
substrate::TerminationDetection & term
Definition: Executor_ForEach.h:191
void push(const Item &item)
Definition: Executor_ForEach.h:136
AbortHandler< value_type > aborted
Definition: Executor_ForEach.h:190
Definition: Executor_ForEach.h:173
AbortHandler()
Definition: Executor_ForEach.h:123
void initThread(const RangeTy &) const
Definition: Executor_ParaMeter.h:415
#define GALOIS_ATTRIBUTE_NOINLINE
Definition: CompilerSpecific.h:46
SimpleRuntimeContext ctx
Definition: Executor_ForEach.h:166
typename internal::OperatorReferenceType_impl< T >::type OperatorReferenceType
Definition: OperatorReferenceTypes.h:66
Simple Container Wrapper worklist (not scalable).
Definition: Simple.h:36
ForEachExecutor(T1, FunctionTy f, const ArgsTy &args, const WArgsTy &wlargs, std::index_sequence< Is...>)
Definition: Executor_ForEach.h:374
TerminationDetection & getSystemTermination(unsigned activeThreads)
Definition: Termination.cpp:35
void start()
Definition: ThreadTimer.h:59
Definition: Executor_ForEach.h:163
Returns the type associated with the given trait in a tuple.
Definition: Traits.h:121
WLTy::template with_iterator< IterTy >::type type
Definition: Executor_ForEach.h:436
void commitIteration(ThreadLocalData &tld)
Definition: Executor_ForEach.h:202
constexpr auto has_with_iterator(int) -> decltype(std::declval< typename WLTy::template with_iterator< int * >::type >(), bool())
Definition: Executor_ForEach.h:418
void for_each_gen(const RangeTy &r, FunctionTy &&fn, const TupleTy &tpl)
Normalize arguments to for_each.
Definition: Executor_ForEach.h:466
void resetPushBuffer()
Definition: UserContextAccess.h:39
auto checkEmpty(WL &wl, ThreadLocalData &, int) -> decltype(wl.empty(), bool())
Definition: Executor_ForEach.h:300
bool broke
Definition: Executor_ForEach.h:197
Indicates worklist to use.
Definition: Traits.h:211
SuperTy & data()
Definition: UserContextAccess.h:40
substrate::Barrier & barrier
Definition: Executor_ForEach.h:192
FunctionTy origFunction
Definition: Executor_ForEach.h:195
unsigned int num
Definition: Executor_ForEach.h:183
value_type & value(value_type &val) const
Definition: Executor_ForEach.h:129
PerThreadTimer< MORE_STATS > execTime
Definition: Executor_ForEach.h:200
void inc_pushes(size_t v=1)
Definition: LoopStatistics.h:54
GALOIS_ATTRIBUTE_NOINLINE void abortIteration(const Item &item, ThreadLocalData &tld)
Definition: Executor_ForEach.h:222
static unsigned getTID()
Definition: ThreadPool.h:204
Definition: PerThreadStorage.h:88
static constexpr bool needsPia
Definition: Executor_ForEach.h:155
void startIteration()
Definition: libgalois/include/galois/runtime/Context.h:175
unsigned int activeThreads
Definition: Threads.cpp:26
void setBreakFlag(bool *b)
Definition: UserContextAccess.h:43
Definition: Executor_ForEach.h:182
ConflictFlag
Definition: libgalois/include/galois/runtime/Context.h:41
Definition: Termination.h:39
void fastPushBack(typename UserContextAccess< value_type >::PushBufferTy &x)
Definition: Executor_ForEach.h:292
std::tuple type
Definition: Traits.h:181
static unsigned getSocket()
Definition: ThreadPool.h:207
void doProcess(value_type &val, ThreadLocalData &tld)
Definition: Executor_ForEach.h:236
static constexpr bool needsBreak
Definition: Executor_ForEach.h:156
void operator()(void)
Definition: Executor_ParaMeter.h:417
Definition: Executor_ForEach.h:52
static bool isLeader()
Definition: ThreadPool.h:205
UserContextAccess< value_type > facing
Definition: Executor_ForEach.h:164
void inc_iterations()
Definition: LoopStatistics.h:56
const char * loopname
Definition: Executor_ForEach.h:196
Definition: Executor_ForEach.h:150
WorkListTy::value_type value_type
Definition: Executor_ForEach.h:161
Definition: libgalois/include/galois/runtime/Context.h:135
galois::optional< typename WL::value_type > item
Definition: Executor_ForEach.h:184
PerThreadTimer< MORE_STATS > initTime
Definition: Executor_ForEach.h:199
void push(const value_type &val)
Definition: Executor_ForEach.h:131
bool runQueue(ThreadLocalData &tld, WL &lwl)
Definition: Executor_ForEach.h:281
unsigned getMaxSockets() const
Definition: ThreadPool.h:180
Definition: Executor_ForEach.h:363
bool checkEmpty(WorkListTy &, ThreadLocalData &,...)
Definition: Executor_ForEach.h:297
WorkListTy wl
Definition: Executor_ForEach.h:194
ThreadLocalBasics(FunctionTy fn)
Definition: Executor_ForEach.h:168
void inc_conflicts()
Definition: LoopStatistics.h:58
AbortedList * getQueue()
Definition: Executor_ForEach.h:144
T value_type
Definition: Executor_ParaMeter.h:111
value_type & value(Item &item) const
Definition: Executor_ForEach.h:128
void resetAlloc()
Definition: UserContextAccess.h:37
static constexpr bool needStats
Definition: Executor_ForEach.h:152
void runQueueDispatch(ThreadLocalData &tld, WL &lwl, RunQueueState< WL > &s)
Definition: Executor_ForEach.h:256
Definition: Executor_ForEach.h:429
static constexpr bool needsPush
Definition: Executor_ForEach.h:153
bool runQueueSimple(ThreadLocalData &tld)
Definition: Executor_ForEach.h:245
constexpr auto get_default_trait_values(std::index_sequence<> GALOIS_UNUSED(seq), S GALOIS_UNUSED(source), T GALOIS_UNUSED(tags), D GALOIS_UNUSED(defaults))
Returns a tuple that has an element from defaults[i] for every type from tags[i] missing in source...
Definition: Traits.h:148
unsigned commitIteration()
Definition: Context.cpp:77
typename GenericWL::template retype< T > WorkListTy
Definition: Executor_ParaMeter.h:113
void setFastPushBack(FastPushBack f)
Definition: UserContextAccess.h:42