Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OwnerComputes.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_WORKLIST_OWNERCOMPUTES_H
21 #define GALOIS_WORKLIST_OWNERCOMPUTES_H
22 
23 #include "galois/config.h"
25 
26 namespace galois {
27 namespace worklists {
28 
29 template <typename OwnerFn = DummyIndexer<int>,
30  typename Container = ChunkLIFO<>, typename T = int>
31 struct OwnerComputes : private boost::noncopyable {
32  template <typename _T>
33  using retype =
35 
36  template <bool b>
37  using rethread =
39 
40  template <typename _container>
41  struct with_container {
43  };
44 
45  template <typename _indexer>
46  struct with_indexer {
48  };
49 
50 private:
51  typedef typename Container::template retype<T> lWLTy;
52 
53  typedef lWLTy cWL;
54  typedef lWLTy pWL;
55 
56  OwnerFn Fn;
59 
60 public:
61  typedef T value_type;
62 
63  void push(const value_type& val) {
64  unsigned int index = Fn(val);
65  auto& tp = substrate::getThreadPool();
66  unsigned int mindex = tp.getSocket(index);
67  // std::cerr << "[" << index << "," << index % active << "]\n";
68  if (mindex == substrate::ThreadPool::getSocket())
69  items.getLocal()->push(val);
70  else
71  pushBuffer.getRemote(mindex)->push(val);
72  }
73 
74  template <typename ItTy>
75  void push(ItTy b, ItTy e) {
76  while (b != e)
77  push(*b++);
78  }
79 
80  template <typename RangeTy>
81  void push_initial(const RangeTy& range) {
82  auto rp = range.local_pair();
83  push(rp.first, rp.second);
84  for (unsigned int x = 0; x < pushBuffer.size(); ++x)
85  pushBuffer.getRemote(x)->flush();
86  }
87 
89  cWL& wl = *items.getLocal();
90  galois::optional<value_type> retval = wl.pop();
91  if (retval)
92  return retval;
93  pWL& p = *pushBuffer.getLocal();
94  while ((retval = p.pop()))
95  wl.push(*retval);
96  return wl.pop();
97  }
98 };
99 GALOIS_WLCOMPILECHECK(OwnerComputes)
100 
101 } // end namespace worklists
102 } // end namespace galois
103 
104 #endif
void push(ItTy b, ItTy e)
Definition: OwnerComputes.h:75
ThreadPool & getThreadPool(void)
return a reference to system thread pool
Definition: ThreadPool.cpp:259
void push(const value_type &val)
Definition: OwnerComputes.h:63
unsigned size() const
Definition: PerThreadStorage.h:243
void push_initial(const RangeTy &range)
Definition: OwnerComputes.h:81
OwnerComputes< _indexer, Container, T > type
Definition: OwnerComputes.h:47
Galois version of boost::optional.
Definition: optional.h:34
s_wl< T, Args...> wl(Args &&...args)
Definition: Traits.h:219
T * getLocal()
Definition: PerThreadStorage.h:202
#define GALOIS_WLCOMPILECHECK(name)
Definition: WLCompileCheck.h:26
static unsigned getSocket()
Definition: ThreadPool.h:207
galois::optional< value_type > pop()
Definition: OwnerComputes.h:88
T * getRemote(unsigned int thread)
Definition: PerThreadStorage.h:223
T value_type
Definition: OwnerComputes.h:61
OwnerComputes< OwnerFn, _container, T > type
Definition: OwnerComputes.h:42
Definition: OwnerComputes.h:31