Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UserContext.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_USERCONTEXT_H
21 #define GALOIS_USERCONTEXT_H
22 
23 #include <functional>
24 
25 #include "galois/config.h"
26 #include "galois/gdeque.h"
27 #include "galois/Mem.h"
28 #include "galois/runtime/Context.h"
29 
30 namespace galois {
31 
36 template <typename T>
37 class UserContext : private boost::noncopyable {
38 protected:
41  static const unsigned int fastPushBackLimit = 64;
42  typedef std::function<void(PushBufferTy&)> FastPushBack;
43 
48 
50  bool* didBreak = nullptr;
52 
54  bool firstPassFlag = false;
55  void* localState = nullptr;
56 
58 
59  void __setFirstPass(void) { firstPassFlag = true; }
60 
61  void __resetFirstPass(void) { firstPassFlag = false; }
62 
64 
66 
67  void __setLocalState(void* p) { localState = p; }
68 
70 
71 public:
75 
78  void breakLoop() { *didBreak = true; }
79 
82 
84  template <typename... Args>
85  void push(Args&&... args) {
86  // galois::runtime::checkWrite(MethodFlag::WRITE, true);
87  pushBuffer.emplace_back(std::forward<Args>(args)...);
90  }
91 
93  template <typename... Args>
94  inline void push_back(Args&&... args) {
95  this->push(std::forward<Args>(args)...);
96  }
97 
99  template <typename... Args>
100  inline void insert(Args&&... args) {
101  this->push(std::forward<Args>(args)...);
102  }
103 
106 
108  template <typename LS>
109  LS* getLocalState(void) {
110  return reinterpret_cast<LS*>(localState);
111  }
112 
113  template <typename LS, typename... Args>
114  LS* createLocalState(Args&&... args) {
115  new (localState) LS(std::forward<Args>(args)...);
116  return getLocalState<LS>();
117  }
118 
123  bool isFirstPass(void) const { return firstPassFlag; }
124 
128  void cautiousPoint() {
129  if (isFirstPass()) {
131  }
132  }
133 };
134 
135 } // namespace galois
136 
137 #endif
PushBufferTy pushBuffer
Definition: UserContext.h:44
void * localState
Definition: UserContext.h:55
LS * createLocalState(Args &&...args)
Definition: UserContext.h:114
void abort()
Force the abort of this iteration.
Definition: UserContext.h:105
FastPushBack fastPushBack
Definition: UserContext.h:51
void push(Args &&...args)
Push new work.
Definition: UserContext.h:85
bool firstPassFlag
some flags used by deterministic
Definition: UserContext.h:54
void __setLocalState(void *p)
Definition: UserContext.h:67
void cautiousPoint()
declare that the operator has crossed the cautious point.
Definition: UserContext.h:128
void __resetFirstPass(void)
Definition: UserContext.h:61
size_t size() const
Definition: gdeque.h:348
void signalFailSafe(void)
Definition: libgalois/include/galois/runtime/Context.h:65
void __resetAlloc()
Definition: UserContext.h:57
void __setFirstPass(void)
Definition: UserContext.h:59
void clear()
Definition: gdeque.h:394
void insert(Args &&...args)
Push new work.
Definition: UserContext.h:100
static const unsigned int fastPushBackLimit
Definition: UserContext.h:41
IterAllocBaseTy IterationAllocatorBase
Allocator stuff.
Definition: UserContext.h:46
bool * didBreak
used by all
Definition: UserContext.h:50
void emplace_back(Args &&...args)
Definition: gdeque.h:462
void push_back(Args &&...args)
Push new work.
Definition: UserContext.h:94
void signalConflict(Lockable *=nullptr)
Definition: libgalois/include/galois/runtime/Context.h:52
PerIterAllocTy PerIterationAllocator
Definition: UserContext.h:47
This is the object passed to the user&#39;s parallel loop.
Definition: UserContext.h:37
PushBufferTy & __getPushBuffer()
Definition: UserContext.h:63
std::function< void(PushBufferTy &)> FastPushBack
Definition: UserContext.h:42
LS * getLocalState(void)
Store and retrieve local state for deterministic.
Definition: UserContext.h:109
void breakLoop()
Signal break in parallel loop, current iteration continues untill natural termination.
Definition: UserContext.h:78
PerIterAllocTy & getPerIterAlloc()
Acquire a per-iteration allocator.
Definition: UserContext.h:81
bool isFirstPass(void) const
used by deterministic and ordered
Definition: UserContext.h:123
void __setFastPushBack(FastPushBack f)
Definition: UserContext.h:69
UserContext()
Definition: UserContext.h:72
gdeque< T > PushBufferTy
push stuff
Definition: UserContext.h:40
void __resetPushBuffer()
Definition: UserContext.h:65
void clear()
Definition: runtime/Mem.h:475