title: OpenMP: Locking access to single array elements?
body: <p>I'm fairly new to OpenMP, so this may have an easy answer, but I haven't been able to find it.</p>
  
  <p>Suppose I have the following C code and want to parallelize it using OpenMP. A is an array of objects which have some double value less than 1 buckets is an array of linked lists, and append adds a pointer to an object to the end fo a linked list.</p>
  
  <pre><code>#pragma omp for 
  for (i = 0; i &lt; n; ++i) {
      x = (int) (A[i].val * NUM_BUCKETS);
      append(&amp;A[i], buckets[x]);
  } 
  </code></pre>
  
  <p>The problem is that multiple threads may be trying to append items to a given bucket at one time. I could make that append statement critical. However, in my application, I'll probably have ~1000 buckets or so, so the large majority of the time the threads will be operating on different buckets. </p>
  
  <p>Is there a way to enforce locks on the individual elements of buckets? Or some other way of handling this?</p>