-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpermutation.cpp
More file actions
61 lines (54 loc) · 1.67 KB
/
permutation.cpp
File metadata and controls
61 lines (54 loc) · 1.67 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
//
// Created by peter on 3/21/24.
//
#include <random>
#include "scatter_gather_algorithms/permutation.h"
#include "utils/command_line.h"
void RunTest(int argc, char **argv) {
if (argc < 4) {
LOG(ERROR) << "Usage: " << argv[0] << " run <input prefix> <output prefix>";
return;
}
std::string input_prefix(argv[2]), output_prefix(argv[3]);
auto input_files = FindFiles(input_prefix);
Permutation<size_t> permutation;
parlay::internal::timer timer("Permutation");
auto result_files = permutation.Permute(input_files, output_prefix);
timer.next("DONE");
}
void Verify(int argc, char **argv) {
std::string prefix(argv[2]);
size_t expected_size = 1UL << ParseLong(argv[3]);
expected_size *= sizeof(size_t);
auto results = FindFiles(prefix);
GetFileInfo(results, true);
size_t actual_size = 0;
for (auto const &f : results) {
actual_size += f.true_size;
}
if (expected_size == actual_size) {
LOG(INFO) << "File size check passed";
} else {
LOG(ERROR) << "File size check failed. "
"Expected " << expected_size << " bytes, got " << actual_size << " bytes.";
}
}
int main(int argc, char **argv) {
ParseGlobalArguments(argc, argv);
if (argc < 2) {
show_usage:
LOG(ERROR) << "Usage: " << argv[0] << " <gen|run> <command-specific options>";
return 0;
}
std::map<std::string, std::function<void(int, char **)>> commands(
{
{"run", RunTest},
{"Verify", Verify}
}
);
if (commands.count(argv[1])) {
commands[argv[1]](argc, argv);
} else {
goto show_usage;
}
}