ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AstSharedMemoryParallelProcessing.h
Go to the documentation of this file.
1 // Author: Gergo Barany
2 // $Id: AstSharedMemoryParallelProcessing.h,v 1.1 2008/01/08 02:56:39 dquinlan Exp $
3 
4 // Classes for shared-memory (multithreaded) parallel AST traversals.
5 
6 #ifndef ASTSHAREDMEMORYPARALLELPROCESSING_H
7 #define ASTSHAREDMEMORYPARALLELPROCESSING_H
8 
9 // tps (01/08/2010) Added sage3basic since this doesnt compile under gcc4.1.2
10 //#include "sage3basic.h"
11 //#include "sage3.h"
12 
13 #include "AstProcessing.h"
14 
15 // Class containing all the information needed to synchronize parallelizable traversals. All traversals running
16 // synchronously must have a shallow copy of this (they all need the same pointers!), the default copy mechanism takes
17 // care of that.
19 {
20 #ifdef _MSC_VER
21 #pragma message ("Error: pthread.h is unavailable on MSVC, we might want to use boost.thread library.")
22 #else
23  // mutex that controls access to the global stuff here
24  pthread_mutex_t *mutex;
25  // signal broadcast by last worker thread to arrive at a synchronization point
26  pthread_cond_t *synchronizationEvent;
27  // signal sent by workers when they exit
28  pthread_cond_t *threadFinishedEvent;
29 #endif
30 
31  // global counter of the number of threads that are still working (i.e.
32  // have not sent a synchronizationEvent)
33  size_t *workingThreads;
34  // global counter of the number of threads that have completely finished
35  // (i.e. have traversed the whole AST)
36  size_t *finishedThreads;
37  // number of nodes to be visited by each traversal before they are
38  // supposed to synchronize
40 
43 
44 #if 1
45  // We can't implement this as private since it is required. So we have a potential double free error here.
46  // private:
47  // DQ (9/13/2011): This copy constructor was built because static analysis tools (made it private to force compile time error if used).
49 #endif
50 };
51 
52 // Class containing the code needed for synchronization of parallelizable traversals. The parallelizable processing
53 // classes inherit privately from this because the code is the same for all of them.
55 {
56 protected:
58  // called when threads want to synchronize
59  void synchronize();
60  // called when threads are about to finish
61  void signalFinish();
62 
63 private:
66 };
67 
68 // TOP DOWN BOTTOM UP parallel traversals
69 
70 // Class representing a traversal that can run in parallel with some other instances of the same type. It is basically a
71 // combined processing class with a thin synchronization layer. The user will probably never need to instantiate this
72 // class, they should use the AstSharedMemoryParallel*Processing classes instead.
73 template <class InheritedAttributeType, class SynthesizedAttributeType>
75  : public AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType>,
77 {
78 public:
86 
89  const TraversalPtrList &);
90 
91  void set_runningParallelTraversal(bool val);
92 
93 protected:
95  SgNode *astNode,
96  InheritedAttributeTypeList *inheritedValues);
97  virtual void atTraversalEnd();
98 
99 private:
100  size_t visitedNodes;
103 };
104 
105 // Class for parallel execution of a number of traversals. This is a drop-in replacement for the corresponding
106 // AstCombined*Processing class, the usage is identical except that you call traverseInParallel() instead of traverse().
107 // (Calling traverse() is identical to AstCombined*Processing, i.e. it will not run in parallel.)
108 template <class InheritedAttributeType, class SynthesizedAttributeType>
110  : public AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType>
111 {
112 public:
118 
120  typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
121 
123  InheritedAttributeTypeList *inheritedValue);
124 
127 
128  void set_numberOfThreads(size_t threads) const;
129  void set_synchronizationWindowSize(size_t windowSize) const;
130 
131 private:
134 };
135 
136 // TOP DOWN parallel traversals
137 
138 // Class representing a traversal that can run in parallel with some other instances of the same type. It is basically a
139 // combined processing class with a thin synchronization layer. The user will probably never need to instantiate this
140 // class, they should use the AstSharedMemoryParallel*Processing classes instead.
141 template <class InheritedAttributeType>
143  : public AstCombinedTopDownProcessing<InheritedAttributeType>,
145 {
146 public:
152 
155  const TraversalPtrList &);
156 
157  void set_runningParallelTraversal(bool val);
158 
159 protected:
161  SgNode *astNode,
162  InheritedAttributeTypeList *inheritedValues);
163  virtual void atTraversalEnd();
164 
165 private:
166  size_t visitedNodes;
169 };
170 
171 // Class for parallel execution of a number of traversals. This is a drop-in replacement for the corresponding
172 // AstCombined*Processing class, the usage is identical except that you call traverseInParallel() instead of traverse().
173 // (Calling traverse() is identical to AstCombined*Processing, i.e. it will not run in parallel.)
174 template <class InheritedAttributeType>
176  : public AstCombinedTopDownProcessing<InheritedAttributeType>
177 {
178 public:
183 
185  typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
186 
187  void traverseInParallel(SgNode *basenode, InheritedAttributeTypeList *inheritedValue);
188 
191 
192  void set_numberOfThreads(size_t threads) const;
193  void set_synchronizationWindowSize(size_t windowSize) const;
194 
195 private:
198 };
199 
200 // BOTTOM UP parallel traversals
201 
202 // Class representing a traversal that can run in parallel with some other instances of the same type. It is basically a
203 // combined processing class with a thin synchronization layer. The user will probably never need to instantiate this
204 // class, they should use the AstSharedMemoryParallel*Processing classes instead.
205 template <class SynthesizedAttributeType>
207  : public AstCombinedBottomUpProcessing<SynthesizedAttributeType>,
209 {
210 public:
217 
220  const TraversalPtrList &);
221 
222  void set_runningParallelTraversal(bool val);
223 
224 protected:
226  SgNode *astNode,
228  virtual void atTraversalEnd();
229 
230 private:
231  size_t visitedNodes;
234 };
235 
236 // Class for parallel execution of a number of traversals. This is a drop-in replacement for the corresponding
237 // AstCombined*Processing class, the usage is identical except that you call traverseInParallel() instead of traverse().
238 // (Calling traverse() is identical to AstCombined*Processing, i.e. it will not run in parallel.)
239 template <class SynthesizedAttributeType>
241  : public AstCombinedBottomUpProcessing<SynthesizedAttributeType>
242 {
243 public:
248 
250  typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
251 
253 
256 
257  void set_numberOfThreads(size_t threads) const;
258  void set_synchronizationWindowSize(size_t windowSize) const;
259 
260 private:
263 };
264 
266 
268 
269 #endif