-
Notifications
You must be signed in to change notification settings - Fork 1
/
ss_test.cpp
59 lines (47 loc) · 1.45 KB
/
ss_test.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
#include <cstdlib>
#include <fstream>
#include <iostream>
#include "misc/utils.h"
#ifdef MULTITHREAD_SUPPORT
#include <omp.h>
const int MAX_THREADS = 64;
#endif
using namespace CSA;
int main(int argc, char** argv)
{
std::cout << "Parallel suffix sort test" << std::endl;
if(argc < 2)
{
std::cout << "Usage: ss_test base_name [threads]" << std::endl;
return 1;
}
std::cout << "Base name: " << argv[1] << std::endl;
uint threads = 1;
if(argc >= 3) { threads = std::min(std::max(atoi(argv[2]), 1), MAX_THREADS); }
std::cout << "Threads: " << threads << std::endl;
std::cout << std::endl;
std::ifstream input(argv[1], std::ios_base::binary);
if(!input)
{
std::cerr << "Error: Cannot open input file " << argv[1] << "!" << std::endl;
return 2;
}
uint n = fileSize(input);
uchar* data = new uchar[n];
input.read((char*)data, n);
input.close();
n++;
usint* sequence = new usint[n];
for(uint i = 0; i < n - 1; i++) { sequence[i] = data[i] + 1; }
sequence[n - 1] = 0;
delete[] data; data = 0;
double start = readTimer();
short_pair* result = simpleSuffixSort(sequence, n, threads);
delete[] result; result = 0;
double time = readTimer() - start;
double megabytes = (n - 1) / (double)MEGABYTE;
std::cout << megabytes << " megabytes in " << time << " seconds (" << (megabytes / time) << " MB/s)" << std::endl;
std::cout << "Memory: " << memoryUsage() << " kB" << std::endl;
std::cout << std::endl;
return 0;
}