Skip to content

Instantly share code, notes, and snippets.

@mikealexander
Created March 10, 2014 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikealexander/9458404 to your computer and use it in GitHub Desktop.
Save mikealexander/9458404 to your computer and use it in GitHub Desktop.
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