build: fix travis MPI/SMP build
[charm.git] / src / ck-pics / picstreenode.C
blob3dbd7b7f7252461196cfadc2ad958862eb96021e
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "picstreenode.h"
4 #include "charm++.h"
5 #include "register.h"
8 char FieldName[NUM_NODES][30] = {
9  "AVG_TotalTime",
10  "AVG_IdlePercentage",
11  "AVG_OverheadPercentage",
12  "AVG_UtilizationPercentage",
13  "AVG_AppPercentage",
14  "AVG_EntryMethodDuration",
15  "AVG_EntryMethodDuration_1",
16  "AVG_EntryMethodDuration_2",
17  "AVG_NumInvocations",
18  "AVG_NumInvocations_1",
19  "AVG_NumInvocations_2",
20  "AVG_LoadPerObject",
21  "AVG_LoadPerPE",
22  "AVG_NumObjectsPerPE",
23  "AVG_BytesPerMsg",
24  "AVG_BytesPerObject",
25  "AVG_NumMsgsPerObject",
26  "AVG_NumMsgPerPE",
27  "AVG_CacheMissRate",
28  "AVG_BytesPerPE",
29  "AVG_ExternalBytePerPE",
30  "AVG_CompressTime",
31  "AVG_CompressSourceBytes",
32  "AVG_CompressDestBytes",
33  "AVG_NumMsgRecv",
34  "AVG_BytesMsgRecv",
35  "AVG_MsgTimeCost",
36  "AVG_TuningOverhead",
37  "MAX_IdlePercentage",
38  "MAX_IdlePE",
39  "MAX_OverheadPercentage",
40  "MAX_OverheadPE",
41  "MAX_UtilizationPercentage",
42  "MAX_UtilPE",
43  "MAX_AppPercentage",
44  "MAX_AppPE",
45  "MAX_NumInvocations",
46  "MAX_NumInvocPE",
47  "MAX_LoadPerObject",
48  "MAX_ObjID",
49  "MAX_LoadPerPE",
50  "MAX_LoadPE",
51  "MAX_BytesPerMsg",
52  "MAX_BytesEntryID",
53  "MAX_BytesPerObject",
54  "MAX_ByteObjID",
55  "MAX_NumMsgsPerObject",
56  "MAX_NumMsgObjID",
57  "MAX_BytesPerPE",
58  "MAX_BytesPE",
59  "MAX_ExternalBytePerPE",
60  "MAX_ExternalBytePE",
61  "MAX_CriticalPathLength",
62  "MAX_CPPE",
63  "MAX_NumMsgRecv",
64  "MAX_NumMsgRecvPE",
65  "MAX_BytesMsgRecv",
66  "MAX_BytesMsgRecvPE",
67  "MAX_EntryMethodDuration",
68  "MAX_EntryID",
69  "MAX_EntryMethodDuration_1",
70  "MAX_EntryID_1",
71  "MAX_EntryMethodDuration_2",
72  "MAX_EntryID_2",
73  "MAX_NumMsgSend",
74  "MAX_NumMsgSendPE",
75  "MAX_BytesSend",
76  "MAX_BytesSendPE",
77  "MIN_IdlePercentage",
78  "MIN_OverheadPercentage",
79  "MIN_UtilizationPercentage",
80  "MIN_AppPercentage",
81  "MIN_LoadPerObject",
82  "MIN_LoadPerPE",
83  "MIN_BytesPerMsg",
84  "MIN_NumMsgRecv",
85  "MIN_BytesMsgRecv",
86  "MinIdlePE",
87  "MaxEntryPE"
91 char EffectName[PICS_NUM_EFFECTS][30] = { 
92   "PICS_EFF_PERFGOOD",
93   "PICS_EFF_GRAINSIZE",
94   "PICS_EFF_AGGREGATION", 
95   "PICS_EFF_COMPRESSION",
96   "PICS_EFF_REPLICA", 
97   "PICS_EFF_LDBFREQUENCY",
98   "PICS_EFF_NODESIZE",
99   "PICS_EFF_MESSAGESIZE",
100   "PICS_EFF_GRAINSIZE_1",
101   "PICS_EFF_GRAINSIZE_2",
102   "PICS_EFF_UNKNOWN"
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];
118   if(varIndex>-1)
119     fprintf(fp, "  %s %f %s ", FieldName[varIndex], input[varIndex], operatorName[op]);
121   if(baseIndex > -1) {
122     base = input[baseIndex];
123     fprintf(fp, " %s %f ", FieldName[baseIndex], base);
124   }
125   else
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)
133   {
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]);
139   fprintf(fp, "\n");
142 bool Condition::test(double *input) {
143   bool ret;
144   double result;
145   if(varIndex == -2) return true;     //always true
147   assert(varIndex>-1 && varIndex<NUM_NODES);
148   double realValue = input[varIndex];
149   if(baseIndex > -1)
150     base = input[baseIndex];
151   if(thresholdIndex > -1)
152     threshold = input[thresholdIndex];
154   switch(op) {
155   case ADD:
156     result = realValue + base;
157     break;
159   case SUB:
160     result = realValue - base;
161     break;
163   case MUL:
164     result = realValue * base;
165     break;
167   case DIV:
168     result = realValue / base;
169     break;
171   default:
172     printf("Undefined OP\n");
173     exit(1);
174   }
176   switch(symbol) {
177   case IS:
178     ret = (result == threshold);
179     break;
181   case LT:
182     ret = (result < threshold);
183     break;
185   case GT:
186     ret = (result > threshold);
187     break;
189   case NLT:
190     ret = (result >= threshold);
191     break;
193   case NGT:
194     ret = (result <= threshold);
195     break;
197   case NOTIS:
198     ret = (result != threshold);
199     break;
201   default:
202     printf("Undefined symbol \n");
203     exit(1);
204   }
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;
211   else 
212     potentialImprove = -100;
214   return ret;
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 ) {
223   parent = p;
224   data.condition = c;
225   _isSolution = false;
228 TreeNode::TreeNode( TreeNode *p, Solution *s ) {
229   parent = p;
230   data.solution = s;
231   _isSolution = true;
234 void TreeNode::addChild(TreeNode *tn) {
235   children.push_back(tn);
238 void TreeNode::setParent(TreeNode *p) {
239   parent = p;
242 TreeNode* TreeNode::getParent() {
243   return parent;
246 Data TreeNode::getValue() {
247   return data;
250 int TreeNode::getSolutionValue() {
251   assert(_isSolution);
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() {
264   it++;
267 TreeNode* TreeNode::getCurrentChild() {
268   return *it;
271 void TreeNode::printMe() {
272   if(_isSolution) {
273     data.solution->printMe();
274   }
275   else {
276     data.condition->printMe();
277   }
280 void TreeNode::printDataToFile(double *input, FILE *fp) {
281   if(_isSolution) {
282     data.solution->printDataToFile(input, fp);
283   }
284   else {
285     data.condition->printDataToFile(input, fp);
286   }
290 bool TreeNode::test(double *input) {
291   if(!children.empty()) {
292     return data.condition->test(input);
293   }
294   else {
295     return false;
296   }