-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptrn_Nto1.cpp
More file actions
337 lines (296 loc) · 11.4 KB
/
ptrn_Nto1.cpp
File metadata and controls
337 lines (296 loc) · 11.4 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
/*
* 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"
#if defined NG_PTRN_NTO1
#include "hrtimer/hrtimer.h"
#include <vector>
#include "statistics.h"
#include <string.h>
#include <algorithm>
#include "ng_tools.hpp"
/* internal function prototypes & extern stuff */
static void Nto1_do_benchmarks(struct ng_module *module);
extern struct ng_options g_options;
/**
* one-to-many communication pattern registration
* structure
*/
static struct ng_comm_pattern pattern_Nto1 = {
pattern_Nto1.name = "Nto1",
pattern_Nto1.desc = "measures bandwith in a N:1 congestion situation",
pattern_Nto1.flags = NG_PTRN_NB,
pattern_Nto1.do_benchmarks = Nto1_do_benchmarks
};
/**
* registers this comm. pattern with the main prog.,
* but only if we use MPI
*/
int register_pattern_Nto1() {
/* there's no use for this mode without MPI */
#if NG_MPI
ng_register_pattern(&pattern_Nto1);
#endif
return 0;
}
void Nto1_do_benchmarks(struct ng_module *module) {
#if NG_MPI
/** current data size for transmission tests */
long data_size;
/** # times to run with current data_size */
long test_count = g_options.testcount;
/** send/receive buffer */
void *buffer;
/** enumerating things is such a fun! */
int i;
/* server role - receive from clients */
NG_Request *reqs = NULL;
/* measurement data ... we need to send it from rank 1 to rank 0 since
* rank 0 doe all the I/O */
double results[2];
/* allocate send / recv buffer */
ng_info(NG_VLEV2, "Allocating %d bytes data buffer", g_options.max_datasize + module->headerlen);
NG_MALLOC(module, void*, g_options.max_datasize + module->headerlen, buffer);
int rank = g_options.mpi_opts->worldrank;
/* initialize the statistics stuff - rank 1 does the whole measurement */
if(rank == 0) {
/* allocate Request structure at server */
reqs = (NG_Request*)malloc(sizeof(NG_Request) * (g_options.mpi_opts->worldsize-1) );
}
/* 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 == 0) {
// if very verbose - long output
if (NG_VLEV2 & g_options.verbose) {
snprintf(txtbuf, 2047,
"## Netgauge v%s - mode %s - 2 processes\n"
"##\n"
"## A...packet 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\n"
"## G...number of send blocking time values, that were bigger than 2*avg.\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\n"
"## M...number of RTT/2 values, that were bigger than 2*avg.\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 S D (E F) - G H T I (J K) - L M U N\n",
NG_VERSION,
g_options.mode);
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...packet 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"
"## H...minimum RTT/2\n"
"## I...average RTT/2\n"
"## J...median RTT/2\n"
"## K...maximum RTT/2\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 S D - G H T I - L M U N\n",
NG_VERSION,
g_options.mode);
printf("%s", txtbuf);
} else
// if not verbose - short output
{
// no header ...
}
}
/* outer test loop, sets data_size and test_count */
for (data_size = NG_START_PACKET_SIZE; !g_stop_tests && data_size > 0;
get_next_testparams(&data_size, &test_count, &g_options, module)) {
if(data_size == -1) goto shutdown;
/* TODO: introduce internal dissemination barrier */
ng_info(NG_VLEV1, "Barrier and testing %d times with %d bytes:", test_count, data_size);
// if we print dots ...
if ( (rank==0) && (NG_VLEV1 & g_options.verbose) ) {
printf("# ");
}
// the benchmark results
std::vector<double> tblock, trtt;
for (long test=-1 /* 1 warmup */; (test < test_count) && !g_stop_tests; test++) {
/* TODO: introduce internal dissemination barrier */
MPI_Barrier(MPI_COMM_WORLD);
if ( rank == 0 && (NG_VLEV1 & g_options.verbose) && ( test_count < NG_DOT_COUNT || !(test % (int)(test_count / NG_DOT_COUNT)) )) {
printf(".");
fflush(stdout);
}
if (g_options.mpi_opts->worldrank == 0) {
for(i = 1; i<g_options.mpi_opts->worldsize; i++) {
/* TODO: all receive in one buffer ... is this a problem? */
module->irecvfrom(i, buffer, data_size, &reqs[i-1]);
}
/* loop until all requests done */
while(1) {
int ctr;
ctr = 0;
for(i = 1; i<g_options.mpi_opts->worldsize; i++) {
ctr += module->test(&reqs[i-1]);
}
/* all returned 0 :) */
if(ctr == 0) break;
}
/* send ack to rank 1 */
module->sendto(1, buffer, 1);
/* receive measurement data from rank 1 */
MPI_Recv(&results, 2, MPI_DOUBLE, 1, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
/* calculate results */
if(test >= 0) {
trtt.push_back(results[1]/2);
tblock.push_back(results[0]);
}
} else {
/* client role - send to server */
unsigned long long tibl, tirtt;
HRT_TIMESTAMP_T t[3];
if(g_options.mpi_opts->worldrank == 1) {
/* get start time - timer is *ONLY* meaningful on rank 1 !! */
HRT_GET_TIMESTAMP(t[0]);
}
module->sendto(0, buffer, data_size);
/* get after-sending time */
if(g_options.mpi_opts->worldrank == 1) HRT_GET_TIMESTAMP(t[1]);
/* rank 1 receives ack from server */
if(g_options.mpi_opts->worldrank == 1) {
module->recvfrom(0,buffer,1);
/* get after-receiving time */
HRT_GET_TIMESTAMP(t[2]);
HRT_GET_ELAPSED_TICKS(t[0],t[1],&tibl);
HRT_GET_ELAPSED_TICKS(t[0],t[2],&tirtt);
/* send results to rank 0 */
results[0] = HRT_GET_USEC(tibl);
results[1] = HRT_GET_USEC(tirtt);
MPI_Send(&results, 2, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD);
}
}
}
/* add linebreak if we made dots ... */
if ( (NG_VLEV1 & g_options.verbose) ) {
ng_info(NG_VLEV1, "\n");
}
if(rank==0) {
/* output statistics - blocking time */
double tblock_avg = std::accumulate(tblock.begin(), tblock.end(), (double)0)/(double)tblock.size();
double tblock_min = *std::min_element(tblock.begin(), tblock.end());
double tblock_max = *std::max_element(tblock.begin(), tblock.end());
std::vector<double>::iterator nthblock = tblock.begin()+tblock.size()/2;
std::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 = *std::min_element(trtt.begin(), trtt.end());
double trtt_max = *std::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);
// if very verbose - long output
if (NG_VLEV2 & g_options.verbose) {
memset(txtbuf, '\0', 2048);
snprintf(txtbuf, 2047,
"%li - %.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 */
);
printf("%s", txtbuf);
} else
// if verbose - short output
if (NG_VLEV1 & g_options.verbose) {
memset(txtbuf, '\0', 2048);
snprintf(txtbuf, 2047,
"%li - %.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,
"%li bytes \t -> %.2lf us \t == %.2lf Mbit/s\n",
data_size, /* packet size */
trtt_med, /* median RTT time */
data_size/trtt_med*8 /* median bandwidth */
);
printf("%s", txtbuf);
}
}
} /* outer test loop */
shutdown:
/* clean up */
if (buffer) free(buffer);
#endif
}
#else
extern "C" {
int register_pattern_Nto1(void) {return 0;}
}
#endif