-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRCW.cpp
More file actions
51 lines (39 loc) · 876 Bytes
/
CRCW.cpp
File metadata and controls
51 lines (39 loc) · 876 Bytes
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
#include<bits/stdc++.h>
#include<omp.h>
#define NUM_THREADS 4
using namespace std;
vector<int> v;
int main() {
ifstream fin;
string a, t;
fin.open("1.txt");
getline(fin, t);
fin.close();
cin>>a;
omp_set_num_threads(NUM_THREADS);
int n = t.size(), m = a.size();
vector<int> check(n, 1);
double start = omp_get_wtime();
#pragma omp parallel for
for(long long i=0;i<n*m;i++) {
int id = i / m;
int j = i % m;
if(a[j] != t[id+j]) {
check[id] = 0;
}
}
#pragma omp parallel for
for(int i=0;i<n;i++) {
if(check[i]) {
#pragma omp critical
v.push_back(i);
}
}
double end = omp_get_wtime();
for(auto it : v) {
cout<<it<<" ";
}
cout<<"\n";
cout<<"Time: "<<end-start<<"\n";
return 0;
}