Created
March 10, 2014 02:15
-
-
Save mikealexander/9458404 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) { | |
j=0; | |
while(j < patternLength && textData[i+j] == patternData[j]) { | |
comps++; | |
j++; | |
} | |
if (j == patternLength) { // we've found a match | |
pos = i; // we should do something about possible RC here... atomic pragma doesn't seem to work | |
} else { | |
comps++; | |
} | |
} | |
} | |
(*comparisons) = comps; | |
return pos; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment