Last active
August 29, 2015 13:57
-
-
Save mikealexander/9396205 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int hostMatch(long *comparisons, int numthreads) { | |
int pos, i, j, lastI; | |
long comps = 0; | |
pos = -1; | |
lastI = textLength-patternLength; | |
#pragma omp parallel private(i, j) shared(pos) num_threads(numthreads) reduction(+ : comps) | |
#pragma omp for schedule(static) | |
for(i=0; i <= lastI; i++) { | |
if (pos == -1 || i<pos) { | |
j=0; | |
while(j < patternLength && textData[i+j] == patternData[j]) { | |
comps++; | |
j++; | |
} | |
if (j == patternLength) { // we've found a match | |
#pragma omp critical (posaccess) | |
{ | |
pos = i; | |
} | |
} else { | |
comps++; | |
} | |
} | |
} | |
(*comparisons) = comps; | |
return pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment