-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path431project.cpp
More file actions
177 lines (150 loc) · 5.42 KB
/
431project.cpp
File metadata and controls
177 lines (150 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <fstream>
#include <map>
#include <math.h>
#include <fcntl.h>
#include <limits>
#include "431project.h"
// Data structures to hold simulation result summaries.
std::pair<double, double> GLOB_baseline_EP_pair;
std::map<std::string, std::map<std::string, double>*> GLOB_extracted_values;
std::map<std::string, std::pair<double, double> > GLOB_derived_values;
std::map<std::string, unsigned int> GLOB_seen_configurations;
void printUsage() {
fprintf(stderr,
"Wrong number of arguments! Run as './DSE energy' or"
" './DSE performance' for energy or performance run, respectively\n");
}
int main(int argc, char** argv) {
std::ofstream logfile;
std::ofstream bestfile;
int optimizeforEDP = 0;
int optimizeforEXEC = 0;
srand(0); // for stability during testing
if (2 != argc) {
printUsage();
return -1;
} else {
int isEarg = ('e' == argv[1][0]);
int isParg = ('p' == argv[1][0]);
if (!(isEarg || isParg)) {
printUsage();
return -1;
} else {
system("mkdir -p logs");
system("mkdir -p summaryfiles");
system("mkdir -p rawProjectOutputData");
if (isParg) { // do performance exploration
optimizeforEXEC = 1;
logfile.open("logs/ExecutionTime.log");
bestfile.open("logs/ExecutionTime.best");
} else { // do energy-efficiency exploration
optimizeforEDP = 1;
logfile.open("logs/EnergyEfficiency.log");
bestfile.open("logs/EnergyEfficiency.best");
}
}
}
std::cout << "Testing baseline: ";
runexperiments(GLOB_baseline, 0); // generate baseline values
populate(GLOB_baseline); // read raw values from files
// Save baseline information
GLOB_baseline_EP_pair.first = calculategeomeanEDP(GLOB_baseline);
GLOB_baseline_EP_pair.second = calculategeomeanExecutionTime(GLOB_baseline);
logfile << calculategeomeanEDP(GLOB_baseline) / GLOB_baseline_EP_pair.first
<< ","
<< calculategeomeanExecutionTime(GLOB_baseline)
/ GLOB_baseline_EP_pair.second << ","
<< calculategeomeanEDP(GLOB_baseline) << ","
<< calculategeomeanExecutionTime(GLOB_baseline) << std::endl;
std::cout << std::endl;
// Prepare for main loop.
std::cout << "Starting DSE" << std::endl << std::endl;
double bestEDP = GLOB_baseline_EP_pair.first;
double bestTime = GLOB_baseline_EP_pair.second;
std::string bestTimeconfig = GLOB_baseline;
std::string bestEDPconfig = GLOB_baseline;
std::string currentConfiguration = GLOB_baseline;
for (unsigned int iter = 0; iter < 1000; ++iter) {
std::string nextconf = generateNextConfigurationProposal(
currentConfiguration, bestTimeconfig, bestEDPconfig,
optimizeforEXEC, optimizeforEDP);
if(currentConfiguration == nextconf) {
std::cerr << "returned the same configuration\n"
"FINISH\n";
break;
}
runexperiments(nextconf, iter);
populate(nextconf);
if (0
== (*(GLOB_extracted_values[nextconf]))[GLOB_prefixes[0]
+ GLOB_fields[0]]) { // quick and dirty sanity check
// run failed, try another, don't count this one
std::cout << " [failed] " << std::endl;
--iter;
continue;
}
double proposedGeoEDP = calculategeomeanEDP(nextconf);
double proposedGeoTime = calculategeomeanExecutionTime(nextconf);
double geomeanEDPNorm = proposedGeoEDP / GLOB_baseline_EP_pair.first;
double geomeanExecTimeNorm = proposedGeoTime
/ GLOB_baseline_EP_pair.second;
logfile << geomeanEDPNorm << "," << geomeanExecTimeNorm << ","
<< proposedGeoEDP << "," << proposedGeoTime << std::endl;
if (proposedGeoTime < bestTime) {
bestTimeconfig = nextconf;
bestTime = proposedGeoTime;
}
if (proposedGeoEDP < bestEDP) {
bestEDPconfig = nextconf;
bestEDP = proposedGeoEDP;
}
std::cout << std::endl << " " << "proposedGeoEDP="
<< proposedGeoEDP << ", bestEDP=" << bestEDP
<< ", proposedGeoTime=" << proposedGeoTime << ", bestTime="
<< bestTime;
// Get ready for next iteration.
std::cout << std::endl << std::endl;
currentConfiguration = nextconf;
}
// Dump best configurations stats and associated data to bestfile.
// Dump best EDP config geomean and all 5 individual benchmark stats.
bestfile << bestEDPconfig << ","
<< calculategeomeanEDP(bestEDPconfig) / GLOB_baseline_EP_pair.first
<< ","
<< calculategeomeanExecutionTime(bestEDPconfig)
/ GLOB_baseline_EP_pair.second << ","
<< calculategeomeanEDP(bestEDPconfig) << ","
<< calculategeomeanExecutionTime(bestEDPconfig) << ",";
for (int i = 0; i < 5; ++i) {
bestfile << calculateEDP(bestEDPconfig, GLOB_prefixes[i]) << ","
<< calculateEDP(bestEDPconfig, GLOB_prefixes[i])
/ calculateEDP(GLOB_baseline, GLOB_prefixes[i]) << ",";
}
bestfile << std::endl;
// Dump best Execution Time config geomean and all 5 individual benchmark stats.
bestfile << bestTimeconfig << ","
<< calculategeomeanEDP(bestTimeconfig) / GLOB_baseline_EP_pair.first
<< ","
<< calculategeomeanExecutionTime(bestTimeconfig)
/ GLOB_baseline_EP_pair.second << ","
<< calculategeomeanEDP(bestTimeconfig) << ","
<< calculategeomeanExecutionTime(bestTimeconfig) << ",";
for (int i = 0; i < 5; ++i) {
bestfile << calculateExecutionTime(bestTimeconfig, GLOB_prefixes[i])
<< ","
<< calculateExecutionTime(bestTimeconfig, GLOB_prefixes[i])
/ calculateExecutionTime(GLOB_baseline,
GLOB_prefixes[i]) << ",";
}
bestfile << std::endl;
logfile.close();
bestfile.close();
}