title: openmp: barrier synchronization not working within loop with if condition
body: <p>I have the following code:</p>
  
  <pre><code>#pragma omp parallel shared(a,n) private(i,j,k,x,pid,rows,mymin,mymax)
  {
      //  nprocs=1;
  #ifdef _OPENMP
      nprocs=omp_get_num_threads();
  #endif
  
  #ifdef _OPENMP
      pid=omp_get_thread_num();
  #endif
  
      rows=n/nprocs;
      mymin=pid * rows;
      mymax=mymin + rows - 1;
  
      for(k=0;k&lt;n;k++){
          if(k&gt;=mymin &amp;&amp; k&lt;=mymax){
  #pragma omp for schedule(static,rows)
              for(x=k+1;x&lt;n;x++){
                  a[k][x]= a[k][x]/a[k][k];
              }
  #pragma omp barrier
          }
      }
  }
  </code></pre>
  
  <p>Here I am selecting which thread will update which row of matrix based on the if condition. For eg, if there are two threads, thread 1 will update first two rows of matrix 'a' and thread 2 will update the other two.</p>
  
  <p>And after I selected that, I divide the iterations on the columns of that row by paralleling the inner loop among thread 1 and two( where I start     <code>for(x=k+1,x&lt;n;x++)</code>). I am also putting a barrier after the inner for loop so that after every column value of single row is updated, its synchronized.</p>
  
  <p>But the problem is I am not getting proper synchronized values. In the final matrix, some values updated by thread 0 are shown in some rows and some by other thread but not all.  </p>