-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_helpers.cpp
More file actions
153 lines (141 loc) · 7.17 KB
/
debug_helpers.cpp
File metadata and controls
153 lines (141 loc) · 7.17 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
#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#include "MIS_parallel.h"
#include <fstream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <sstream>
#include "status.h"
#include <iostream>
#include "debug_helpers.h"
//-----------------------------------------------------------------------------------------------------------------------------
////-----------------------------------------------------------------------------------------------------------------------------
////---------module_name:::showNodesStatus
////---------functionlity:::shows the status of the nodes
////-----------------------------------------------------------------------------------------------------------------------------
////-----------------------------------------------------------------------------------------------------------------------------
void showNodesInfo(int *nodesStatus, float *nodeRandValues, int nodeArraySize, string request){
//this veriable determines whether we want tow show the complete name of the status or just numbers
bool showFullStatusName = true;
//change the following if status.h changed
//show status
if (request == "status") {
cout<<"***********************************************";
cout<<"showing all the nodes status was requests"<<endl;
string nodeStatusString[3] = {"INACTIVE", "ACTIVE", "SELECTED"};
for (int i = 0; i< nodeArraySize; i++){
if(showFullStatusName) {
cout<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
}else{
cout<<"node "<< i + 1 << "th status is: " << nodesStatus[i]<<endl;
}
}
cout<<"***********************************************";
}
//show rand values
else if (request == "randValues") {
cout<<"***********************************************";
cout<<"showing all the nodes rand values was requests"<<endl;
for (int i = 0; i< nodeArraySize; i++){
cout<<"node "<< i + 1<< "th status is: " << nodeRandValues[i]<<endl;
}
cout<<"***********************************************";
}
//show all the info
else if (request == "all") {
//showNodesInfo(nodesStatus, nodeRandValues, nodeArraySize, "status");
//showNodesInfo(nodesStatus, nodeRandValues, nodeArraySize, "randValues");
cout<<"***********************************************";
cout<<"showing all the nodes status was requests"<<endl;
string nodeStatusString[3] = {"INACTIVE", "ACTIVE", "SELECTED"};
for (int i = 0; i< nodeArraySize; i++){
cout <<"node "<< i + 1 << ":\t" << nodeStatusString[nodesStatus[i]] << "\t" << nodeRandValues[i] << "\t" << nodesStatus[i] << endl;
}
cout<<"***********************************************";
}
else {
cout<< "this information is not applicable"<<endl;
}
}
//-----------------------------------------------------------------------------------------------------------------------------
////-----------------------------------------------------------------------------------------------------------------------------
////---------module_name::: writeToFileInfo
////---------functionlity::: writes the status of the nodes to the file
////-----------------------------------------------------------------------------------------------------------------------------
////-----------------------------------------------------------------------------------------------------------------------------
void writeToFileNodeInfo(int *nodesStatus, float *nodeRandValues, int nodeArraySize, string fileName, string request){
//open the file
ofstream myfile;
myfile.open (fileName.c_str(), std::ios_base::app);
//this veriable determines whether we want to show the complete name of the status or just numbers
bool showFullStatusName = true;
//change the following if status.h changed
//show status
if (request == "status") {
myfile<<"***********************************************"<<endl;
myfile<<"showing all the nodes status was requests"<<endl;
string nodeStatusString[3] = {"INACTIVE", "ACTIVE", "SELECTED"};
for (int i = 0; i< nodeArraySize; i++){
if(showFullStatusName) {
myfile<<"node "<< i + 1 << "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
}else{
myfile<<"node "<< i + 1<< "th status is: " << nodesStatus[i]<<endl;
}
}
myfile<<"***********************************************"<<endl;;
myfile<< "status:" << " ";
for (int i = 0; i< nodeArraySize; i++){
if(showFullStatusName) {
//myfile<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
myfile<< nodeStatusString[nodesStatus[i]]<< " ";
}
}
myfile << endl;
}
//show rand values
else if (request == "randValues") {
myfile<<"***********************************************"<<endl;;
myfile<<"showing all the nodes rand values was requests"<<endl;
for (int i = 0; i< nodeArraySize; i++){
//myfile<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
myfile<<"node "<< i + 1<< "rand value is: " << nodeRandValues[i] << endl;
}
myfile<<"***********************************************"<<endl;
myfile<< "randValues:" << " ";
for (int i = 0; i< nodeArraySize; i++){
//myfile<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
myfile<< nodeRandValues[i] << " ";
}
myfile<< endl;
myfile<<"***********************************************"<<endl;;
}
//show all the info
//
else if (request == "all") {
writeToFileNodeInfo(nodesStatus, nodeRandValues, nodeArraySize, fileName, "status");
writeToFileNodeInfo(nodesStatus, nodeRandValues, nodeArraySize, fileName, "randValues");
// cout << "the file name is" << fileName;
// string nodeStatusString[3] = {"INACTIVE", "ACTIVE", "SELECTED"};
// myfile<<"***********************************************"<<endl;;
// myfile<<"showing all the nodes rand values was requests"<<endl;
// for (int i = 0; i< nodeArraySize; i++){
// //myfile<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
// myfile<<"node "<< i + 1 << ":\t" << nodeStatusString[nodesStatus[i]] << "\t" << nodeRandValues[i] << "\t" << nodesStatus[i] << endl;
// }
// myfile<<"***********************************************"<<endl;
// myfile<< "randValues:" << " ";
// for (int i = 0; i< nodeArraySize; i++){
// //myfile<<"node "<< i + 1<< "th status is: " << nodeStatusString[nodesStatus[i]]<<endl;
// myfile<< nodeRandValues[i] << " ";
// }
// myfile<< endl;
// myfile<<"***********************************************"<<endl;;
}else {
myfile<< "this information is not applicable"<<endl;
}
//closing the file
myfile.close();
}