Skip to content

Instantly share code, notes, and snippets.

@mikealexander
Created March 10, 2014 02:15
Show Gist options
  • Save mikealexander/9458404 to your computer and use it in GitHub Desktop.
Save mikealexander/9458404 to your computer and use it in GitHub Desktop.

Revisions

  1. mikealexander created this gist Mar 10, 2014.
    29 changes: 29 additions & 0 deletions searching_OMP_1.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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;
    }