title: How do I use a increment operator in parallel in OpenMP
body: <p>I want to increment <code>count</code> variable in all of my threads if a condition is met. Is there a better way to do this other than enclosing the <code>count</code> variable in a critical block or using <code>count[]</code> as an array?</p>
  <pre><code>pragma omp parallel for num_threads(number_of_threads)
  
  int id = omp_get_thread_num();    
  for(i=1; i &lt; ht; i++) { 
      for(j=1; j &lt; wd; j++) {
                              
              // Some random code
                              
              double mag = sqrt(a[i] * a[i] + b[j] * b[j]); 
                  
              if(mag &gt; 100) {         
                    #pragma omp critical 
                    { 
                          count++;
                    }
              } else {
                    // do nothing
              }
          }
      }
  }
  </code></pre>