forked from michitux/extmem-lfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.cpp
199 lines (154 loc) · 6.72 KB
/
benchmark.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
#include <iostream>
#include <chrono>
#include <stxxl/cmdline>
#include <stack>
#include <stxxl/vector>
#include <Utils/MonotonicPowerlawRandomStream.h>
#include <DistributionCount.h>
#include <HavelHakimi/HavelHakimiGeneratorRLE.h>
#include <DegreeDistributionCheck.h>
#include "SwapGenerator.h"
#include <EdgeSwaps/EdgeSwapInternalSwaps.h>
#include <EdgeSwaps/EdgeSwapTFP.h>
#include <Utils/AsyncStream.h>
struct RunConfig {
stxxl::uint64 numNodes;
stxxl::uint64 numEdges;
stxxl::uint64 minDeg;
stxxl::uint64 maxDeg;
double gamma;
bool swapInternal;
bool swapTFP;
stxxl::uint64 swapsPerIteration;
stxxl::uint64 swapsPerTFPIteration;
unsigned int randomSeed;
stxxl::uint64 sweep_min;
stxxl::uint64 sweep_max;
stxxl::uint64 sweep_steps_per_dec;
RunConfig()
: numNodes(10 * IntScale::M)
, numEdges(50 * IntScale::M)
, minDeg(2)
, maxDeg(100000)
, gamma(-2.0)
, swapInternal(false)
, swapsPerIteration(1024*1024)
, swapsPerTFPIteration(0)
, sweep_min(IntScale::K)
, sweep_max(IntScale::G)
, sweep_steps_per_dec(4)
{
using myclock = std::chrono::high_resolution_clock;
myclock::duration d = myclock::now() - myclock::time_point::min();
randomSeed = d.count();
}
#if STXXL_VERSION_INTEGER > 10401
#define CMDLINE_COMP(chr, str, dest, args...) \
chr, str, dest, args
#else
#define CMDLINE_COMP(chr, str, dest, args...) \
chr, str, args, dest
#endif
bool parse_cmdline(int argc, char* argv[]) {
stxxl::cmdline_parser cp;
cp.add_bytes (CMDLINE_COMP('n', "num-nodes", numNodes, "Generate # nodes, Default: 10 Mi"));
cp.add_bytes (CMDLINE_COMP('m', "num-edges", numEdges, "If >0 generated sorted edge list is gets truncated"));
cp.add_bytes (CMDLINE_COMP('a', "min-deg", minDeg, "Min. Deg of Powerlaw Deg. Distr."));
cp.add_bytes (CMDLINE_COMP('b', "max-deg", maxDeg, "Max. Deg of Powerlaw Deg. Distr."));
cp.add_uint (CMDLINE_COMP('s', "seed", randomSeed, "Initial seed for PRNG"));
cp.add_flag (CMDLINE_COMP('i', "swap-internal", swapInternal, "Perform edge swaps in internal memory"));
cp.add_flag (CMDLINE_COMP('t', "swap-tfp", swapTFP, "Perform edge swaps using TFP"));
cp.add_bytes (CMDLINE_COMP('p', "swaps-per-iteration", swapsPerIteration, "Number of swaps per iteration"));
cp.add_bytes (CMDLINE_COMP('q', "swaps-per-tfp-iteration", swapsPerTFPIteration, "Number of swaps per TFP iteration"));
cp.add_bytes (CMDLINE_COMP('x', "sweep-min", sweep_min, "Min. Number of swaps"));
cp.add_bytes (CMDLINE_COMP('y', "sweep-max", sweep_max, "Max. Number of swaps"));
cp.add_bytes (CMDLINE_COMP('z', "sweep-steps", sweep_steps_per_dec, "Number of steps in sweep per decade"));
if (!cp.process(argc, argv)) {
cp.print_usage();
return false;
}
cp.print_result();
return true;
}
};
template <typename Generator, typename Vector>
void materialize(Generator& gen, Vector & edges, stxxl::stats * stats, stxxl::stats_data& stats_begin) {
std::cout << "Stats after filling of prio queue:" << (stxxl::stats_data(*stats) - stats_begin);
edges.resize(gen.maxEdges());
auto endIt = stxxl::stream::materialize(gen, edges.begin());
edges.resize(endIt - edges.begin());
std::cout << "Generated " << edges.size() << " edges of possibly " << gen.maxEdges() << " edges" << std::endl;
}
void benchmark(RunConfig & config) {
stxxl::stats * stats = stxxl::stats::get_instance();
stxxl::stats_data stats_begin(*stats);
MonotonicPowerlawRandomStream<> degreeSequence(config.minDeg, config.maxDeg, config.gamma, config.numNodes);
// create edge list
using result_vector_type = stxxl::VECTOR_GENERATOR<edge_t>::result;
result_vector_type edges;
AsyncStream<MonotonicPowerlawRandomStream<>> asyncDegree(degreeSequence, true);
DistributionCount<decltype(asyncDegree)> dcount(asyncDegree);
HavelHakimiGeneratorRLE<decltype(dcount)> hhgenerator(dcount);
materialize(hhgenerator, edges, stats, stats_begin);
STXXL_VERBOSE0("Edge list generated");
// sort edge list
result_vector_type swapEdges(edges.size());
{
result_vector_type::bufreader_type edgeReader(edges);
stxxl::sorter<edge_t, GenericComparator<edge_t>::Ascending> edgeSorter(GenericComparator<edge_t>::Ascending(), SORTER_MEM);
while (!edgeReader.empty()) {
if (edgeReader->first < edgeReader->second) {
edgeSorter.push(edge_t {edgeReader->first, edgeReader->second});
} else {
edgeSorter.push(edge_t {edgeReader->second, edgeReader->first});
}
++edgeReader;
}
edgeSorter.sort();
stxxl::stream::materialize(edgeSorter, swapEdges.begin());
}
STXXL_VERBOSE0("Edge list sorted");
// truncate edge list
if (config.numEdges) {
if (config.numEdges > edges.size()) {
std::cerr << "numEdges > number of edges generated " << edges.size() << std::endl;
abort();
}
edges.resize(config.numEdges);
STXXL_VERBOSE0("Edge list truncated to " << config.numEdges);
}
unsigned int iter = 1;
SwapGenerator swapGen(config.sweep_max, edges.size());
for(uint_t num_swaps = config.sweep_min;
num_swaps <= config.sweep_max;
num_swaps = static_cast<uint_t>(num_swaps * pow(10.0, 1.0 / config.sweep_steps_per_dec))
) {
STXXL_VERBOSE0("Begin iteration " << iter++ << " with |num_swaps|=" << num_swaps);
STXXL_VERBOSE0("Swap vector updated");
if (config.swapInternal) {
result_vector_type medges(swapEdges);
STXXL_VERBOSE0("Start Internal");
auto stat_start = stxxl::stats_data(*stats);
EdgeSwapInternalSwaps internalSwaps(medges, config.swapsPerIteration);
SwapGenerator mySwapGen(swapGen);
AsyncStream<SwapGenerator> astream(mySwapGen, true, config.swapsPerIteration, 2);
for(; !astream.empty(); astream.nextBuffer())
internalSwaps.swap_buffer(astream.readBuffer());
internalSwaps.run();
STXXL_VERBOSE0("Completed Internal Swaps" << (stxxl::stats_data(*stats) - stat_start));
}
}
}
int main(int argc, char* argv[]) {
#ifndef NDEBUG
std::cout << "[build with assertions]" << std::endl;
#endif
std::cout << STXXL_VERSION_INTEGER << std::endl;
RunConfig config;
if (!config.parse_cmdline(argc, argv))
return -1;
stxxl::srandom_number32(config.randomSeed);
stxxl::set_seed(config.randomSeed);
benchmark(config);
return 0;
}