-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput.cpp
More file actions
214 lines (188 loc) · 4.93 KB
/
output.cpp
File metadata and controls
214 lines (188 loc) · 4.93 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
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
#include "output.h"
#include <iostream>
KmeansCluster::KmeansCluster(Point p) {
rep = p;
oldRep = p;
count = 0;
}
double ConvergenceCriteria(List<KmeansCluster> CL) {
try {
int myrank;
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
int numprocs;
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Status status;
List<double> x;
double y;
List<double> xx_0_xx;
if (CL.Size() >= 5000) {
int xx_28_xx = 0;
MPI_Bcast(&xx_28_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
CL.distributeList(numprocs);
xx_0_xx.gatherList(numprocs);
} else {
for (auto &xx_3_xx : CL.Elements()) {
auto xx_1_xx = distanceEuclidean(xx_3_xx.oldRep, xx_3_xx.rep);
xx_0_xx.AddEle(xx_1_xx);
}
}
x = xx_0_xx;
y = *(double *)(Reduce(SUM, x.Elements(), true));
return (y / CL.Size());
}
catch(std::exception &e) {
std::cout << std::string(e.what()) +" At line no. 12, function "
+ "ConvergenceCriteria in file dwarf_source_codes\/kmeans.dw" << std::endl;
}
}
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int numprocs, myrank;
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Status status;
File ff;
Point p;
List<KmeansCluster> CL;
List<Point> data;
double threshold;
double error;
int iter;
int K;
List<Point> seeds;
int xy;
try{
ff.ReadDataset("datasets/3droad.arff", &data);
int xx_31_xx = -2;
MPI_Bcast(&xx_31_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
data.broadcastList(numprocs);
K = 100;
List<Point> xx_4_xx;
if ((K - 1) - (0) >= 5000) {
int xx_32_xx = 1;
MPI_Bcast(&xx_32_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
List<int> xx_8_xx;
int xx_9_xx = 0;
int xx_10_xx = K - 1;
xx_8_xx.distributeRangeList(xx_9_xx , xx_10_xx, numprocs);
xx_4_xx.gatherList(numprocs);
} else {
for (int xx_7_xx = 0; xx_7_xx <= K - 1; xx_7_xx++) {
auto xx_5_xx = data.GetEleAtIndex(xx_7_xx);
xx_4_xx.AddEle(xx_5_xx);
}
}
seeds = xx_4_xx;
List<KmeansCluster> xx_14_xx;
if ((K - 1) - (0) >= 5000) {
int xx_35_xx = 2;
MPI_Bcast(&xx_35_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
List<int> xx_18_xx;
seeds.broadcastList(numprocs);
int xx_19_xx = 0;
int xx_20_xx = K - 1;
xx_18_xx.distributeRangeList(xx_19_xx , xx_20_xx, numprocs);
xx_14_xx.gatherList(numprocs);
} else {
for (int xx_17_xx = 0; xx_17_xx <= K - 1; xx_17_xx++) {
auto xx_15_xx = KmeansCluster(seeds.GetEleAtIndex(xx_17_xx));
xx_14_xx.AddEle(xx_15_xx);
}
}
CL = xx_14_xx;
threshold = 0.5;
std::cout << "Number of points:" << data.Size() << "\nK :" << K << "\nError threshold :" << threshold << std::endl;
std::cout << "\nseeds:" << seeds << std::endl;
error = 100.0;
iter = 0;
while(error > threshold) {
if (CL.Size() >= 5000) {
int xx_38_xx = 3;
MPI_Bcast(&xx_38_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
CL.distributeList(numprocs);
CL.gatherList(numprocs);
} else {
for( auto &clus : CL.Elements()) {
int a;
clus.count = 0;
clus.oldRep = clus.rep;
a = clus.rep.InitializePoint();
}
}
if (data.Size() >= 5000) {
int xx_40_xx = 4;
MPI_Bcast(&xx_40_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
CL.broadcastList(numprocs);
HashMap<Point> xx_41_xx= HashMap<Point>();
HashMap<int> xx_42_xx= HashMap<int>();
for (int xx_43_xx = 1; xx_43_xx < numprocs; xx_43_xx++){
xx_41_xx = xx_41_xx.deserializeRecv(xx_43_xx);
for( auto iterator = xx_41_xx.htmap.begin(); iterator != xx_41_xx.htmap.end(); iterator++) {
uint index = iterator->first;
CL[index].rep += xx_41_xx.htmap[index];
}
}
for (int xx_44_xx = 1; xx_44_xx < numprocs; xx_44_xx++){
xx_42_xx = xx_42_xx.deserializeRecv(xx_44_xx);
for( auto iterator = xx_42_xx.htmap.begin(); iterator != xx_42_xx.htmap.end(); iterator++) {
uint index = iterator->first;
CL[index].count += xx_42_xx.htmap[index];
}
}
} else {
for( auto &i : data.Elements()) {
int xx_26_xx;
int index;
double xx_25_xx;
double xx_24_xx;
int xx_27_xx;
xx_24_xx = 0.0;
xx_25_xx = DBL_MAX;
xx_26_xx = -1;
xx_27_xx = 0;
for( auto &CC : CL.Elements()) {
xx_24_xx = distanceEuclidean(i, CC.oldRep);
if(xx_24_xx < xx_25_xx) {
KmeansCluster CC;
xx_25_xx = xx_24_xx;
xx_26_xx = xx_27_xx;
}
xx_27_xx = xx_27_xx + 1;
}
index = xx_26_xx;
CL.GetEleAtIndex(index).rep = CL.GetEleAtIndex(index).rep + i;
CL.GetEleAtIndex(index).count = CL.GetEleAtIndex(index).count + 1;
}
}
if (CL.Size() >= 5000) {
int xx_51_xx = 5;
MPI_Bcast(&xx_51_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
CL.distributeList(numprocs);
CL.gatherList(numprocs);
} else {
for( auto &clus : CL.Elements()) {
Point sum;
sum = clus.rep;
if(clus.count != 0) {
clus.rep = sum / clus.count;
}
}
}
error = ConvergenceCriteria(CL);
}
std::cout << "\nClustering Results: " << std::endl;
xy = 0;
for( auto &c : CL.Elements()) {
xy = xy + 1;
std::cout << "\nCluster: " << xy << ", Members: " << c.count << ", Centroid:" << c.rep << std::endl;
}
}
catch(std::exception &e) {
std::cout << std::string(e.what()) +" At line no. 0, function"
+ "" << std::endl;
}
int xx_53_xx = -1;
MPI_Bcast(&xx_53_xx, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}