00001
00002
00003
00004
00005
00006 #ifndef ASTSHAREDMEMORYPARALLELPROCESSING_H
00007 #define ASTSHAREDMEMORYPARALLELPROCESSING_H
00008
00009
00010
00011
00012
00013 #include "AstProcessing.h"
00014
00015
00016
00017
00018 struct AstSharedMemoryParallelProcessingSynchronizationInfo
00019 {
00020 #ifdef _MSC_VER
00021 #pragma message ("Error: pthread.h is unavailable on MSVC, we might want to use boost.thread library.")
00022 #else
00023
00024 pthread_mutex_t *mutex;
00025
00026 pthread_cond_t *synchronizationEvent;
00027
00028 pthread_cond_t *threadFinishedEvent;
00029 #endif
00030
00031
00032
00033 size_t *workingThreads;
00034
00035
00036 size_t *finishedThreads;
00037
00038
00039 size_t synchronizationWindowSize;
00040
00041 AstSharedMemoryParallelProcessingSynchronizationInfo(size_t numberOfThreads, size_t synchronizationWindowSize);
00042 ~AstSharedMemoryParallelProcessingSynchronizationInfo();
00043
00044 #if 1
00045
00046
00047
00048 AstSharedMemoryParallelProcessingSynchronizationInfo( const AstSharedMemoryParallelProcessingSynchronizationInfo & X );
00049 #endif
00050 };
00051
00052
00053
00054 class AstSharedMemoryParallelProcessingSynchronizationBase
00055 {
00056 protected:
00057 AstSharedMemoryParallelProcessingSynchronizationBase(const AstSharedMemoryParallelProcessingSynchronizationInfo &);
00058
00059 void synchronize();
00060
00061 void signalFinish();
00062
00063 private:
00064 AstSharedMemoryParallelProcessingSynchronizationInfo syncInfo;
00065 size_t numberOfThreads;
00066 };
00067
00068
00069
00070
00071
00072
00073 template <class InheritedAttributeType, class SynthesizedAttributeType>
00074 class AstSharedMemoryParallelizableTopDownBottomUpProcessing
00075 : public AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType>,
00076 private AstSharedMemoryParallelProcessingSynchronizationBase
00077 {
00078 public:
00079 typedef AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType> Superclass;
00080 typedef typename Superclass::TraversalType TraversalType;
00081 typedef typename Superclass::TraversalPtr TraversalPtr;
00082 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00083 typedef typename Superclass::InheritedAttributeTypeList InheritedAttributeTypeList;
00084 typedef typename Superclass::SynthesizedAttributeTypeList SynthesizedAttributeTypeList;
00085 typedef typename Superclass::SynthesizedAttributesList SynthesizedAttributesList;
00086
00087 AstSharedMemoryParallelizableTopDownBottomUpProcessing(
00088 const AstSharedMemoryParallelProcessingSynchronizationInfo &,
00089 const TraversalPtrList &);
00090
00091 void set_runningParallelTraversal(bool val);
00092
00093 protected:
00094 virtual InheritedAttributeTypeList *evaluateInheritedAttribute(
00095 SgNode *astNode,
00096 InheritedAttributeTypeList *inheritedValues);
00097 virtual void atTraversalEnd();
00098
00099 private:
00100 size_t visitedNodes;
00101 bool runningParallelTraversal;
00102 size_t synchronizationWindowSize;
00103 };
00104
00105
00106
00107
00108 template <class InheritedAttributeType, class SynthesizedAttributeType>
00109 class AstSharedMemoryParallelTopDownBottomUpProcessing
00110 : public AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType>
00111 {
00112 public:
00113 typedef AstCombinedTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType> Superclass;
00114 typedef typename Superclass::InheritedAttributeTypeList InheritedAttributeTypeList;
00115 typedef typename Superclass::SynthesizedAttributeTypeList SynthesizedAttributeTypeList;
00116 typedef typename Superclass::TraversalPtr TraversalPtr;
00117 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00118
00119 typedef AstSharedMemoryParallelizableTopDownBottomUpProcessing<InheritedAttributeType, SynthesizedAttributeType> *ParallelizableTraversalPtr;
00120 typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
00121
00122 SynthesizedAttributeTypeList *traverseInParallel(SgNode *basenode,
00123 InheritedAttributeTypeList *inheritedValue);
00124
00125 AstSharedMemoryParallelTopDownBottomUpProcessing();
00126 AstSharedMemoryParallelTopDownBottomUpProcessing(const TraversalPtrList &);
00127
00128 void set_numberOfThreads(size_t threads) const;
00129 void set_synchronizationWindowSize(size_t windowSize) const;
00130
00131 private:
00132 size_t numberOfThreads;
00133 size_t synchronizationWindowSize;
00134 };
00135
00136
00137
00138
00139
00140
00141 template <class InheritedAttributeType>
00142 class AstSharedMemoryParallelizableTopDownProcessing
00143 : public AstCombinedTopDownProcessing<InheritedAttributeType>,
00144 private AstSharedMemoryParallelProcessingSynchronizationBase
00145 {
00146 public:
00147 typedef AstCombinedTopDownProcessing<InheritedAttributeType> Superclass;
00148 typedef typename Superclass::TraversalType TraversalType;
00149 typedef typename Superclass::TraversalPtr TraversalPtr;
00150 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00151 typedef typename Superclass::InheritedAttributeTypeList InheritedAttributeTypeList;
00152
00153 AstSharedMemoryParallelizableTopDownProcessing(
00154 const AstSharedMemoryParallelProcessingSynchronizationInfo &,
00155 const TraversalPtrList &);
00156
00157 void set_runningParallelTraversal(bool val);
00158
00159 protected:
00160 virtual InheritedAttributeTypeList *evaluateInheritedAttribute(
00161 SgNode *astNode,
00162 InheritedAttributeTypeList *inheritedValues);
00163 virtual void atTraversalEnd();
00164
00165 private:
00166 size_t visitedNodes;
00167 bool runningParallelTraversal;
00168 size_t synchronizationWindowSize;
00169 };
00170
00171
00172
00173
00174 template <class InheritedAttributeType>
00175 class AstSharedMemoryParallelTopDownProcessing
00176 : public AstCombinedTopDownProcessing<InheritedAttributeType>
00177 {
00178 public:
00179 typedef AstCombinedTopDownProcessing<InheritedAttributeType> Superclass;
00180 typedef typename Superclass::InheritedAttributeTypeList InheritedAttributeTypeList;
00181 typedef typename Superclass::TraversalPtr TraversalPtr;
00182 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00183
00184 typedef AstSharedMemoryParallelizableTopDownProcessing<InheritedAttributeType> *ParallelizableTraversalPtr;
00185 typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
00186
00187 void traverseInParallel(SgNode *basenode, InheritedAttributeTypeList *inheritedValue);
00188
00189 AstSharedMemoryParallelTopDownProcessing();
00190 AstSharedMemoryParallelTopDownProcessing(const TraversalPtrList &);
00191
00192 void set_numberOfThreads(size_t threads) const;
00193 void set_synchronizationWindowSize(size_t windowSize) const;
00194
00195 private:
00196 size_t numberOfThreads;
00197 size_t synchronizationWindowSize;
00198 };
00199
00200
00201
00202
00203
00204
00205 template <class SynthesizedAttributeType>
00206 class AstSharedMemoryParallelizableBottomUpProcessing
00207 : public AstCombinedBottomUpProcessing<SynthesizedAttributeType>,
00208 private AstSharedMemoryParallelProcessingSynchronizationBase
00209 {
00210 public:
00211 typedef AstCombinedBottomUpProcessing<SynthesizedAttributeType> Superclass;
00212 typedef typename Superclass::TraversalType TraversalType;
00213 typedef typename Superclass::TraversalPtr TraversalPtr;
00214 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00215 typedef typename Superclass::SynthesizedAttributeTypeList SynthesizedAttributeTypeList;
00216 typedef typename Superclass::SynthesizedAttributesList SynthesizedAttributesList;
00217
00218 AstSharedMemoryParallelizableBottomUpProcessing(
00219 const AstSharedMemoryParallelProcessingSynchronizationInfo &,
00220 const TraversalPtrList &);
00221
00222 void set_runningParallelTraversal(bool val);
00223
00224 protected:
00225 virtual SynthesizedAttributeTypeList *evaluateSynthesizedAttribute(
00226 SgNode *astNode,
00227 SynthesizedAttributesList synthesizedAttributes);
00228 virtual void atTraversalEnd();
00229
00230 private:
00231 size_t visitedNodes;
00232 bool runningParallelTraversal;
00233 size_t synchronizationWindowSize;
00234 };
00235
00236
00237
00238
00239 template <class SynthesizedAttributeType>
00240 class AstSharedMemoryParallelBottomUpProcessing
00241 : public AstCombinedBottomUpProcessing<SynthesizedAttributeType>
00242 {
00243 public:
00244 typedef AstCombinedBottomUpProcessing<SynthesizedAttributeType> Superclass;
00245 typedef typename Superclass::SynthesizedAttributeTypeList SynthesizedAttributeTypeList;
00246 typedef typename Superclass::TraversalPtr TraversalPtr;
00247 typedef typename Superclass::TraversalPtrList TraversalPtrList;
00248
00249 typedef AstSharedMemoryParallelizableBottomUpProcessing<SynthesizedAttributeType> *ParallelizableTraversalPtr;
00250 typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList;
00251
00252 SynthesizedAttributeTypeList *traverseInParallel(SgNode *basenode);
00253
00254 AstSharedMemoryParallelBottomUpProcessing();
00255 AstSharedMemoryParallelBottomUpProcessing(const TraversalPtrList &);
00256
00257 void set_numberOfThreads(size_t threads) const;
00258 void set_synchronizationWindowSize(size_t windowSize) const;
00259
00260 private:
00261 size_t numberOfThreads;
00262 size_t synchronizationWindowSize;
00263 };
00264
00265 #include "AstSharedMemoryParallelProcessingImpl.h"
00266
00267 #include "AstSharedMemoryParallelSimpleProcessing.h"
00268
00269 #endif