title: Why this piece of parallelized code with OpenMP is not working well?
body: <p>I am trying to parallelize this piece of C code with OpenMP:</p>
  <pre><code>for (i = 0; i &lt; openSetSize; i++) {
      tmpF = arrayCells[openSet[i]].f;
      if (tmpF &lt;= arrayCells[openSet[best]].f &amp;&amp; tmpF &lt;= arrayCells[bestPath[0]].f){
          isThereBest = true;
          best = i;
      }
  }
  </code></pre>
  <p>I tried this way:</p>
  <pre><code>#pragma omp parallel {
              
      int best_private = 0;
      #pragma omp for nowait
      for (int i = 0; i &lt; openSetSize; i++) {
          double tmpF = arrayCells[openSet[i]].f;
          if (tmpF &lt;= arrayCells[openSet[best_private]].f &amp;&amp; tmpF &lt;= arrayCells[bestPath[0]].f) {
              isThereBest = true;
              best_private = i;
          }
      }
              
      #pragma omp critical
      {
          if(best_private &gt; best){
              best = best_private;
          }
      }
  }
  </code></pre>
  <p>but the performance are not satisfactory at all (much more time spent with the omp version).</p>
  <p>Does anyone have better hints? Or do know where I am wrong?
  Thank you so much</p>