-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptrn_one_one.cpp
More file actions
417 lines (343 loc) · 13.7 KB
/
ptrn_one_one.cpp
File metadata and controls
417 lines (343 loc) · 13.7 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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
/*
* Copyright (c) 2009 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
*
* Author(s): Torsten Hoefler <htor@cs.indiana.edu>
*
*/
#include "netgauge.h"
#ifdef NG_PTRN_ONE_ONE
#include "hrtimer/hrtimer.h"
#include <vector>
#include <time.h>
#include <algorithm>
#include "fullresult.h"
#include "statistics.h"
#include "ng_tools.hpp"
extern "C" {
extern struct ng_options g_options;
/* internal function prototypes */
static void one_one_do_benchmarks(struct ng_module *module);
/**
* comm. pattern description and function pointer table
*/
static struct ng_comm_pattern pattern_one_one = {
pattern_one_one.name = "one_one",
pattern_one_one.desc = "measures ping-pong latency&bandwidth",
pattern_one_one.flags = 0,
pattern_one_one.do_benchmarks = one_one_do_benchmarks
};
/**
* register this comm. pattern for usage in main
* program
*/
int register_pattern_one_one() {
ng_register_pattern(&pattern_one_one);
return 0;
}
static void one_one_do_benchmarks(struct ng_module *module) {
/** for collecting statistics */
struct ng_statistics statistics;
/** currently tested packet size and maximum */
long data_size;
/** number of times to test the current datasize */
long test_count = g_options.testcount;
/** counts up to test_count */
int test_round = 0;
/** how long does the test run? */
time_t test_time, cur_test_time;
/** number of tests run */
int ovr_tests=0, ovr_bytes=0;
long max_data_size = ng_min(g_options.max_datasize + module->headerlen, module->max_datasize);
/* get needed data buffer memory */
ng_info(NG_VLEV1, "Allocating %d bytes data buffer", max_data_size);
char *buffer; // = (char*)module->malloc(max_data_size);
NG_MALLOC(module, char*, max_data_size, buffer);
ng_info(NG_VLEV2, "Initializing data buffer (make sure it's really allocated)");
for (int i = 0; i < max_data_size; i++) buffer[i] = 0xff;
int rank = g_options.mpi_opts->worldrank;
int p = g_options.mpi_opts->worldsize;
if(p % 2 != 0) {
ng_abort("this pattern needs an even number of ranks\n");
}
if(rank % 2 == 0) g_options.mpi_opts->partner = rank+1;
else g_options.mpi_opts->partner = rank-1;
FILE *outputfd;
if(rank % 2 == 0) {
char fname[1024];
strncpy(fname, g_options.output_file, 1023);
if(p > 2) {
char suffix[512];
snprintf(suffix, 511, ".%i", g_options.mpi_opts->worldrank);
strncat(fname, suffix, 1023);
}
// TODO: should be done globally in netgauge.c
ng_info(NG_VNORM, "writing data to %s", fname);
outputfd = open_output_file(fname);
write_host_information(outputfd);
}
/* buffer for header ... */
char* txtbuf = (char *)malloc(2048 * sizeof(char));
if (txtbuf == NULL) {
ng_error("Could not (re)allocate 2048 byte for output buffer");
ng_exit(10);
}
memset(txtbuf, '\0', 2048);
/* header printing */
if(rank % 2 == 0) {
// if very verbose - long output
snprintf(txtbuf, 2047,
"## Netgauge v%s - mode %s - %i processes\n"
"##\n"
"## A...message size [byte]\n"
"##\n"
"## B...minimum send blocking time\n"
"## C...average send blocking time\n"
"## D...median send blocking time\n"
"## E...maximum send blocking time\n"
"## F...standard deviation for send blocking time (stddev)\n"
"## G...number of send blocking time values, that were bigger than avg + 2 * stddev.\n"
"##\n"
"## H...minimum RTT/2\n"
"## I...average RTT/2\n"
"## J...median RTT/2\n"
"## K...maximum RTT/2\n"
"## L...standard deviation for RTT/2 (stddev)\n"
"## M...number of RTT/2 values, that were bigger than avg + 2 * stddev.\n"
"##\n"
"## N...minimum throughput [Mbit/sec]\n"
"## O...average throughput [Mbit/sec]\n"
"## P...median throughput [Mbit/sec]\n"
"## Q...maximum throughput [Mbit/sec]\n"
"##\n"
"## A - B C D E (F G) - H I J K (L M) - N O P Q\n",
NG_VERSION,
g_options.mode, p);
fprintf(outputfd, "%s", txtbuf);
if(rank == 0) {
if (NG_VLEV2 & g_options.verbose) {
printf("%s", txtbuf);
} else
// if verbose - short output
if (NG_VLEV1 & g_options.verbose) {
snprintf(txtbuf, 2047,
"## Netgauge v%s - mode %s - 2 processes\n"
"##\n"
"## A...message size [byte]\n"
"##\n"
"## B...minimum send blocking time\n"
"## C...average send blocking time\n"
"## D...median send blocking time\n"
"## E...maximum send blocking time\n"
"##\n"
"## F...minimum RTT/2\n"
"## G...average RTT/2\n"
"## H...median RTT/2\n"
"## I...maximum RTT/2\n"
"##\n"
"## J...minimum throughput [Mbit/sec]\n"
"## K...average throughput [Mbit/sec]\n"
"## L...median throughput [Mbit/sec]\n"
"## M...maximum throughput [Mbit/sec]\n"
"##\n"
"## A - B C D E - F G H I - J K L M\n",
NG_VERSION,
g_options.mode);
printf("%s", txtbuf);
} else { // if not verbose - short output
// no header ...
}
}
}
/* Outer test loop
* - geometrically increments data_size (i.e. data_size = data_size * 2)
* (- geometrically decrements test_count) not yet implemented
*/
for (data_size = g_options.min_datasize; data_size > 0;
get_next_testparams(&data_size, &test_count, &g_options, module)) {
if(data_size == -1) goto shutdown;
++test_round;
// the benchmark results
std::vector<double> tblock, trtt;
ng_info(NG_VLEV1, "Round %d: testing %d times with %d bytes:", test_round, test_count, data_size);
// if we print dots ...
if ( (rank==0) && (NG_VLEV1 & g_options.verbose) ) {
printf("# ");
}
//if (!g_options.server) ng_statistics_start_round(&statistics, data_size);
/* Inner test loop
* - run the requested number of tests for the current data size
* - but only if testtime does not exceed the max. allowed test time
* (only if max. test time is not zero)
*/
test_time = 0;
for (int test = -1 /* 1 warmup test */; test < test_count; test++) {
/* first statement to prevent floating exception */
/* TODO: add cool abstract dot interface ;) */
if ( rank == 0 && (NG_VLEV1 & g_options.verbose) && ( test_count < NG_DOT_COUNT || !(test % (int)(test_count / NG_DOT_COUNT)) )) {
printf(".");
fflush(stdout);
}
#ifdef NG_MPI
if(p > 2) MPI_Barrier(MPI_COMM_WORLD);
#endif
/* call the appropriate client or server function */
if (rank % 2 == 1) {
cur_test_time = time(NULL);
/* do the server stuff basically a simple receive and send to
* mirror the data in a ping-pong fashion ... this is not in a
* subfunction since this may be performance critical. The
* send and receive functions are also macros */
/* Phase 1: receive data (wait for data - blocking) */
NG_RECV(g_options.mpi_opts->partner, buffer, data_size, module);
/* Phase 2: send data back */
NG_SEND(g_options.mpi_opts->partner, buffer, data_size, module);
test_time += time(NULL) - cur_test_time;
} else {
/* wait some time for the server to get ready */
usleep(10);
cur_test_time = time(NULL);
/* do the client stuff ... take time, send message, wait for
* reply and take time ... simple ping-pong scheme */
HRT_TIMESTAMP_T t[3];
unsigned long long tibl, tirtt;
/* init statistics (TODO: what does this do?) */
ng_statistics_test_begin(&statistics);
HRT_GET_TIMESTAMP(t[0]);
NG_SEND(g_options.mpi_opts->partner, buffer, data_size, module);
/* get after-sending time */
HRT_GET_TIMESTAMP(t[1]);
/* phase 2: receive returned data */
NG_RECV(g_options.mpi_opts->partner, buffer, data_size, module);
HRT_GET_TIMESTAMP(t[2]);
HRT_GET_ELAPSED_TICKS(t[0],t[1],&tibl);
HRT_GET_ELAPSED_TICKS(t[0],t[2],&tirtt);
/* TODO: check received data */
/* calculate results */
if(test >= 0) {
trtt.push_back(HRT_GET_USEC(tirtt)/2);
tblock.push_back(HRT_GET_USEC(tibl));
}
test_time += time(NULL) - cur_test_time;
}
/* calculate overall statistics */
ovr_tests++;
ovr_bytes += data_size;
/* measure test time and quit test if
* test time exceeds max. test time
* but not if the max. test time is zero
*/
if ( (g_options.max_testtime > 0) &&
(test_time > g_options.max_testtime) ) {
ng_info(NG_VLEV2, "Round %d exceeds %d seconds (duration %d seconds)", test_round, g_options.max_testtime, test_time);
ng_info(NG_VLEV2, "Test stopped at %d tests", test);
break;
}
} /* end inner test loop */
if (rank % 2 ==0) {
/* add linebreak if we made dots ... */
if ( (NG_VLEV1 & g_options.verbose) ) {
ng_info(NG_VLEV1, "\n");
}
/* output statistics - blocking time */
double tblock_avg = std::accumulate(tblock.begin(), tblock.end(), (double)0)/(double)tblock.size();
double tblock_min = *min_element(tblock.begin(), tblock.end());
double tblock_max = *max_element(tblock.begin(), tblock.end());
std::vector<double>::iterator nthblock = tblock.begin()+tblock.size()/2;
nth_element(tblock.begin(), nthblock, tblock.end());
double tblock_med = *nthblock;
double tblock_var = standard_deviation(tblock.begin(), tblock.end(), tblock_avg);
int tblock_fail = count_range(tblock.begin(), tblock.end(), tblock_avg-tblock_var*2, tblock_avg+tblock_var*2);
/* output statistics - rtt time */
double trtt_avg = std::accumulate(trtt.begin(), trtt.end(), (double)0)/(double)trtt.size();
double trtt_min = *min_element(trtt.begin(), trtt.end());
double trtt_max = *max_element(trtt.begin(), trtt.end());
std::vector<double>::iterator nthrtt = trtt.begin()+trtt.size()/2;
std::nth_element(trtt.begin(), nthrtt, trtt.end());
double trtt_med = *nthrtt;
double trtt_var = standard_deviation(trtt.begin(), trtt.end(), trtt_avg);
int trtt_fail = count_range(trtt.begin(), trtt.end(), trtt_avg-trtt_var*2, trtt_avg+trtt_var*2);
// generate long output for output file
memset(txtbuf, '\0', 2048);
snprintf(txtbuf, 2047,
"%ld - %.2lf %.2lf %.2lf %.2lf (%.2lf %i) - %.2lf %.2lf %.2lf %.2lf (%.2lf %i) - %.2lf %.2lf %.2lf %.2lf\n",
data_size, /* packet size */
tblock_min, /* minimum send blocking time */
tblock_avg, /* average send blocking time */
tblock_med, /* median send blocking time */
tblock_max, /* maximum send blocking time */
tblock_var, /* standard deviation */
tblock_fail, /* how many are bigger than twice the standard deviation? */
trtt_min, /* minimum RTT time */
trtt_avg, /* average RTT time */
trtt_med, /* median RTT time */
trtt_max, /* maximum RTT time */
trtt_var, /* standard deviation */
trtt_fail, /* how many are bigger than twice the standard deviation? */
data_size/trtt_max*8, /* minimum bandwidth */
data_size/trtt_avg*8, /* average bandwidth */
data_size/trtt_med*8, /* median bandwidth */
data_size/trtt_min*8 /* maximum bandwidth */
);
fprintf(outputfd, "%s", txtbuf);
// printf output *only* on rank 0!
if (rank ==0) {
// if very verbose - long output
if (NG_VLEV2 & g_options.verbose) {
printf("%s", txtbuf);
} else
// if verbose - short output
if (NG_VLEV1 & g_options.verbose) {
memset(txtbuf, '\0', 2048);
snprintf(txtbuf, 2047,
"%ld - %.2lf %.2lf %.2lf %.2lf - %.2lf %.2lf %.2lf %.2lf - %.2lf %.2lf %.2lf %.2lf\n",
data_size, /* packet size */
tblock_min, /* minimum send blocking time */
tblock_avg, /* average send blocking time */
tblock_med, /* median send blocking time */
tblock_max, /* maximum send blocking time */
trtt_min, /* minimum RTT time */
trtt_avg, /* average RTT time */
trtt_med, /* median RTT time */
trtt_max, /* maximum RTT time */
data_size/trtt_max*8, /* minimum bandwidth */
data_size/trtt_avg*8, /* average bandwidth */
data_size/trtt_med*8, /* median bandwidth */
data_size/trtt_min*8 /* maximum bandwidth */
);
printf("%s", txtbuf);
} else
// if not verbose - short output
{
memset(txtbuf, '\0', 2048);
snprintf(txtbuf, 2047,
"%ld bytes \t -> %.2lf us \t == %.2lf Mbit/s\n",
data_size, /* packet size */
//trtt_med, /* median RTT time */
trtt_min, /* minimum RTT time */
data_size/trtt_med*8 /* median bandwidth */
);
printf("%s", txtbuf);
}
}
}
// write output file
ng_info(NG_VLEV1, "\n");
fflush(stdout);
/* only a client does the stats stuff */
//if (!g_options.server)
// ng_statistics_finish_round(&statistics);
} /* end outer test loop */
if(rank % 2 == 0) {
fclose(outputfd);
}
shutdown:
if(txtbuf) free(txtbuf);
}
} /* extern C */
#else
extern "C" {
int register_pattern_one_one(void) {return 0;};
}
#endif