7 #include "misc/utils.h"
9 #ifdef MULTITHREAD_SUPPORT
17 const int MAX_THREADS = 64;
18 const usint MAX_OCCURRENCES = 100000;
21 int main(int argc, char** argv)
23 std::cout << "RLCSA test" << std::endl;
26 std::cout << "Usage: rlcsa_test basename [patterns [threads]]" << std::endl;
30 std::cout << "Base name: " << argv[1] << std::endl;
31 if(argc > 2) { std::cout << "Patterns: " << argv[2] << std::endl; }
35 threads = std::min(MAX_THREADS, std::max(atoi(argv[3]), 1));
37 std::cout << "Threads: " << threads << std::endl;
38 std::cout << std::endl;
40 const RLCSA rlcsa(argv[1], false);
42 rlcsa.reportSize(true);
44 if(argc < 3) { return 0; }
45 std::ifstream patterns(argv[2], std::ios_base::binary);
48 std::cerr << "Error opening pattern file!" << std::endl;
52 std::vector<std::string> rows;
53 readRows(patterns, rows, true);
55 usint total = 0, total_size = 0, ignored = 0, found = 0;
56 sint i, n = rows.size();
60 double start = readTimer();
61 #ifdef MULTITHREAD_SUPPORT
63 omp_set_num_threads(threads);
64 #pragma omp parallel private(result, matches, occurrences)
66 #pragma omp for schedule(dynamic, 1)
67 for(i = 0; i < n; i++)
69 result = rlcsa.count(rows[i]);
70 occurrences = length(result);
76 if(occurrences <= MAX_OCCURRENCES) { total += occurrences; }
79 total_size += rows[i].length();
81 if(!isEmpty(result) && occurrences <= MAX_OCCURRENCES)
83 matches = rlcsa.locate(result);
89 for(i = 0; i < n; i++)
91 result = rlcsa.count(rows[i]);
92 total_size += rows[i].length();
93 if(!isEmpty(result)) { found++; total += length(result); }
94 matches = rlcsa.locate(result);
95 if(matches) { delete[] matches; }
99 double time = readTimer() - start;
100 std::cout << "Patterns: " << n << " (" << (n / time) << " / sec)" << std::endl;
101 std::cout << "Total size: " << total_size << " bytes (" << (total_size / time) << " / sec)" << std::endl;
102 std::cout << "Matches: " << total << " (" << (total / time) << " / sec)" << std::endl;
103 std::cout << "Found: " << found << std::endl;
104 std::cout << "Time: " << time << " seconds" << std::endl;
105 std::cout << std::endl;
106 std::cout << "Ignored " << ignored << " patterns with more than " << MAX_OCCURRENCES << " occurrences." << std::endl;
107 std::cout << std::endl;