-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCREW.cpp
More file actions
62 lines (48 loc) · 1.15 KB
/
CREW.cpp
File metadata and controls
62 lines (48 loc) · 1.15 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
61
62
#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(omp_get_max_threads());
int n = t.size(), m = a.size();
vector<vector<int> > check(m, vector<int>(n, 0));
int *SUM = new int[n];
double start = omp_get_wtime();
#pragma omp parallel for shared(a,t,check)
for(long long i=0;i<n*m;i++) {
int id = i / m;
int j = i % m;
if(a[j] == t[id+j]) {
check[j][id] = 1;
}
}
#pragma omp parallel for
for(int i=0;i<n;i++) {
SUM[i] = 0;
#pragma omp parallel for reduction(+:SUM[i])
for(int j=0;j<m;j++) {
SUM[i] += check[j][i];
}
}
#pragma omp parallel for shared(m)
for(int i=0;i<n;i++) {
if(SUM[i] == m) {
#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;
}