title: Is mutex lock required when each thread is writing to a separate cell in a shared 2d array
body: <p>Is a mutex needed in the following Parallel Computation of a Cellular Automata?</p>
  <p>I thought it was always advised to use a mutex lock when writing to a shared resource when using parallel threads.</p>
  <p>The mutex is dramatically slowing the program, but is it needed in order to ensure data in the 2d array (<code>futureOcean</code>) remains safe/consistent?</p>
  <p>When a mutex locks <code>futureOcean</code> during write operations:</p>
  <pre><code>2 threads: 163.352990 seconds
  5 threads: 515.739237 seconds
  10threads: 1021.035517 seconds
  </code></pre>
  <p>Without the use of a mutex:</p>
  <pre><code>2 threads: 65.817534 seconds
  10threads: 93.822217 seconds
  </code></pre>
  <p>I'm implementing a cellular automata model, specifically the fish, shark and ocean simulation.</p>
  <p>I've got a 1000x600 2d array called <code>ocean</code>, obviously representing the ocean.</p>
  <p>And another 1000x600 2d array called <code>futureOcean</code>, which will store the states of each cell for <code>currentGeneration + 1</code>.</p>
  <p>Initially the <code>ocean</code> is populated with:</p>
  <ul>
  <li>50% water i.e 0 values.</li>
  <li>25% fish i.e positive integer values</li>
  <li>25% shark i.e negative integer values</li>
  </ul>
  <p>Processing a single generation involves processing rules for each cell within <code>ocean</code>.</p>
  <p>Each time I compute the new value for the current cell, I store its future value in a 2nd 2d array (futureOcean), at the same <code>row</code>/<code>column</code> position that the original value is inside <code>ocean</code>. So each cell in <code>futureOcean</code> will only be updated once per generation.</p>
  <p>And I do this 20000 times (generations).</p>