-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
562 lines (500 loc) · 17.2 KB
/
main.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
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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
// ***********************************************************************
//
// NEVE
//
// ***********************************************************************
//
// Copyright (2019) Battelle Memorial Institute
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ************************************************************************
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "comm.hpp"
static std::string inputFileName;
static int me, nprocs;
static int ranksPerNode = 1;
static GraphElem nvRGG = 0;
static int generateGraph = 0;
static GraphWeight randomEdgePercent = 0.0;
static long minSizeExchange = 0;
static long maxSizeExchange = 0;
static long maxNumGhosts = 0;
static bool readBalanced = false;
static bool hardSkip = false;
static bool randomNumberLCG = false;
static bool fallAsleep = false;
static int lttOption = 0, performWork = 0;
static bool performBWTest = false;
static bool performLTTest = false;
static bool performWorkMax = false;
static bool performWorkSum = false;
static bool performLTTestNbrAlltoAll = false;
static bool performLTTestNbrAllGather = false;
static bool createRankOrder = false;
static bool performBFS = false;
static bool performSSSP = false;
static int dumpSharedEdgesBetweenPEs = 0;
static int rankOrderType = 0;
static bool chooseSingleNbr = false;
static int processNbr = 0;
static bool shrinkGraph = false;
static float graphShrinkPercent = 0;
// parse command line parameters
static void parseCommandLine(int argc, char** argv);
int main(int argc, char **argv)
{
double t0, t1, td, td0, td1;
MPI_Init(&argc, &argv);
#if defined(SCOREP_USER_ENABLE)
SCOREP_RECORDING_OFF();
#endif
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &me);
// command line options
MPI_Barrier(MPI_COMM_WORLD);
parseCommandLine(argc, argv);
Graph* g = nullptr;
td0 = MPI_Wtime();
// generate graph only supports RGG as of now
if (generateGraph)
{
GenerateRGG gr(nvRGG);
g = gr.generate(randomNumberLCG, true /*isUnitEdgeWeight*/, randomEdgePercent);
}
else
{ // read input graph
#ifndef SSTMAC
BinaryEdgeList rm;
if (readBalanced == true)
{
if (me == 0)
{
std::cout << std::endl;
std::cout << "Trying to balance the edge distribution (#edges/p) while reading: " << std::endl;
std::cout << inputFileName << std::endl;
}
g = rm.read_balanced(me, nprocs, ranksPerNode, inputFileName);
}
else
{
if (me == 0)
{
std::cout << std::endl;
std::cout << "Standard edge distribution (#vertices/p) while reading: " << std::endl;
std::cout << inputFileName << std::endl;
}
g = rm.read(me, nprocs, ranksPerNode, inputFileName);
}
#else
#warning "SSTMAC is defined: Trying to load external graph binaries will FAIL."
#endif
}
#if defined(PRINT_GRAPH_EDGES)
g->print();
#endif
g->print_dist_stats();
assert(g != nullptr);
if (dumpSharedEdgesBetweenPEs)
{
if (dumpSharedEdgesBetweenPEs == 1)
g->pg_matrix(adjacency);
else if (dumpSharedEdgesBetweenPEs == 2)
g->pg_matrix(chaco_unweighted);
else if (dumpSharedEdgesBetweenPEs == 3)
g->pg_matrix(chaco_weighted);
else
g->pg_matrix();
}
if (createRankOrder)
{
t0 = MPI_Wtime();
if (rankOrderType == 1)
g->rank_order(none);
else if (rankOrderType == 2)
g->weighted_rank_order(none);
else if (rankOrderType == 3)
g->rank_order(ascending);
else if (rankOrderType == 4)
g->rank_order(descending);
else if (rankOrderType == 5)
g->weighted_rank_order(ascending);
else if (rankOrderType == 6)
g->weighted_rank_order(descending);
else if (rankOrderType == 7)
g->weighted_rank_order(normal);
else if (rankOrderType == 8)
g->common_neighbors_rank_order(ascending);
else if (rankOrderType == 9)
g->common_neighbors_rank_order(descending);
else if (rankOrderType == 10)
g->common_neighbors_rank_order(normal);
else if (rankOrderType >= 11)
g->matching_rank_order();
else
g->weighted_rank_order(ascending);
t1 = MPI_Wtime() - t0;
double tr = 0.0;
MPI_Reduce(&t1, &tr, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
if (me == 0)
std::cout << "Time to create rank order file (in s): " << tr << std::endl;
}
MPI_Barrier(MPI_COMM_WORLD);
td1 = MPI_Wtime();
td = td1 - td0;
double tdt = 0.0;
MPI_Reduce(&td, &tdt, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
if (me == 0)
{
if (!generateGraph)
std::cout << "Time to read input file and create distributed graph (in s): "
<< tdt << std::endl;
else
std::cout << "Time to generate distributed graph of "
<< nvRGG << " vertices (in s): " << tdt << std::endl;
}
if (performBFS)
{
BFS b(g);
b.run_test();
}
if (performSSSP)
{
BFS b(g);
b.run_test_sssp();
}
if (performBWTest || performLTTest || performLTTestNbrAlltoAll || performLTTestNbrAllGather)
{
// Comm object can be instantiated
// with iteration ranges and other
// info, see class Comm in comm.hpp
if (maxSizeExchange == 0)
maxSizeExchange = MAX_SIZE;
if (minSizeExchange == 0)
minSizeExchange = MIN_SIZE;
Comm *c = nullptr;
if (performBWTest)
c = new Comm(g, minSizeExchange, maxSizeExchange, graphShrinkPercent);
else
c = new Comm(g, minSizeExchange, maxSizeExchange);
MPI_Barrier(MPI_COMM_WORLD);
t0 = MPI_Wtime();
// bandwidth test
if (performBWTest)
{
if (chooseSingleNbr)
{
if (me == 0)
{
std::cout << "Choosing the neighborhood of process #" << processNbr
<< " for bandwidth test." << std::endl;
}
if (maxNumGhosts > 0)
c->p2p_bw_snbr(processNbr, maxNumGhosts);
else
c->p2p_bw_snbr(processNbr);
}
else
{
if (hardSkip)
c->p2p_bw_hardskip();
else
c->p2p_bw();
}
}
// latency tests
if (performLTTest || performLTTestNbrAlltoAll || performLTTestNbrAllGather)
{
if (performLTTest)
{
if (chooseSingleNbr)
{
if (me == 0)
{
std::cout << "Choosing the neighborhood of process #" << processNbr
<< " for latency test." << std::endl;
}
c->p2p_lt_snbr(processNbr);
}
else {
if (fallAsleep) {
if (me == 0)
std::cout << "Invoking (u)sleep for an epoch equal to #locally-owned-vertices" << std::endl;
c->p2p_lt_usleep();
}
else if (performWorkSum) {
if (me == 0)
std::cout << "Invoking work performing degree sum for #locally-owned-vertices" << std::endl;
c->p2p_lt_worksum();
}
else if (performWorkMax) {
if (me == 0)
std::cout << "Invoking work performing degree max for #locally-owned-vertices" << std::endl;
c->p2p_lt_workmax();
}
else
c->p2p_lt();
}
}
if (performLTTestNbrAlltoAll)
{
if (chooseSingleNbr)
{
if (me == 0)
{
std::cout << "Choosing the neighborhood of process #" << processNbr
<< " for latency test (using MPI_Isend/Irecv)." << std::endl;
}
c->p2p_lt_snbr(processNbr);
}
else
{
#ifndef SSTMAC
c->nbr_ala_lt();
#else
#warning "SSTMAC is defined: MPI3 neighborhood collectives are turned OFF."
#endif
}
}
if (performLTTestNbrAllGather)
{
if (chooseSingleNbr)
{
if (me == 0)
{
std::cout << "Choosing the neighborhood of process #" << processNbr
<< " for latency test (using MPI_Isend/Irecv)." << std::endl;
}
c->p2p_lt_snbr(processNbr);
}
else
{
#ifndef SSTMAC
c->nbr_aga_lt();
#else
#warning "SSTMAC is defined: MPI3 neighborhood collectives are turned OFF."
#endif
}
}
}
MPI_Barrier(MPI_COMM_WORLD);
t1 = MPI_Wtime();
double p_tot = t1 - t0, t_tot = 0.0;
MPI_Reduce(&p_tot, &t_tot, 1, MPI_DOUBLE,
MPI_SUM, 0, MPI_COMM_WORLD);
if (me == 0)
{
std::cout << "Average execution time (in s) for running the test on " << nprocs << " processes: "
<< (double)(t_tot/(double)nprocs) << std::endl;
#ifndef SSTMAC
std::cout << "Resolution of MPI_Wtime: " << MPI_Wtick() << std::endl;
#endif
}
c->destroy_nbr_comm();
delete c;
} // end latency/bandwidth tests
delete g;
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
void parseCommandLine(int argc, char** const argv)
{
int ret;
optind = 1;
while ((ret = getopt(argc, argv, "f:r:n:lhp:m:x:bg:t:ws:z:ud:o:aji:")) != -1) {
switch (ret) {
case 'f':
inputFileName.assign(optarg);
break;
case 'b':
readBalanced = true;
break;
case 'r':
ranksPerNode = atoi(optarg);
break;
case 'n':
nvRGG = atol(optarg);
if (nvRGG > 0)
generateGraph = true;
break;
case 'l':
randomNumberLCG = true;
break;
case 'p':
randomEdgePercent = atof(optarg);
break;
case 'x':
maxSizeExchange = atol(optarg);
break;
case 'i':
dumpSharedEdgesBetweenPEs = atol(optarg);
break;
case 'm':
minSizeExchange = atol(optarg);
break;
case 'g':
maxNumGhosts = atol(optarg);
break;
case 'w':
performBWTest = true;
break;
case 't':
lttOption = atoi(optarg);
if (lttOption == 0)
performLTTest = true;
else if (lttOption == 1)
performLTTestNbrAlltoAll = true;
else if (lttOption == 2)
performLTTestNbrAllGather = true;
else
performLTTest = true;
break;
case 'd':
performWork = atoi(optarg);
if (performWork > 0)
performWorkSum = true;
else
performWorkMax = true;
break;
case 'h':
hardSkip = true;
break;
case 's':
chooseSingleNbr = true;
processNbr = atoi(optarg);
break;
case 'z':
shrinkGraph = true;
graphShrinkPercent = atof(optarg);
break;
case 'u':
fallAsleep = true;
break;
case 'o':
rankOrderType = atoi(optarg);
createRankOrder = true;
break;
case 'a':
performBFS = true;
break;
case 'j':
performSSSP = true;
break;
default:
assert(0 && "Should not reach here!!");
break;
}
}
// warnings/info
if (me == 0 && (performLTTest || performLTTestNbrAlltoAll || performLTTestNbrAllGather) && maxNumGhosts)
{
std::cout << "Setting the number of ghost vertices (-g <...>) has no effect for latency test."
<< std::endl;
}
if (me == 0 && generateGraph && readBalanced)
{
std::cout << "Balanced read (option -b) is only applicable for real-world graphs. "
<< "This option does nothing for generated (synthetic) graphs." << std::endl;
}
if (me == 0 && generateGraph && shrinkGraph && graphShrinkPercent > 0.0)
{
std::cout << "Graph shrinking (option -z) is only applicable for real-world graphs. "
<< "This option does nothing for generated (synthetic) graphs." << std::endl;
}
if (me == 0 && shrinkGraph && graphShrinkPercent <= 0.0)
{
std::cout << "Graph shrinking (option -z) must be greater than 0.0. " << std::endl;
}
if (me == 0 && shrinkGraph && (performLTTest || performLTTestNbrAlltoAll || performLTTestNbrAllGather))
{
std::cout << "Graph shrinking is ONLY valid for bandwidth test, NOT latency test which just performs message exchanges across the process neighborhood of a graph." << std::endl;
}
if (me == 0 && (performLTTest || performLTTestNbrAlltoAll || performLTTestNbrAllGather) && hardSkip)
{
std::cout << "The hard skip option to disable warmup and extra communication loops only affects the bandwidth test." << std::endl;
}
if (me == 0 && (!performLTTest) && (performWorkSum || performWorkMax))
{
std::cout << "Passing -d <> has no effect unless -t <> is passed as well. In other words, work-option is enabled only for latency tests." << std::endl;
}
if (me == 0 && chooseSingleNbr && (performLTTestNbrAlltoAll || performLTTestNbrAllGather))
{
std::cout << "At present, only MPI Isend/Irecv communication is supported when a single process's neighborhood is selected.." << std::endl;
}
if (me == 0 && lttOption > 2)
{
std::cout << "Valid values for latency test arguments are 0 (Isend/Irecv, the default case), 1 (Neighbor All-to-All) and 2 (Neighbor All-Gather)." << std::endl;
}
// errors
if (me == 0 && (argc == 1))
{
std::cerr << "Must specify some options." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && !generateGraph && inputFileName.empty())
{
std::cerr << "Must specify a binary file name with -f or provide parameters for generating a graph." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && !generateGraph && randomNumberLCG)
{
std::cerr << "Must specify -n for graph generation using LCG." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && !generateGraph && (randomEdgePercent > 0.0))
{
std::cerr << "Must specify -n for graph generation first to add random edges to it." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && generateGraph && ((randomEdgePercent < 0.0) || (randomEdgePercent >= 100.0)))
{
std::cerr << "Invalid random edge percentage for generated graph!" << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && !chooseSingleNbr && (maxNumGhosts > 0))
{
std::cerr << "Fixing ghosts only allowed when a single neighborhood (-s <...>) is chosen." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
if (me == 0 && !generateGraph && shrinkGraph && (graphShrinkPercent != 0.0 && (graphShrinkPercent < 0.0 || graphShrinkPercent > 100.0)))
{
std::cerr << "Allowable value of graph shrink percentage is 0.0...-100%." << std::endl;
MPI_Abort(MPI_COMM_WORLD, -99);
}
} // parseCommandLine