-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathac_open_acc.cpp
37 lines (27 loc) · 906 Bytes
/
ac_open_acc.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
#include "ac.h"
using namespace std;
void
profanity_filter_acc_parallel(int* dfa, int* fail_state, char* tweets, bool* valid_state, int num_tweets, int tweet_length) {
#pragma acc data copy(valid_state[0:num_tweets]) copyin(fail_state[0:NUM_ROWS], dfa[0:NUM_ROWS*NUM_COLS])
#pragma acc parallel loop present(valid_state, fail_state,dfa)
for(int i=0; i<num_tweets; i++) {
char* tweet = (tweets +i*tweet_length);
int curr_state = 0;
int idx = 0;
char ch;
while((ch = tweet[idx++])!=10) {
int ord = get_state_as_int(ch);
if(ord < 0 || ord > 29)
continue;
while(curr_state!=0 && dfa[curr_state*NUM_COLS + ord] == 0)
curr_state = fail_state[curr_state];
if(curr_state==0 && dfa[curr_state*NUM_COLS + ord]==0)
continue;
curr_state = dfa[curr_state*NUM_COLS + ord];
if(dfa[curr_state*NUM_COLS + 0] == 1) {
valid_state[i] = true;
break;
}
}
}
}