Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LocalQueue.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_LOCALQUEUE_H
21 #define GALOIS_WORKLIST_LOCALQUEUE_H
22 
23 #include <type_traits>
24 
25 #include <boost/mpl/if.hpp>
26 
27 #include "galois/config.h"
29 
30 namespace galois {
31 namespace worklists {
32 
33 template <typename T = int>
34 struct NoGlobalQueue {
35  template <bool _concurrent>
37 
38  template <typename _T>
40 };
41 
42 template <typename Global = NoGlobalQueue<>, typename Local = GFIFO<int>,
43  typename T = int>
44 struct LocalQueue : private boost::noncopyable {
45  template <bool _concurrent>
47 
48  template <typename _T>
50  typename Local::template retype<_T>, _T>;
51 
52  template <typename _global>
54 
55  template <typename _local>
57 
58 private:
59  typedef typename Local::template rethread<false> lWLTy;
61  Global global;
62 
63  template <typename RangeTy,
64  bool Enable = std::is_same<Global, NoGlobalQueue<T>>::value>
65  void pushGlobal(const RangeTy& range,
66  typename std::enable_if<Enable>::type* = 0) {
67  auto rp = range.local_pair();
68  local.getLocal()->push(rp.first, rp.second);
69  }
70 
71  template <typename RangeTy,
72  bool Enable = std::is_same<Global, NoGlobalQueue<T>>::value>
73  void pushGlobal(const RangeTy& range,
74  typename std::enable_if<!Enable>::type* = 0) {
75  global.push_initial(range);
76  }
77 
78  template <bool Enable = std::is_same<Global, NoGlobalQueue<T>>::value>
79  galois::optional<T> popGlobal(typename std::enable_if<Enable>::type* = 0) {
81  }
82 
83  template <bool Enable = std::is_same<Global, NoGlobalQueue<T>>::value>
84  galois::optional<T> popGlobal(typename std::enable_if<!Enable>::type* = 0) {
85  return global.pop();
86  }
87 
88 public:
89  typedef T value_type;
90 
91  void push(const value_type& val) { local.getLocal()->push(val); }
92 
93  template <typename Iter>
94  void push(Iter b, Iter e) {
95  local.getLocal()->push(b, e);
96  }
97 
98  template <typename RangeTy>
99  void push_initial(const RangeTy& range) {
100  pushGlobal(range);
101  }
102 
104  galois::optional<value_type> ret = local.getLocal()->pop();
105  if (ret)
106  return ret;
107  return popGlobal();
108  }
109 };
110 GALOIS_WLCOMPILECHECK(LocalQueue)
111 
112 } // end namespace worklists
113 } // end namespace galois
114 
115 #endif
void push(const value_type &val)
Definition: LocalQueue.h:91
void push(Iter b, Iter e)
Definition: LocalQueue.h:94
Definition: LocalQueue.h:44
T * getLocal()
Definition: PerThreadStorage.h:128
Definition: LocalQueue.h:34
galois::optional< value_type > pop()
Definition: LocalQueue.h:103
Galois version of boost::optional.
Definition: optional.h:34
#define GALOIS_WLCOMPILECHECK(name)
Definition: WLCompileCheck.h:26
void push_initial(const RangeTy &range)
Definition: LocalQueue.h:99
T value_type
Definition: LocalQueue.h:89