-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_client.cpp
350 lines (256 loc) · 11.3 KB
/
test_client.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
#include <kommclient.h>
#include <thallium.hpp>
#include <mpi.h>
#include <chrono>
void bench1(int bench_rounds, int argc, char** argv) {
double total_time = 0.0;
MPI_Init(&argc, &argv);
int my_rank = 0, size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
std::chrono::high_resolution_clock::time_point start_t, end_t;
unsigned int tsum = 0, loop_rank = my_rank * 16777216;
struct stat ts;
// START THREAD TIME MEASSUREMENT
MPI_Barrier(MPI_COMM_WORLD);
start_t = std::chrono::high_resolution_clock::now();
// 4 OPS PER LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
int tufd = komm_open(tf);
komm_close(tufd);
komm_stat(tf, &ts);
komm_unlink(tf);
}
//STOP THREAD TIME MEASSUREMENT
end_t = std::chrono::high_resolution_clock::now();
MPI_Barrier(MPI_COMM_WORLD);
std::chrono::duration<double> elapsed_time = std::chrono::duration_cast<std::chrono::duration<double>>(end_t - start_t);
double elapsed_time_int = elapsed_time.count();
MPI_Reduce(&elapsed_time_int, &total_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
std::cout << "THREAD: " << my_rank << ", THREAD TIME: " << elapsed_time.count() << std::endl;
if (my_rank == 0) {
std::cout << "TOTAL TIME: " << total_time << std::endl;
std::cout << "TOTAL OPS: " << bench_rounds * size * 4 << std::endl;
std::cout << "CALC SPEED: " << bench_rounds * size * 4 / total_time << " ops/s" << std::endl;
}
}
void bench2(int transfer_size_in_kib, int argc, char** argv) {
double total_time = 0.0;
MPI_Init(&argc, &argv);
int my_rank = 0, size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
// CREATE WRITE BULK
std::string s_write_bulk_content(transfer_size_in_kib * 1024, 'A');
const char* write_bulk_content = s_write_bulk_content.c_str();
std::size_t write_bulk_size = std::strlen(write_bulk_content);
// CREATE READ BULK
void* read_bulk_content = new char[transfer_size_in_kib * 1024];
// SETUP
std::chrono::high_resolution_clock::time_point start_t, end_t;
const char* f_path = (std::string("tft" + std::to_string(my_rank) + "c")).c_str();
int ufd = komm_open(f_path);
std::cout << f_path << std::endl;
std::cout << ufd << std::endl;
// START THREAD TIME MEASSUREMENT
MPI_Barrier(MPI_COMM_WORLD);
start_t = std::chrono::high_resolution_clock::now();
// WRITE BULK
int write_ret = komm_pwrite(ufd, write_bulk_content, write_bulk_size, 0);
// READ BULK
int read_ret = komm_pread(ufd, read_bulk_content, write_bulk_size, 0);
// STOP THREAD TIME MEASSUREMENT
end_t = std::chrono::high_resolution_clock::now();
MPI_Barrier(MPI_COMM_WORLD);
// CLOSE, UNLINK
int close_ret = komm_close(ufd);
int unlink_ret = komm_unlink(f_path);
// COMPARE READ WRITE CONTENT SIZE
if (write_ret == read_ret) {
std::cout << "T" << my_rank << ": READ WRITE SIZE MATCH" << std::endl;
}
else {
std::cout << "T" << my_rank << ": READ WRITE SIZE MISMATCH" << std::endl;
std::cout << "T" << my_rank << ": READ SIZE " << read_ret << std::endl;
std::cout << "T" << my_rank << ": WRITE SIZE " << write_ret << std::endl;
}
// COMPARE READ WRITE CONTENT
if (std::strcmp(write_bulk_content, static_cast<const char*>(read_bulk_content)) == 0) {
std::cout << "T" << my_rank << ": READ WRITE CONTENT MATCH" << std::endl;
}
else {
std::cout << "T" << my_rank << ": READ WRITE CONTENT MISMATCH" << std::endl;
std::cout << "T" << my_rank << ": WRITE LAST 100 CHAR: " << write_bulk_content + (std::strlen(write_bulk_content) - 100) << std::endl;
const char* read_bulk_convserion = static_cast<const char*>(read_bulk_content);
std::cout << "T" << my_rank << ": READ LAST 100 CHAR: " << read_bulk_convserion + (std::strlen(read_bulk_convserion) - 100) << std::endl;
}
// MiB CALC
std::chrono::duration<double> elapsed_time = std::chrono::duration_cast<std::chrono::duration<double>>(end_t - start_t);
double elapsed_time_int = elapsed_time.count();
MPI_Reduce(&elapsed_time_int, &total_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
if (my_rank == 0) {
std::cout << "TOTAL TIME: " << total_time << " s" << std::endl;
std::cout << "TOTAL MiB: " << transfer_size_in_kib * 2.00 * size / 1024 << std::endl;
std::cout << "TRANSFER SPEED: " << transfer_size_in_kib * 2 * size / 1024 / total_time << " MiB/s" << std::endl;
}
}
void bench3(int bench_rounds, int argc, char** argv) {
double total_time = 0.0;
MPI_Init(&argc, &argv);
int my_rank = 0, size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
std::chrono::high_resolution_clock::time_point start_t, end_t;
unsigned int tsum = 0, loop_rank = my_rank * 16777216;
int ufds[bench_rounds];
const char* paths[bench_rounds];
struct stat ts;
// START THREAD TIME MEASSUREMENT
MPI_Barrier(MPI_COMM_WORLD);
start_t = std::chrono::high_resolution_clock::now();
// OPEN LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
ufds[i] = komm_open(tf);
paths[i] = tf;
}
//STOP THREAD TIME MEASSUREMENT
end_t = std::chrono::high_resolution_clock::now();
MPI_Barrier(MPI_COMM_WORLD);
// CLOSE, DEL LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
komm_close(ufds[i]);
komm_unlink(paths[i]);
}
std::chrono::duration<double> elapsed_time = std::chrono::duration_cast<std::chrono::duration<double>>(end_t - start_t);
double elapsed_time_int = elapsed_time.count();
MPI_Reduce(&elapsed_time_int, &total_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
std::cout << "THREAD: " << my_rank << ", THREAD TIME: " << elapsed_time.count() << std::endl;
if (my_rank == 0) {
std::cout << "TOTAL TIME: " << total_time << std::endl;
std::cout << "TOTAL OPS: " << bench_rounds * size << std::endl;
std::cout << "CALC SPEED: " << bench_rounds * size / total_time << " ops/s" << std::endl;
}
}
void bench4(int bench_rounds, int argc, char** argv) {
double total_time = 0.0;
MPI_Init(&argc, &argv);
int my_rank = 0, size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
std::chrono::high_resolution_clock::time_point start_t, end_t;
unsigned int tsum = 0, loop_rank = my_rank * 16777216;
int ufds[bench_rounds];
const char* paths[bench_rounds];
struct stat ts;
// OPEN LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
ufds[i] = komm_open(tf);
paths[i] = tf;
}
// START THREAD TIME MEASSUREMENT
MPI_Barrier(MPI_COMM_WORLD);
start_t = std::chrono::high_resolution_clock::now();
// CLOSE LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
komm_close(ufds[i]);
}
//STOP THREAD TIME MEASSUREMENT
end_t = std::chrono::high_resolution_clock::now();
MPI_Barrier(MPI_COMM_WORLD);
// DEL LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
komm_unlink(paths[i]);
}
std::chrono::duration<double> elapsed_time = std::chrono::duration_cast<std::chrono::duration<double>>(end_t - start_t);
double elapsed_time_int = elapsed_time.count();
MPI_Reduce(&elapsed_time_int, &total_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
std::cout << "THREAD: " << my_rank << ", THREAD TIME: " << elapsed_time.count() << std::endl;
if (my_rank == 0) {
std::cout << "TOTAL TIME: " << total_time << std::endl;
std::cout << "TOTAL OPS: " << bench_rounds * size << std::endl;
std::cout << "CALC SPEED: " << bench_rounds * size / total_time << " ops/s" << std::endl;
}
}
void bench5(int bench_rounds, int argc, char** argv) {
double total_time = 0.0;
MPI_Init(&argc, &argv);
int my_rank = 0, size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
std::chrono::high_resolution_clock::time_point start_t, end_t;
unsigned int tsum = 0, loop_rank = my_rank * 16777216;
const char* paths[bench_rounds];
struct stat ts;
// OPEN LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
int tufd = komm_open(tf);
komm_close(tufd);
paths[i] = tf;
}
// START THREAD TIME MEASSUREMENT
MPI_Barrier(MPI_COMM_WORLD);
start_t = std::chrono::high_resolution_clock::now();
// STAT LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
komm_stat(paths[i], &ts);
}
//STOP THREAD TIME MEASSUREMENT
end_t = std::chrono::high_resolution_clock::now();
MPI_Barrier(MPI_COMM_WORLD);
// DEL LOOP
for (int i = 0; i < bench_rounds; i++) {
const char* tf = (std::string("tf" + std::to_string(loop_rank+ i))).c_str();
komm_unlink(paths[i]);
}
std::chrono::duration<double> elapsed_time = std::chrono::duration_cast<std::chrono::duration<double>>(end_t - start_t);
double elapsed_time_int = elapsed_time.count();
MPI_Reduce(&elapsed_time_int, &total_time, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);
MPI_Finalize();
std::cout << "THREAD: " << my_rank << ", THREAD TIME: " << elapsed_time.count() << std::endl;
if (my_rank == 0) {
std::cout << "TOTAL TIME: " << total_time << std::endl;
std::cout << "TOTAL OPS: " << bench_rounds * size << std::endl;
std::cout << "CALC SPEED: " << bench_rounds * size / total_time << " ops/s" << std::endl;
}
}
int main(int argc, char** argv) {
// SERVER SETUP
server_list = read_conf();
tl::endpoint server = myEngine.lookup(server_list[0]);
// BENCHMARKs
if (argc == 3) {
//OPEN, CLOSE, STAT, DEL LOOP: bench1
if (std::strcmp(argv[1], "bench1") == 0) {
bench1(std::atoi(argv[2]), argc, argv);
}
//READ, WRITE LOOP: bench2
if (std::strcmp(argv[1], "bench2") == 0) {
bench2(std::atoi(argv[2]), argc, argv);
}
//OPEN LOOP: bench3
if (std::strcmp(argv[1], "bench3") == 0) {
bench3(std::atoi(argv[2]), argc, argv);
}
//CLOSE LOOP: bench4
if (std::strcmp(argv[1], "bench4") == 0) {
bench4(std::atoi(argv[2]), argc, argv);
}
//STAT LOOP: bench5
if (std::strcmp(argv[1], "bench5") == 0) {
bench5(std::atoi(argv[2]), argc, argv);
}
}
return 0;
}