title: String searching - parallel version is slower
body: <p>I am trying to paralelize naive algorithm for string searching. I created simple version and then I tried to speed it up, using multiple threads.</p>
  
  <p>But following code makes it much slower:</p>
  
  <pre><code>template&lt;typename T&gt; long unsigned int simple_paralel(const T * str1, unsigned long int str1_length, const T * str2, unsigned long int str2_length) {
    unsigned int long result = ~0;
    unsigned int long count = 0;
  
    unsigned long int in;
    unsigned int long top;
    #pragma omp parallel
    #pragma for ordered shared(result, count) private(in, top) firstprivate(str1, str2, str1_length, str2_length)
    for (top = 0; top &lt; str1_length; top++) {
      in = 0;
  
      // &amp; top + in &lt; str1_length
      while (in &lt; str2_length ) {
        if ( top + in &gt;= str1_length)
          break;
  
        if ( str1[top+in] != str2[in] ) {
          break;
        }
        ++in;
  
        if( in == str2_length ) {
          // shared and we want to have the smallest index
          if( result &gt;= top + 1 ) {
            result = top + 1;
          }
          count++;
        }
      }
    }
    return count;
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>