00001 // Author: Gergo Barany 00002 // $Id: AstSharedMemoryParallelSimpleProcessing.h,v 1.1 2008/01/08 02:56:39 dquinlan Exp $ 00003 00004 // Class for parallelizing AstSimpleProcessing traversals; see the comment in 00005 // AstSharedMemoryParallelProcessing.h for general information. 00006 00007 #ifndef ASTSHAREDMEMORYPARALLELSIMPLEPROCESSING_H 00008 #define ASTSHAREDMEMORYPARALLELSIMPLEPROCESSING_H 00009 00010 #include "AstSimpleProcessing.h" 00011 #include "AstSharedMemoryParallelProcessing.h" 00012 00013 // parallel SIMPLE processing class 00014 00015 // Class representing a traversal that can run in parallel with some other instances of the same type. It is basically a 00016 // combined processing class with a thin synchronization layer. The user will probably never need to instantiate this 00017 // class, they should use the AstSharedMemoryParallel*Processing classes instead. 00018 class AstSharedMemoryParallelizableSimpleProcessing 00019 : public AstCombinedSimpleProcessing, 00020 private AstSharedMemoryParallelProcessingSynchronizationBase 00021 { 00022 public: 00023 typedef AstCombinedSimpleProcessing Superclass; 00024 typedef Superclass::TraversalType TraversalType; 00025 typedef Superclass::TraversalPtr TraversalPtr; 00026 typedef Superclass::TraversalPtrList TraversalPtrList; 00027 00028 AstSharedMemoryParallelizableSimpleProcessing( 00029 const AstSharedMemoryParallelProcessingSynchronizationInfo &, 00030 const TraversalPtrList &); 00031 00032 void set_runningParallelTraversal(bool val); 00033 00034 protected: 00035 virtual void visit(SgNode *astNode); 00036 virtual void atTraversalEnd(); 00037 00038 private: 00039 size_t visitedNodes; 00040 bool runningParallelTraversal; 00041 size_t synchronizationWindowSize; 00042 }; 00043 00044 // Class for parallel execution of a number of traversals. This is a drop-in 00045 // replacement for the corresponding AstCombined*Processing class, the usage 00046 // is identical except that you call traverseInParallel() instead of 00047 // traverse(). (Calling traverse() is identical to AstCombined*Processing, 00048 // i.e. it will not run in parallel.) 00049 class AstSharedMemoryParallelSimpleProcessing 00050 : public AstCombinedSimpleProcessing 00051 { 00052 public: 00053 typedef AstCombinedSimpleProcessing Superclass; 00054 typedef Superclass::TraversalPtr TraversalPtr; 00055 typedef Superclass::TraversalPtrList TraversalPtrList; 00056 00057 typedef AstSharedMemoryParallelizableSimpleProcessing *ParallelizableTraversalPtr; 00058 typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList; 00059 00060 AstSharedMemoryParallelSimpleProcessing(int threads); 00061 AstSharedMemoryParallelSimpleProcessing(const TraversalPtrList &, int threads); 00062 00063 void traverseInParallel(SgNode *basenode, t_traverseOrder treeTraverseOrder); 00064 00065 private: 00066 size_t numberOfThreads; 00067 size_t synchronizationWindowSize; 00068 }; 00069 00070 // parallel PRE POST processing class 00071 00072 // Class representing a traversal that can run in parallel with some other instances of the same type. It is basically a 00073 // combined processing class with a thin synchronization layer. The user will probably never need to instantiate this 00074 // class, they should use the AstSharedMemoryParallel*Processing classes instead. 00075 class AstSharedMemoryParallelizablePrePostProcessing 00076 : public AstCombinedPrePostProcessing, 00077 private AstSharedMemoryParallelProcessingSynchronizationBase 00078 { 00079 public: 00080 typedef AstCombinedPrePostProcessing Superclass; 00081 typedef Superclass::TraversalType TraversalType; 00082 typedef Superclass::TraversalPtr TraversalPtr; 00083 typedef Superclass::TraversalPtrList TraversalPtrList; 00084 00085 AstSharedMemoryParallelizablePrePostProcessing( 00086 const AstSharedMemoryParallelProcessingSynchronizationInfo &, 00087 const TraversalPtrList &); 00088 00089 void set_runningParallelTraversal(bool val); 00090 00091 protected: 00092 virtual void preOrderVisit(SgNode *astNode); 00093 virtual void atTraversalEnd(); 00094 00095 private: 00096 size_t visitedNodes; 00097 bool runningParallelTraversal; 00098 size_t synchronizationWindowSize; 00099 }; 00100 00101 // Class for parallel execution of a number of traversals. This is a drop-in 00102 // replacement for the corresponding AstCombined*Processing class, the usage 00103 // is identical except that you call traverseInParallel() instead of 00104 // traverse(). (Calling traverse() is identical to AstCombined*Processing, 00105 // i.e. it will not run in parallel.) 00106 class AstSharedMemoryParallelPrePostProcessing 00107 : public AstCombinedPrePostProcessing 00108 { 00109 public: 00110 typedef AstCombinedPrePostProcessing Superclass; 00111 typedef Superclass::TraversalPtr TraversalPtr; 00112 typedef Superclass::TraversalPtrList TraversalPtrList; 00113 00114 typedef AstSharedMemoryParallelizablePrePostProcessing *ParallelizableTraversalPtr; 00115 typedef std::vector<ParallelizableTraversalPtr> ParallelizableTraversalPtrList; 00116 00117 AstSharedMemoryParallelPrePostProcessing(int threads); 00118 AstSharedMemoryParallelPrePostProcessing(const TraversalPtrList &,int threads); 00119 00120 void traverseInParallel(SgNode *basenode); 00121 00122 private: 00123 size_t numberOfThreads; 00124 size_t synchronizationWindowSize; 00125 }; 00126 00127 #endif
1.4.7