Newer
Older
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**
* @file MpiUncertainty_exc.cc
* @brief The MpiUncertainty BarbequeRTRM application
*
* Description: to be done...
*
* @author Name Surname (nickname), your@email.com
*
* Company Your Company
* Copyright Copyright (c) 20XX, Name Surname
*
* This source code is released for free distribution under the terms of the
* GNU General Public License as published by the Free Software Foundation.
* =====================================================================================
*/
#include "MpiUncertainty_exc.h"
#include <cstdio>
#include <bbque/utils/utility.h>
#include <bbque/monitors/operating_point.h>
#include <unistd.h>
#include <mpi.h>
#include <omp.h>
#include "MatData.h"
#include "easylogging++.h"
namespace ba = bbque::rtlib::as;
extern ba::OperatingPointsList opList;
extern ba::OperatingPointsList opList2;
#define _ELPP_THREAD_SAFE
_INITIALIZE_EASYLOGGINGPP
MpiUncertainty::MpiUncertainty(std::string const & name,
std::string const & uncertaintyConfigXmlPath,
std::string const & recipe,
RTLIB_Services_t *rtlib) :
BbqueEXC(name, recipe, rtlib),
m_configXmlPath(uncertaintyConfigXmlPath) {
logger->Warn("New MpiUncertainty::MpiUncertainty()");
// NOTE: since RTLib 1.1 the derived class construct should be used
// mainly to specify instantiation parameters. All resource
// acquisition, especially threads creation, should be palced into the
// new onSetup() method.
logger->Info("EXC Unique IDentifier (UID): %u", GetUid());
}
RTLIB_ExitCode_t MpiUncertainty::onSetup() {
// This is just an empty method in the current implementation of this
// testing application. However, this is intended to collect all the
// application specific initialization code, especially the code which
// acquire system resources (e.g. thread creation)
logger->Warn("MpiUncertainty::onSetup()");
// UNCERTAINTY LOGGER SETTINGS ////////////////////////////////////////////////////////////////
/* Init logger */
//_START_EASYLOGGINGPP();
/* Logger configuration */
// Change default format
el::Configurations defaultConf;
defaultConf.setToDefault();
defaultConf.setGlobally(el::ConfigurationType::Format, "%level [%logger] %msg");
//defaultConf.set(el::Level::Debug, el::ConfigurationType::Format, "%level [%logger] %msg");
el::Loggers::addFlag(el::LoggingFlag::HierarchicalLogging);
el::Loggers::reconfigureLogger("default", defaultConf);
// Register logger for model
el::Loggers::getLogger("model");
el::Loggers::reconfigureLogger("model", defaultConf);
// Register logger for montecarlo
el::Loggers::getLogger("montecarlo");
el::Loggers::reconfigureLogger("montecarlo", defaultConf);
// Load configuration for QoS modes and logger
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(m_configXmlPath.c_str());
if (result.status != pugi::status_ok)
{
// Config file load unsuccesfull
LOG(FATAL) << "Configuration load result: " << std::string(result.description());
std::exit(EXIT_FAILURE);
}
else
{
// Initialize values for QoS modes
m_jobsNumber[0] = doc.child("conf").child("uncertainity").child("params").child("mcCount").text().as_int();
m_timeFrame[0] = doc.child("conf").child("uncertainity").child("params").child("timeframe").text().as_int();
m_jobsNumber[1] = doc.child("conf").child("uncertainity").child("params").child("mcCount1").text().as_int();
m_timeFrame[1] = doc.child("conf").child("uncertainity").child("params").child("timeframe1").text().as_int();
m_jobsNumber[2] = doc.child("conf").child("uncertainity").child("params").child("mcCount2").text().as_int();
m_timeFrame[2] = doc.child("conf").child("uncertainity").child("params").child("timeframe2").text().as_int();
m_jobsNumber[3] = doc.child("conf").child("uncertainity").child("params").child("mcCount3").text().as_int();
m_timeFrame[3] = doc.child("conf").child("uncertainity").child("params").child("timeframe3").text().as_int();
// Set loglevel
std::string loglevel = doc.child("conf").child("math1D").child("logLevel").text().as_string();
#ifdef DEBUG
el::Loggers::setLoggingLevel(el::Level::Debug);
#else
if(loglevel == "DEBUG") el::Loggers::setLoggingLevel(el::Level::Debug);
else if(loglevel == "INFO") el::Loggers::setLoggingLevel(el::Level::Info);
else if(loglevel == "WARNING") el::Loggers::setLoggingLevel(el::Level::Warning);
else if(loglevel == "ERROR") el::Loggers::setLoggingLevel(el::Level::Error);
else LOG(WARNING) << "Unknown logging level " << loglevel << " selected!";
#endif
}
/////////////////////////////////////////////////////////////////////////////////////////////////
LOG(INFO) << "Math1D Model";
/* MPI Initialize */
MPI::Init();//argc, argv);
if(MPI::Is_initialized())
{
logger->Info("MPI Initialized");
} else {
logger->Warn("MPI was not initialized");
std::exit(-1);
}
int rank = -1, numProc = -1; // Holds rank of current process and total number of processes
MPI_Comm_size(MPI_COMM_WORLD, &numProc);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// Do the first run of the model
std::shared_ptr<math1d_cl::MatData> matData = std::make_shared<math1d_cl::MatData>(m_configXmlPath);
matData->runRR();
// Check FWL within simulated values in measured stations and select QoS mode according current situation (FWL)
m_qosMode = matData->checkFWL();
logger->Warn("QoS mode %d selected (%d MC samples, %d sec)", m_qosMode, m_jobsNumber[m_qosMode], m_timeFrame[m_qosMode]);
// Start timer
m_timer.start();
// // REMOVE
// MPI_Barrier(MPI_COMM_WORLD);
// Generate samples
m_uncertainty = std::unique_ptr<math1d_cl::Uncertainity>(new math1d_cl::Uncertainity(m_configXmlPath, matData, m_jobsNumber[m_qosMode]));
m_uncertainty->Initialize();
return RTLIB_OK;
}
RTLIB_ExitCode_t MpiUncertainty::onConfigure(uint8_t awm_id) {
logger->Warn("MpiUncertainty::onConfigure(): EXC [%s] => AWM [%02d]",
exc_name.c_str(), awm_id);
// Extracting parameters
if(rpc_name == "MpiUncertainty")
m_threadsNumber = opList[awm_id].parameters["threads"];
else if(rpc_name == "MpiUncertainty2")
m_threadsNumber = opList2[awm_id].parameters["threads"];
// add more recipes and oplists
m_uncertainty->CreateModels(m_threadsNumber);
logger->Warn("[onConfigure]: Configured with <threads>: <%d> via %s recipe",
m_threadsNumber, rpc_name.c_str());
return RTLIB_OK;
}
RTLIB_ExitCode_t MpiUncertainty::onRun() {
RTLIB_WorkingModeParams_t const wmp = WorkingModeParams();
// Return after all jobs done
if(m_jobsDone >= m_jobsNumber[m_qosMode])
return RTLIB_EXC_WORKLOAD_NONE;
// Do one more cycle
logger->Warn("MpiUncertainty::onRun() : EXC [%s] @ AWM [%02d]",
exc_name.c_str(), wmp.awm_id);
// Set number of OMP threads to uncertainty and simulate given chunk of MC samples
m_uncertainty->RunMC(m_threadsNumber);
m_jobsDone += m_threadsNumber;
logger->Warn("%d Monte Carlo samples computed, %d out of %d in total", m_threadsNumber, m_jobsDone, m_jobsNumber[m_qosMode]);
// Compute the average time required to simulate one MC sample
m_avgTimePerSimulation = m_timer.getElapsedTimeMs() / m_jobsDone;
// or ???
// m_avgTimePerSimulation = timePerOnRun / m_tthreadsNumber;
return RTLIB_OK;
}
RTLIB_ExitCode_t MpiUncertainty::onMonitor() {
RTLIB_WorkingModeParams_t const wmp = WorkingModeParams();
logger->Warn("MpiUncertainty::onMonitor() : EXC [%s] @ AWM [%02d], Cycle [%4d]",
exc_name.c_str(), wmp.awm_id, Cycles());
// Compute time required to simulate the remaining number of MC samples at a current speed
double timeRequired = (m_jobsNumber[m_qosMode] - m_jobsDone) * m_avgTimePerSimulation;
double estimatedTotalTime = timeRequired + m_timer.getElapsedTimeMs();
// If this remaining time plus the actual total execution time exceeds the time slot limit
// defined by the QoS mode, the higher AWM is requested
if((estimatedTotalTime) > m_timeFrame[m_qosMode] * 1000.0)
{
int goalGap = (1 - (estimatedTotalTime / timeRequired - 1)) * 100;
logger->Warn("MpiUncertainty::onMonitor() : Requesting higher AWM, gap is %d", goalGap);
SetGoalGap(goalGap);
} else
logger->Warn("MpiUncertainty::onMonitor() : Current AWM is OK");
// Exploit less threads if less jobs remain
if ( m_jobsNumber[m_qosMode] - m_jobsDone < m_threadsNumber )
m_threadsNumber = m_jobsNumber[m_qosMode] - m_jobsDone;
return RTLIB_OK;
}
RTLIB_ExitCode_t MpiUncertainty::onRelease() {
// Collect results
m_uncertainty->CollectResults();
logger->Warn("MpiUncertainty::onRelease() : exit");
return RTLIB_OK;
}