ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DistributedMemoryAnalysis.h
Go to the documentation of this file.
1 // This file is part of a new experimental framework for distributed memory program analysis using MPI.
2 // Author: Gergo Barany
3 // $Id: DistributedMemoryAnalysis.h,v 1.1 2008/01/08 02:55:52 dquinlan Exp $
4 
5 #ifndef DISTRIBUTED_MEMORY_ANALYSIS_H
6 #define DISTRIBUTED_MEMORY_ANALYSIS_H
7 
8 #if ROSE_MPI
9 
10 //#include <mpi.h>
11 
12 #include <utility>
13 
14 void initializeDistributedMemoryProcessing(int *argc, char ***argv);
15 void finalizeDistributedMemoryProcessing();
16 
17 template <class InheritedAttributeType>
18 class DistributedMemoryAnalysisBase
19 {
20 public:
21  bool isRootProcess() const {return (my_rank == root_process);}
22  DistributedMemoryAnalysisBase() {
23  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
24  MPI_Comm_size(MPI_COMM_WORLD, &processes);
25  nrOfNodes=0;
26  }
27  virtual ~DistributedMemoryAnalysisBase() {}
28 
29 public:
30  int myID() const { return my_rank; }
31  int numberOfProcesses() const { return processes; }
32 
33  int nrOfNodes;
34  std::vector<size_t> myNodeCounts;
35  std::vector<size_t> myFuncWeights;
36 
37  std::vector<SgFunctionDeclaration *> funcDecls;
38  std::vector<InheritedAttributeType> initialInheritedValues;
39  std::vector<int> functionsPerProcess;
40  static const int root_process = 0;
41  std::pair<int, int> computeFunctionIndices(SgNode *root,
42  InheritedAttributeType rootInheritedValue,
44  void computeFunctionIndicesPerNode(SgNode *root, std::vector<int>& functionToProcessor,
45  InheritedAttributeType rootInheritedValue,
47  void sortFunctions(std::vector<SgFunctionDeclaration*>& funcDecls, std::vector<InheritedAttributeType>& inhertiedValues,
48  std::vector<size_t>& nodeCounts, std::vector<size_t>& funcWeights);
49 
50  private:
51  int my_rank;
52  int processes;
53 };
54 
55 
56 
57 
58 template <class InheritedAttributeType, class SynthesizedAttributeType>
59 class DistributedMemoryTraversal: public DistributedMemoryAnalysisBase<InheritedAttributeType>
60 {
61 public:
62  void performAnalysis(SgNode *root, InheritedAttributeType rootInheritedValue,
65  SynthesizedAttributeType getFinalResults() {return finalResults;}
66  DistributedMemoryTraversal() {}
67  virtual ~DistributedMemoryTraversal() {}
68 
69 protected:
70  virtual SynthesizedAttributeType analyzeSubtree(SgFunctionDeclaration *funcDecl,
71  InheritedAttributeType initialInheritedValue) = 0;
72  virtual std::pair<int, void *> serializeAttribute(SynthesizedAttributeType attribute) const = 0;
73  virtual SynthesizedAttributeType deserializeAttribute(std::pair<int, void *> serializedAttribute) const = 0;
74  virtual void deleteSerializedAttribute(std::pair<int, void *> serializedAttribute) const {}
75 
76 private:
77  SynthesizedAttributeType finalResults;
78  std::vector<SynthesizedAttributeType> functionResults;
79 
80  DistributedMemoryTraversal(const DistributedMemoryTraversal &);
81  const DistributedMemoryTraversal &operator=(const DistributedMemoryTraversal &);
82 };
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 // --------- Implementor Line - Do Not Cross ---------
96 // There is nothing for users to see here, move along.
97 
98 template <class InheritedAttributeType>
100  : public AstTopDownProcessing<InheritedAttributeType>
101 {
102 public:
104  : preTraversal(preTraversal), inFunc(false), nodeCount(0), stdFunc(false), weightNullDeref(1),
105  weightAssignOp(1) {}
106 
107  std::vector<SgFunctionDeclaration *> &get_funcDecls() {return funcDecls;}
108  std::vector<InheritedAttributeType> &get_initialInheritedValues() {return initialInheritedValues;}
109  std::vector<size_t> &get_nodeCounts() {return nodeCounts;}
110  std::vector<size_t> &get_funcWeights() {return funcWeights;}
111 
112 protected:
113  InheritedAttributeType evaluateInheritedAttribute(SgNode *, InheritedAttributeType);
114  void destroyInheritedValue(SgNode *, InheritedAttributeType);
115 
116 private:
118  bool inFunc;
119  size_t nodeCount;
120  bool stdFunc;
121  size_t weightNullDeref;
122  size_t weightAssignOp;
123 
124  std::vector<SgFunctionDeclaration *> funcDecls;
125  std::vector<InheritedAttributeType> initialInheritedValues;
126  std::vector<size_t> nodeCounts;
127  std::vector<size_t> funcWeights;
128 };
129 
130 
131 
132 
133 //namespace DistributedMemoryAnalysisNamespace {
134 // bool postTraversalEvaluateInheritedAttribute(SgNode* node, bool inFunction);
135 //}
136 
137 template <class SynthesizedAttributeType>
139  : public AstTopDownBottomUpProcessing<bool, SynthesizedAttributeType>
140 {
141 public:
143  const std::vector<SynthesizedAttributeType> &functionResults)
144  : postTraversal(postTraversal), functionResults(functionResults), functionCounter(0), stdFunc(false) {}
145 
147 
148 protected:
149  bool evaluateInheritedAttribute(SgNode *node, bool inFunction);
150  // {
151  // return DistributedMemoryAnalysisNamespace::postTraversalEvaluateInheritedAttribute(node, inFunction);
152  //}
153  SynthesizedAttributeType evaluateSynthesizedAttribute(SgNode *, bool, SynthesizedAttributesList);
154  SynthesizedAttributeType defaultSynthesizedAttribute(bool) {return postTraversal->defaultSynthesizedAttribute();}
155 
156 private:
158  const std::vector<SynthesizedAttributeType> &functionResults;
159  int functionCounter;
160  bool stdFunc;
161 };
162 
163 
164 
165 
166 
167 
168 
169 
170 
171 
172 
173 
175 
176 #endif
177 
178 #endif