-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcluster_architecture.cpp
356 lines (308 loc) · 12.5 KB
/
cluster_architecture.cpp
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#include "cluster_architecture.h"
#include "database_thread.h"
Cluster_Architecture::Cluster_Architecture(QObject *parent) : QObject(parent) {
}
Cluster_Architecture::~Cluster_Architecture()
{
if (database_thread.isRunning()) {
if (database_thread.isRunning()) {
// Signal zum Beenden des Threads senden
m_dbThread->set_thread_running(false);
emit signalToClearDB();
database_thread.quit(); // Veranlasst den Thread, die Ereignisschleife zu verlassen
database_thread.wait(); // Wartet, bis der Thread beendet ist
delete m_dbThread;
}
//delete database_thread; // Löscht den Thread, nachdem er beendet wurde
//database_thread = nullptr;
}
}
void Cluster_Architecture::initialize(QString db_connection, bool live){
m_connectionName = db_connection;
m_live_run = live;
}
void Cluster_Architecture::resetCluster_Architecture(){
if (database_thread.isRunning()) {
if (database_thread.isRunning()) {
// Signal zum Beenden des Threads senden
emit signalToClearDB();
database_thread.quit(); // Veranlasst den Thread, die Ereignisschleife zu verlassen
database_thread.wait(); // Wartet, bis der Thread beendet ist
delete m_dbThread;
}
//delete database_thread; // Löscht den Thread, nachdem er beendet wurde
//database_thread = nullptr;
}
m_componentsBuilt = false;
m_nodes.clear();
m_p2p_send_max = 0;
m_coll_send_max = 0;
m_p2p_recv_max = 0;
m_coll_recv_max = 0;
m_time_display = 0;
m_start_timestamp = QDateTime();
m_slurm_id = 0;
m_proc_num = 0;
m_status_running=false;
m_end_time = 0;
}
void Cluster_Architecture::setOption(int opt){
std::cout << "setOption" << std::endl;
m_option = opt;
}
void Cluster_Architecture::startThread(){
if(!QSqlDatabase::contains(m_connectionName)) {
qDebug() << "Connection " << m_connectionName << " does not exist.";
return;
}
QString name_helper = "Thread_%1";
QSqlDatabase db = QSqlDatabase::database(m_connectionName);
if (!db.isOpen()) {
qDebug() << "Databaseconnection " << m_connectionName << " is not open";
return;
}
QString thread_connection_name = name_helper.arg(m_slurm_id);
m_dbThread = new Database_Thread(thread_connection_name, m_slurm_id, m_proc_num, m_live_run);
m_dbThread->moveToThread(&database_thread);
//clone_db.moveToThread(&database_thread);
//m_dbThread->moveToThread(dbThread);
Database_Thread::connect(m_dbThread, &Database_Thread::clusterComponentsReady, this, &Cluster_Architecture::buildClusterComponents);
Database_Thread::connect(this, &Cluster_Architecture::signalToDBConnection, m_dbThread, &Database_Thread::connectToDB);
Database_Thread::connect(this, &Cluster_Architecture::startDatabaseThread, m_dbThread, &Database_Thread::threadbuildClusterComponents);
Database_Thread::connect(this, &Cluster_Architecture::signalToUpdateData, m_dbThread, &Database_Thread::updateData);
Database_Thread::connect(m_dbThread, &Database_Thread::updateDataReady, this, &Cluster_Architecture::updateDataToUI);
Database_Thread::connect(this, &Cluster_Architecture::signalToClearDB, m_dbThread, &Database_Thread::clearDatabase);
Database_Thread::connect(m_dbThread, &Database_Thread::dbCleared, this, &Cluster_Architecture::removeClusterComponents);
Database_Thread::connect(this, &Cluster_Architecture::signalToShowTimestampData, m_dbThread, &Database_Thread::showDataFromTimePeriod);
Database_Thread::connect(m_dbThread, &Database_Thread::setTimestamp, this, &Cluster_Architecture::handleTimestamp);
Database_Thread::connect(this, &Cluster_Architecture::waitForEnd, m_dbThread, &Database_Thread::selectEndTimestamp);
Database_Thread::connect(this, &Cluster_Architecture::end_timeChanged, m_dbThread, &Database_Thread::set_end_timestamp_db);
Database_Thread::connect(this, &Cluster_Architecture::reset_bottom_bar, m_dbThread, &Database_Thread::reset_actual_timestamp);
Database_Thread::connect(m_dbThread, &Database_Thread::updateDetailedP2P, &m_detailed_p2p, &Detailed_p2p_data::queryData);
Database_Thread::connect(m_dbThread, &Database_Thread::updateDetailedColl, &m_detailed_coll, &Detailed_coll_data::queryData);
//database_thread.start();
database_thread.start();
}
void Cluster_Architecture::buildClusterComponents(const QMap<QString, QVector<int>> &map){
//std::cout << "componentsBuilt 1!" << std::endl;
if(m_option!=0){
std::cout << "m_option NULL Fehler, " << m_option << std::endl;
return;
}
Cluster_Node *node;
if(map.isEmpty()){
std::cout << "Build Cluster Compoenents failed!" << std::endl;
} else{
QMapIterator<QString, QVector<int>> iter(map);
while(iter.hasNext()){
iter.next();
//std::cout << "Iter-Key: " << iter.key().toStdString() << std::endl;
node = new Cluster_Node(this, iter.key().toUtf8().constData());
m_nodes << node;
for(int i = 0; i<iter.value().length(); i++){
Cluster_Rank *rank = new Cluster_Rank(node, iter.value()[i]);
node->addRank(rank);
//std::cout << rank->getId() << std::endl;
}
}
}
//if(m_live_run){
//timerId = startTimer(1000);
emit signalToUpdateData(m_time_display);
//}
emit componentsBuilt();
//std::cout << "componentsBuilt 2!" << std::endl;
m_componentsBuilt = true;
}
void Cluster_Architecture::removeClusterComponents(){
m_nodes.clear();
timerId = -1;
std::cout << "Removed Cluster-Components" << std::endl;
}
int Cluster_Architecture::count() const{
return this->m_nodes.count();
}
long Cluster_Architecture::coll_send_max(){
return m_coll_send_max;
}
long Cluster_Architecture::p2p_send_max(){
return m_p2p_send_max;
}
long Cluster_Architecture::coll_recv_max(){
return m_coll_recv_max;
}
long Cluster_Architecture::p2p_recv_max(){
return m_p2p_recv_max;
}
int Cluster_Architecture::slurm_id(){
return m_slurm_id;
}
int Cluster_Architecture::proc_num(){
return m_proc_num;
}
int Cluster_Architecture::end_time(){
return m_end_time;
}
void Cluster_Architecture::set_coll_send_max(long max){
m_coll_send_max = max;
emit coll_send_max_changed();
}
void Cluster_Architecture::set_p2p_send_max(long max){
m_p2p_send_max = max;
emit p2p_send_max_changed();
}
void Cluster_Architecture::set_coll_recv_max(long max){
m_coll_recv_max = max;
emit coll_recv_max_changed();
}
void Cluster_Architecture::set_p2p_recv_max(long max){
m_p2p_recv_max = max;
emit p2p_recv_max_changed();
}
void Cluster_Architecture::set_slurm_id(int id){
m_slurm_id = id;
//qDebug() << "set_slurm_id";
startThread();
emit signalToDBConnection();
emit startDatabaseThread();
}
void Cluster_Architecture::set_proc_num(int proc){
m_proc_num = proc;
emit proc_num_changed();
}
void Cluster_Architecture::set_end_time(int time){
if(time == -1){
QThread::msleep(2000);
m_dbThread->set_thread_running(false);
} else {
m_end_time = time;
QDateTime timestamp = m_start_timestamp.addSecs(time);
emit end_timeChanged(timestamp);
}
}
Cluster_Node* Cluster_Architecture::nodeAt(int index){
if(index<0 || index>=m_nodes.count()){
return 0;
}
return this->m_nodes[index];
}
QVector<Cluster_Node*> Cluster_Architecture::get_nodeList(){
return m_nodes;
}
void Cluster_Architecture::updateDataToUI(const QList<DataColumn> &list){
if(!m_componentsBuilt){
return;
}
for (Cluster_Node *n : m_nodes){
for(Cluster_Rank *r : n->ranks()){
r->set_coll_recvDatasize(0);
r->set_coll_sendDatasize(0);
r->set_p2p_recvDatasize(0);
r->set_p2p_sendDatasize(0);
r->set_p2p_late_sender(0);
r->set_p2p_late_recvr(0);
r->set_coll_late_sender(0);
r->set_coll_late_recvr(0);
r->set_p2p_timediff(0);
r->set_coll_timediff(0);
}
}
set_p2p_recv_max(0);
set_p2p_send_max(0);
set_coll_send_max(0);
set_coll_recv_max(0);
QString name = m_nodes[0]->getName();
int index = 0;
for(int i = 0; i<list.count(); i++){
DataColumn dc = list[i];
if(name != dc.proc_name){
//std::cout << "test" << std::endl;
for(int i=0; i<this->m_nodes.count(); i++){
if (this->m_nodes[i]->getName()==dc.proc_name){
name = dc.proc_name;
index = i;
break;
}
}
}
if(dc.comm_type=="p2p"){
if(dc.send_datasize>m_p2p_send_max){
set_p2p_send_max(dc.send_datasize);
}
if(dc.recv_datasize>m_p2p_recv_max){
set_p2p_recv_max(dc.recv_datasize);
}
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_p2p_sendDatasize(dc.send_datasize);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_p2p_recvDatasize(dc.recv_datasize);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_p2p_late_sender(dc.late_sender);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_p2p_late_recvr(dc.late_receiver);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_p2p_timediff(dc.time_diff);
} else if(dc.comm_type=="collective"){
if(dc.send_datasize>m_coll_send_max){
set_coll_send_max(dc.send_datasize);
}
if(dc.recv_datasize>m_coll_recv_max){
set_coll_recv_max(dc.recv_datasize);
}
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_coll_sendDatasize(dc.send_datasize);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_coll_recvDatasize(dc.recv_datasize);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_coll_late_sender(dc.late_sender);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_coll_late_recvr(dc.late_receiver);
this->m_nodes[index]->rankAt(dc.proc_rank-this->m_nodes[index]->getSmalestRankId())->set_coll_timediff(dc.time_diff);
} else{
std::cerr << "The communication_type " << dc.comm_type.toStdString() << " is unknown!" << std::endl;
}
}
return;
}
void Cluster_Architecture::timerEvent(QTimerEvent* event){
if(m_componentsBuilt){
//std::cout << "timer:Event, TRUE!" << std::endl;
emit signalToUpdateData(m_time_display);
}
//updateDatasize();
//emit r
//std::cout << "Name: " << m_nodes[0]->getName().toStdString() << std::endl;
}
//Functionality for timeline
void Cluster_Architecture::startAndStop(bool start){
if(!m_componentsBuilt){
return;
}
if(start == true){
if(timerId != -1){
std::cout << "Kill Timer" << std::endl;
killTimer(timerId);
}
} else{
timerId = startTimer(1000);
}
}
void Cluster_Architecture::handleTimestamp(QDateTime timestamp, bool start){
QTime qtimeTimestamp;
int seconds;
if(start){
std::cout << "Start-Timestamp: " << timestamp.toString("yyyy-MM-d HH:mm:ss").toStdString() << std::endl;
m_start_timestamp = timestamp;
} else {
std::cout << "End-Timestamp: " << timestamp.toString("yyyy-MM-d HH:mm:ss").toStdString() << std::endl;
}
qtimeTimestamp = timestamp.time();
QTime midnight;
midnight.setHMS(0,0,0);
seconds = midnight.secsTo(qtimeTimestamp);
emit dataIn(seconds, qtimeTimestamp, start);
}
void Cluster_Architecture::showConditionAt(int timeSecondsA, int timeSecondsB){
QDateTime timestampA = m_start_timestamp.addSecs(timeSecondsA);
QDateTime timestampB = m_start_timestamp.addSecs(timeSecondsB);
//std::cout << "Timestamp A: " << timestampA.toString("hh:mm:ss").toStdString() << std::endl;
//std::cout << "Timestamp B: " << timestampB.toString("hh:mm:ss").toStdString() << std::endl;
emit signalToShowTimestampData(timestampA, timestampB);
}
Detailed_p2p_data* Cluster_Architecture::detailedP2P() {
return &m_detailed_p2p;
}
Detailed_coll_data* Cluster_Architecture::detailedColl() {
return &m_detailed_coll;
}