title: Insertion Sort in OpenMP
body: <p>I'm trying to write OpenMP solution for Insertion sort but I'm having problems to make it run in parallel and give correct results :). Is there any way to make Insertion sort it run in parallel.</p>
  <p>Here is my code:</p>
  <pre><code>void insertionsort(int *A, int num)
  {
      // clock_t start, stop;
      // 
      // start=clock();
      int k;
      #pragma omp parallel for shared(A) private(k)
      for(int n = 1; n &lt; num; n++)
      {
          int key = A[n];
          k = n;
          #pragma omp critical
          for(;k&gt;0 &amp;&amp; A[k-1]&gt; key;k--)
          {
              A[k] = A[k-1];   
          }
          A[k] = key;  
      }
  // stop=clock();
  // cas = (double)(stop-start)/CLOCKS_PER_SEC;
  }
  </code></pre>