3 #include "picstreenode.h"
8 char FieldName[NUM_NODES][30] = {
11 "AVG_OverheadPercentage",
12 "AVG_UtilizationPercentage",
14 "AVG_EntryMethodDuration",
15 "AVG_EntryMethodDuration_1",
16 "AVG_EntryMethodDuration_2",
18 "AVG_NumInvocations_1",
19 "AVG_NumInvocations_2",
22 "AVG_NumObjectsPerPE",
25 "AVG_NumMsgsPerObject",
29 "AVG_ExternalBytePerPE",
31 "AVG_CompressSourceBytes",
32 "AVG_CompressDestBytes",
39 "MAX_OverheadPercentage",
41 "MAX_UtilizationPercentage",
55 "MAX_NumMsgsPerObject",
59 "MAX_ExternalBytePerPE",
61 "MAX_CriticalPathLength",
67 "MAX_EntryMethodDuration",
69 "MAX_EntryMethodDuration_1",
71 "MAX_EntryMethodDuration_2",
78 "MIN_OverheadPercentage",
79 "MIN_UtilizationPercentage",
91 char EffectName[PICS_NUM_EFFECTS][30] = {
94 "PICS_EFF_AGGREGATION",
95 "PICS_EFF_COMPRESSION",
97 "PICS_EFF_LDBFREQUENCY",
99 "PICS_EFF_MESSAGESIZE",
100 "PICS_EFF_GRAINSIZE_1",
101 "PICS_EFF_GRAINSIZE_2",
105 char operatorName[4][2] = {"+", "-", "*", "/" };
106 char compareName[6][3] = {"==", "<", ">", ">=", "<=", "!="};
109 void Condition::printMe() {
110 printf("condition %s \n", name.c_str());
113 void Condition::printDataToFile(double *input, FILE *fp) {
115 fprintf(fp, "Condition %s %d %d ", name.c_str(), varIndex, baseIndex);
116 if(thresholdIndex > -1)
117 threshold = input[thresholdIndex];
119 fprintf(fp, " %s %f %s ", FieldName[varIndex], input[varIndex], operatorName[op]);
122 base = input[baseIndex];
123 fprintf(fp, " %s %f ", FieldName[baseIndex], base);
126 fprintf(fp, " %f ", base);
128 fprintf(fp, " %s %f ", compareName[symbol], threshold);
129 //potential improvement
130 fprintf(fp, " %f ", potentialImprove);
132 if(varIndex == MAX_EntryMethodDuration)
134 int entryIdx = (int)input[varIndex+1];
135 fprintf(fp, " %d %s %s ", entryIdx, _entryTable[entryIdx]->name, _chareTable[_entryTable[entryIdx]->chareIdx]->name);
136 }else if(varIndex>=NUM_AVG && varIndex<NUM_AVG+NUM_MAX)
137 fprintf(fp, " %d ", (int)input[varIndex+1]);
142 bool Condition::test(double *input) {
145 if(varIndex == -2) return true; //always true
147 assert(varIndex>-1 && varIndex<NUM_NODES);
148 double realValue = input[varIndex];
150 base = input[baseIndex];
151 if(thresholdIndex > -1)
152 threshold = input[thresholdIndex];
156 result = realValue + base;
160 result = realValue - base;
164 result = realValue * base;
168 result = realValue / base;
172 printf("Undefined OP\n");
178 ret = (result == threshold);
182 ret = (result < threshold);
186 ret = (result > threshold);
190 ret = (result >= threshold);
194 ret = (result <= threshold);
198 ret = (result != threshold);
202 printf("Undefined symbol \n");
205 if(!strcmp(name.c_str(), "CPU_Util"))
206 potentialImprove = 1 - realValue;
207 else if(!strcmp(name.c_str(), "High_Overhead"))
208 potentialImprove = realValue;
209 else if(!strcmp(name.c_str(), "High_Idle"))
210 potentialImprove = realValue;
212 potentialImprove = -100;
217 void Solution::printDataToFile(double *input, FILE *fp) {
218 int abseff = eff>=0?eff:-eff;
219 fprintf(fp, "Solution %s %s \n", eff>0?"UP":"Down", EffectName[abseff]);
222 TreeNode::TreeNode( TreeNode *p, Condition *c ) {
228 TreeNode::TreeNode( TreeNode *p, Solution *s ) {
234 void TreeNode::addChild(TreeNode *tn) {
235 children.push_back(tn);
238 void TreeNode::setParent(TreeNode *p) {
242 TreeNode* TreeNode::getParent() {
246 Data TreeNode::getValue() {
250 int TreeNode::getSolutionValue() {
252 return data.solution->getValue();
255 void TreeNode::beginChild() {
256 it = children.begin();
259 int TreeNode::isEndChild() {
260 return it == children.end();
263 void TreeNode::nextChild() {
267 TreeNode* TreeNode::getCurrentChild() {
271 void TreeNode::printMe() {
273 data.solution->printMe();
276 data.condition->printMe();
280 void TreeNode::printDataToFile(double *input, FILE *fp) {
282 data.solution->printDataToFile(input, fp);
285 data.condition->printDataToFile(input, fp);
290 bool TreeNode::test(double *input) {
291 if(!children.empty()) {
292 return data.condition->test(input);