forked from RoySRC/Cuda_Poly_Long_Div
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_main.cpp
55 lines (44 loc) · 1.17 KB
/
cpu_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
/*
* cpu_main.cpp
*
* Created on: Dec 23, 2020
* Author: sajeeb
*/
#include "FileWriter.h"
#include "cuda.cu"
class params {
public:
vector<uint64_t> sol;
uint64_t start, end;
};
template<int t, int da, int dc>
void search_for_CRC_polynomial_cpu(params& p, FileWriter& fw) {
if (t<2) return;
for (size_t i=p.start; i<p.end; ++i) {
if (!(i&1)) continue;
if (i > (uint64_t(1)<<(dc+1))-1) break;
bool ret = test_all_two_bit_patterns<da, dc>(i);
if (ret && t >= 3) ret = test_all_three_bit_patterns<da, dc>(i);
if (ret) p.sol.push_back(i);
}
fw.write(p.sol);
}
int main() {
int num_sol{0};
constexpr int t{2};
constexpr int da{256};
constexpr int dc{16};
FileWriter fw("output_cpu");
size_t n = std::thread::hardware_concurrency();
thread threads[n];
params p[n];
for (size_t i{0}, d{(uint64_t(1)<<(dc+1))/n}; i<n; ++i) {
p[i].start = i*d;
p[i].end = (i+1 == n) ? uint64_t(1)<<(dc+1) : p[i].start + d;
threads[i] = thread(search_for_CRC_polynomial_cpu<t,da,dc>,
std::ref(p[i]), std::ref(fw));
}
for (size_t i{0}; i<n; ++i) threads[i].join();
for (size_t i{0}; i<n; ++i) num_sol += p[i].sol.size();
cout << "num_sol: " << num_sol << endl;
}