20 #ifndef GALOIS_PERTHREADCONTAINER_H
21 #define GALOIS_PERTHREADCONTAINER_H
32 #include <boost/iterator/counting_iterator.hpp>
33 #include <boost/iterator/iterator_facade.hpp>
34 #include <boost/iterator/transform_iterator.hpp>
36 #include "galois/config.h"
53 enum GlobalPos { GLOBAL_BEGIN, GLOBAL_END };
55 #define ADAPTOR_BASED_OUTER_ITER
59 #ifdef ADAPTOR_BASED_OUTER_ITER
61 template <
typename PerThrdCont>
63 :
public std::unary_function<unsigned,
64 typename PerThrdCont::container_type&> {
65 typedef typename PerThrdCont::container_type Ret_ty;
69 WLindexer() :
wl(NULL) {}
71 WLindexer(PerThrdCont& _wl) :
wl(&_wl) {}
75 assert(i < wl->numRows());
76 return const_cast<Ret_ty&
>(
wl->get(i));
80 template <
typename PerThrdCont>
82 typedef typename boost::transform_iterator<WLindexer<PerThrdCont>,
83 boost::counting_iterator<unsigned>>
85 typedef typename std::reverse_iterator<OuterIter> RvrsOuterIter;
88 template <
typename PerThrdCont>
89 typename TypeFactory<PerThrdCont>::OuterIter make_outer_begin(PerThrdCont&
wl) {
90 return boost::make_transform_iterator(boost::counting_iterator<unsigned>(0),
91 WLindexer<PerThrdCont>(wl));
94 template <
typename PerThrdCont>
95 typename TypeFactory<PerThrdCont>::OuterIter make_outer_end(PerThrdCont& wl) {
96 return boost::make_transform_iterator(
97 boost::counting_iterator<unsigned>(wl.numRows()),
98 WLindexer<PerThrdCont>(wl));
101 template <
typename PerThrdCont>
102 typename TypeFactory<PerThrdCont>::RvrsOuterIter
103 make_outer_rbegin(PerThrdCont& wl) {
104 return typename TypeFactory<PerThrdCont>::RvrsOuterIter(make_outer_end(wl));
107 template <
typename PerThrdCont>
108 typename TypeFactory<PerThrdCont>::RvrsOuterIter
109 make_outer_rend(PerThrdCont& wl) {
110 return typename TypeFactory<PerThrdCont>::RvrsOuterIter(make_outer_begin(wl));
115 template <
typename PerThrdCont>
116 class OuterPerThreadWLIter
117 :
public boost::iterator_facade<OuterPerThreadWLIter<PerThrdCont>,
118 typename PerThrdCont::container_type,
119 boost::random_access_traversal_tag> {
121 using container_type =
typename PerThrdCont::container_type;
122 using Diff_ty = ptrdiff_t;
124 friend class boost::iterator_core_access;
126 PerThrdCont* workList;
131 void assertInRange()
const {
132 assert((row >= 0) && (row < workList->numRows()));
140 container_type& getWL()
const {
142 return (*workList)[row];
146 OuterPerThreadWLIter() : workList(NULL), row(0) {}
148 OuterPerThreadWLIter(PerThrdCont& wl,
const GlobalPos& pos)
149 : workList(&wl), row(0) {
163 container_type& dereference(
void)
const {
return getWL(); }
169 void increment(
void) { ++row; }
171 void decrement(
void) { --row; }
173 bool equal(
const OuterPerThreadWLIter& that)
const {
174 assert(this->workList == that.workList);
175 return this->row == that.row;
178 void advance(ptrdiff_t n) { row += n; }
180 Diff_ty distance_to(
const OuterPerThreadWLIter& that)
const {
181 assert(this->workList == that.workList);
182 return that.row - this->row;
186 template <
typename PerThrdCont>
187 OuterPerThreadWLIter<PerThrdCont> make_outer_begin(PerThrdCont& wl) {
188 return OuterPerThreadWLIter<PerThrdCont>(
wl, GLOBAL_BEGIN);
191 template <
typename PerThrdCont>
192 OuterPerThreadWLIter<PerThrdCont> make_outer_end(PerThrdCont& wl) {
193 return OuterPerThreadWLIter<PerThrdCont>(
wl, GLOBAL_END);
196 template <
typename PerThrdCont>
197 std::reverse_iterator<OuterPerThreadWLIter<PerThrdCont>>
198 make_outer_rbegin(PerThrdCont& wl) {
199 typedef typename std::reverse_iterator<OuterPerThreadWLIter<PerThrdCont>>
201 return Ret_ty(make_outer_end(wl));
204 template <
typename PerThrdCont>
205 std::reverse_iterator<OuterPerThreadWLIter<PerThrdCont>>
206 make_outer_rend(PerThrdCont& wl) {
207 typedef typename std::reverse_iterator<OuterPerThreadWLIter<PerThrdCont>>
209 return Ret_ty(make_outer_begin(wl));
216 template <
typename Cont_tp>
222 typedef typename container_type::pointer
pointer;
228 typedef typename container_type::const_reverse_iterator
233 #ifdef ADAPTOR_BASED_OUTER_ITER
234 typedef typename TypeFactory<This_ty>::OuterIter
OuterIter;
237 typedef OuterPerThreadWLIter<This_ty>
OuterIter;
238 typedef typename std::reverse_iterator<OuterIter>
RvrsOuterIter;
243 OuterIter,
typename container_type::const_iterator>::type
246 RvrsOuterIter,
typename container_type::reverse_iterator>::type
249 RvrsOuterIter,
typename container_type::const_reverse_iterator>::type
262 std::vector<container_type*> v;
269 return getRemote (galois::runtime::LL::getTID ());
273 assert (i < v.size ());
277 size_t size ()
const {
return galois::runtime::LL::getMaxThreads(); }
283 PerThrdCont_ty perThrdCont;
286 for (
unsigned i = 0; i < perThrdCont.
size(); ++i) {
294 for (
unsigned i = 0; i < perThrdCont.
size(); ++i) {
299 template <
typename... Args>
301 for (
unsigned i = 0; i < perThrdCont.
size(); ++i) {
331 make_outer_end(*
this));
336 make_outer_end(*
this));
358 make_outer_end(*
this));
363 make_outer_end(*
this));
368 make_outer_rend(*
this));
373 make_outer_rend(*
this));
382 make_outer_rend(*
this));
387 make_outer_rend(*
this));
409 for (
unsigned i = 0; i < perThrdCont.
size(); ++i) {
425 [
this](
const unsigned,
const unsigned) {
get().clear(); },
431 for (
unsigned i = 0; i < perThrdCont.
size(); ++i) {
432 res = res &&
get(i).empty();
438 template <
typename Range,
typename Ret>
441 &container_type::push_back) {
453 template <
typename T>
457 typedef typename gstl::template Pow2Alloc<T>
Alloc_ty;
470 size_t perT = (sz + numT - 1) / numT;
472 for (
unsigned i = 0; i < numT; ++i) {
478 template <
typename T>
483 typedef typename gstl::template Pow2Alloc<T>
Alloc_ty;
495 template <
typename T,
unsigned ChunkSize = 64>
505 template <
typename T>
510 typedef typename gstl::template FixedSizeAlloc<T>
Alloc_ty;
522 template <
typename K,
typename V,
typename C = std::less<K>>
559 template <
typename T,
typename C = std::less<T>>
564 typedef typename gstl::template FixedSizeAlloc<T>
Alloc_ty;
594 template <
typename T,
typename C = std::less<T>>
599 typedef typename gstl::template Pow2Alloc<T>
Alloc_ty;
602 typedef typename gstl::template Vector<T>
Vec_ty;
631 #endif // GALOIS_PERTHREADCONTAINER_H
container_type::reverse_iterator local_reverse_iterator
Definition: PerThreadContainer.h:227
container_type::iterator local_iterator
Definition: PerThreadContainer.h:225
local_iterator local_begin()
Definition: PerThreadContainer.h:390
global_const_reverse_iterator const_reverse_iterator
Definition: PerThreadContainer.h:255
global_const_iterator end_all() const
Definition: PerThreadContainer.h:548
Super_ty::global_const_reverse_iterator global_const_reverse_iterator
Definition: PerThreadContainer.h:579
local_const_iterator local_cbegin() const
Definition: PerThreadContainer.h:397
PerThreadGdeque()
Definition: PerThreadContainer.h:502
Alloc_ty alloc
Definition: PerThreadContainer.h:606
Super_ty::global_const_iterator global_const_iterator
Definition: PerThreadContainer.h:542
Super_ty::global_const_iterator global_const_iterator
Definition: PerThreadContainer.h:577
global_const_iterator cbegin() const
Definition: PerThreadContainer.h:352
internal::StlInnerIsConstIterator< Outer >::type stl_two_level_cend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:780
PerThreadMinHeap(const C &cmp=C())
Definition: PerThreadContainer.h:609
unsigned int getActiveThreads() noexcept
Returns the number of threads in use.
Definition: Threads.cpp:37
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:461
gstl::template PQ< T, C > container_type
Definition: PerThreadContainer.h:603
global_iterator end_all()
Definition: PerThreadContainer.h:334
container_type::reference reference
Definition: PerThreadContainer.h:221
Definition: PerThreadContainer.h:479
PerThreadContainer()
Definition: PerThreadContainer.h:293
global_const_reverse_iterator rbegin_all() const
Definition: PerThreadContainer.h:376
global_const_iterator cbegin_all() const
Definition: PerThreadContainer.h:356
TypeFactory< This_ty >::RvrsOuterIter RvrsOuterIter
Definition: PerThreadContainer.h:235
global_iterator iterator
Definition: PerThreadContainer.h:252
global_const_iterator begin_all() const
Definition: PerThreadContainer.h:339
local_iterator local_end()
Definition: PerThreadContainer.h:391
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:533
TypeFactory< This_ty >::OuterIter OuterIter
Definition: PerThreadContainer.h:234
Definition: PerThreadContainer.h:496
void reserve_all(size_t sz)
Definition: PerThreadContainer.h:468
internal::StlInnerIsRvrsIterator< Outer >::type stl_two_level_rbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:786
galois::ChooseStlTwoLevelIterator< OuterIter, typename container_type::const_iterator >::type global_const_iterator
Definition: PerThreadContainer.h:244
T * getLocal()
Definition: PerThreadStorage.h:128
global_iterator end()
Definition: PerThreadContainer.h:346
container_type & get()
Definition: PerThreadContainer.h:315
global_iterator begin_all()
Definition: PerThreadContainer.h:329
PerThreadDeque()
Definition: PerThreadContainer.h:492
container_type & operator[](unsigned i)
Definition: PerThreadContainer.h:325
gstl::template FixedSizeAlloc< T > Alloc_ty
Definition: PerThreadContainer.h:510
global_reverse_iterator reverse_iterator
Definition: PerThreadContainer.h:254
gstl::template Set< T, C > container_type
Definition: PerThreadContainer.h:567
global_const_iterator end() const
Definition: PerThreadContainer.h:350
global_const_iterator begin_all() const
Definition: PerThreadContainer.h:547
global_const_reverse_iterator rend_all() const
Definition: PerThreadContainer.h:378
gstl::template Pow2Alloc< T > Alloc_ty
Definition: PerThreadContainer.h:457
size_type size_all() const
Definition: PerThreadContainer.h:406
internal::StlInnerIsConstRvrsIterator< Outer >::type stl_two_level_crbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:798
Definition: PerThreadContainer.h:506
global_const_reverse_iterator crbegin_all() const
Definition: PerThreadContainer.h:380
unsigned numRows() const
Definition: PerThreadContainer.h:313
void clear_all_parallel(void)
Definition: PerThreadContainer.h:423
gstl::template FixedSizeAlloc< T > Alloc_ty
Definition: PerThreadContainer.h:564
void on_each_gen(FunctionTy &&fn, const TupleTy &tpl)
Definition: Executor_OnEach.h:74
gstl::template Vector< T > Vec_ty
Definition: PerThreadContainer.h:602
PerThreadVector()
Definition: PerThreadContainer.h:466
gstl::template Pow2Alloc< T > Alloc_ty
Definition: PerThreadContainer.h:483
Super_ty::global_const_iterator global_const_iterator
Definition: PerThreadContainer.h:613
local_reverse_iterator local_rbegin()
Definition: PerThreadContainer.h:400
Definition: PerThreadContainer.h:217
bool empty_all() const
Definition: PerThreadContainer.h:429
Alloc_ty alloc
Definition: PerThreadContainer.h:463
s_wl< T, Args...> wl(Args &&...args)
Definition: Traits.h:219
container_type::const_iterator local_const_iterator
Definition: PerThreadContainer.h:226
global_const_reverse_iterator rend_all() const
Definition: PerThreadContainer.h:589
container_type::value_type value_type
Definition: PerThreadContainer.h:220
local_reverse_iterator local_rend()
Definition: PerThreadContainer.h:401
global_const_iterator end_all() const
Definition: PerThreadContainer.h:341
local_const_iterator local_cend() const
Definition: PerThreadContainer.h:398
typename runtime::FixedSizeAllocator< T > FixedSizeAlloc
[define Pow_2_VarSizeAlloc]
Definition: gstl.h:48
gstl::template Vector< T > container_type
Definition: PerThreadContainer.h:458
void do_all_gen(const R &range, F &&func, const ArgsTuple &argsTuple)
Definition: Executor_DoAll.h:530
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:514
Alloc_ty alloc
Definition: PerThreadContainer.h:489
gstl::template Map< K, V, C > container_type
Definition: PerThreadContainer.h:527
PerThreadSet(const C &cmp=C())
Definition: PerThreadContainer.h:573
container_type::size_type size_type
Definition: PerThreadContainer.h:223
gstl::template List< T > container_type
Definition: PerThreadContainer.h:513
PerThreadMap(const C &cmp=C())
Definition: PerThreadContainer.h:538
global_iterator begin()
Definition: PerThreadContainer.h:344
local_const_reverse_iterator local_crbegin() const
Definition: PerThreadContainer.h:403
void operator()(void)
Definition: Executor_ParaMeter.h:417
PerThreadContainer This_ty
Definition: PerThreadContainer.h:231
Alloc_ty alloc
Definition: PerThreadContainer.h:516
local_const_reverse_iterator local_crend() const
Definition: PerThreadContainer.h:404
global_const_reverse_iterator rbegin_all() const
Definition: PerThreadContainer.h:622
internal::StlInnerIsConstIterator< Outer >::type stl_two_level_cbegin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:774
~PerThreadContainer()
Definition: PerThreadContainer.h:307
Super_ty::global_const_reverse_iterator global_const_reverse_iterator
Definition: PerThreadContainer.h:544
galois::ChooseStlTwoLevelIterator< RvrsOuterIter, typename container_type::const_reverse_iterator >::type global_const_reverse_iterator
Definition: PerThreadContainer.h:250
gstl::template Pow2Alloc< T > Alloc_ty
Definition: PerThreadContainer.h:599
global_const_reverse_iterator rbegin_all() const
Definition: PerThreadContainer.h:551
unsigned size() const
Definition: PerThreadStorage.h:159
void fill_parallel(const Range &range, Ret(container_type::*pushFn)(const value_type &)=&container_type::push_back)
Definition: PerThreadContainer.h:439
global_reverse_iterator rbegin_all()
Definition: PerThreadContainer.h:366
global_const_iterator begin() const
Definition: PerThreadContainer.h:348
PerThreadList()
Definition: PerThreadContainer.h:519
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:568
internal::StlInnerIsConstRvrsIterator< Outer >::type stl_two_level_crend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:804
Super_ty::global_const_reverse_iterator global_const_reverse_iterator
Definition: PerThreadContainer.h:615
Definition: PerThreadContainer.h:560
global_reverse_iterator rend_all()
Definition: PerThreadContainer.h:371
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:604
global_const_iterator end_all() const
Definition: PerThreadContainer.h:619
Definition: PerThreadContainer.h:523
Definition: PerThreadContainer.h:454
internal::StlInnerIsIterator< Outer >::type stl_two_level_begin(Outer beg, Outer end)
Definition: TwoLevelIterator.h:762
gstl::template Deque< T > container_type
Definition: PerThreadContainer.h:486
internal::StlInnerIsIterator< Outer >::type stl_two_level_end(Outer beg, Outer end)
Definition: TwoLevelIterator.h:768
gstl::template FixedSizeAlloc< typename container_type::value_type > Alloc_ty
Definition: PerThreadContainer.h:530
global_const_iterator const_iterator
Definition: PerThreadContainer.h:253
const container_type & operator[](unsigned i) const
Definition: PerThreadContainer.h:327
global_const_reverse_iterator rend_all() const
Definition: PerThreadContainer.h:554
global_const_iterator end_all() const
Definition: PerThreadContainer.h:583
container_type::pointer pointer
Definition: PerThreadContainer.h:222
global_const_reverse_iterator crend_all() const
Definition: PerThreadContainer.h:385
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:149
global_const_iterator cend_all() const
Definition: PerThreadContainer.h:361
galois::ChooseStlTwoLevelIterator< RvrsOuterIter, typename container_type::reverse_iterator >::type global_reverse_iterator
Definition: PerThreadContainer.h:247
global_const_iterator begin_all() const
Definition: PerThreadContainer.h:618
Type function to select appropriate two-level iterator.
Definition: TwoLevelIterator.h:756
Definition: PerThreadContainer.h:595
T value_type
Definition: Executor_ParaMeter.h:111
galois::ChooseStlTwoLevelIterator< OuterIter, typename container_type::iterator >::type global_iterator
Definition: PerThreadContainer.h:241
global_const_iterator cend() const
Definition: PerThreadContainer.h:354
Cont_tp container_type
Definition: PerThreadContainer.h:219
global_const_iterator begin_all() const
Definition: PerThreadContainer.h:582
Alloc_ty alloc
Definition: PerThreadContainer.h:535
Alloc_ty alloc
Definition: PerThreadContainer.h:570
PerThreadContainer< container_type > Super_ty
Definition: PerThreadContainer.h:487
local_const_iterator local_begin() const
Definition: PerThreadContainer.h:394
local_const_iterator local_end() const
Definition: PerThreadContainer.h:395
global_const_reverse_iterator rbegin_all() const
Definition: PerThreadContainer.h:586
void init(Args &&...args)
Definition: PerThreadContainer.h:300
internal::StlInnerIsRvrsIterator< Outer >::type stl_two_level_rend(Outer beg, Outer end)
Definition: TwoLevelIterator.h:792
global_const_reverse_iterator rend_all() const
Definition: PerThreadContainer.h:625
container_type::const_reverse_iterator local_const_reverse_iterator
Definition: PerThreadContainer.h:229