title: How to extract indices of all nonzero elements from an 0-1 array using OpenMP?
body: <p>I am an OpenMP beginner. I come across such a problem. </p>
  
  <p>I have a mask array <code>M</code> with the length <code>N</code>, whose element is <code>either 0 or 1</code>. I hope to extract all indices <code>i</code> that satisfies <code>M[i]=1</code> and store them into a new array <code>T</code>.</p>
  
  <p>Can this problem be accelerated by OpenMP?</p>
  
  <p>I have tried following code. But it is not performance effective.</p>
  
  <pre><code>int count = 0;
  #pragma omp parallel for
  for(int i = 0; i &lt; N; ++i) {
      if(M[i] == hashtag) {
          int pos = 0;
          #pragma omp critical (c1)
          pos = count++;
          T[pos] = i;
  }
  </code></pre>