title: Difference between static and dynamic schedule in OpenMP in C
body: <p>I've got two similar codes.  </p>
  
  <p>First</p>
  
  <pre><code>#pragma omp parallel for shared(g) private(i) schedule(dynamic, 1)
  for(i = (*g).actualNumberOfChromosomes; i &lt; (*g).maxNumberOfChromosomes; i++)
  {
      AddCrossoverChromosome(g, i); // it doesnt change actualNumberOfChromosomes
      #pragma omp atomic
      (*g).actualNumberOfChromosomes++;
  }
  </code></pre>
  
  <p>Second</p>
  
  <pre><code>#pragma omp parallel for shared(g) private(i) schedule(static, 1)
  for(i = (*g).actualNumberOfChromosomes; i &lt; (*g).maxNumberOfChromosomes; i++)
  {
      AddCrossoverChromosome(g, i); // it doesnt change actualNumberOfChromosomes
      #pragma omp atomic
      (*g).actualNumberOfChromosomes++;
  }
  </code></pre>
  
  <p>The only difference is in the first line. First code works fine, but the second one crashes. Why?</p>
  
  <p>Problem is somewhere in <code>actualNumberOfChromosomes</code>, but I would like to understand why, and not just solve this. I could solve this by creating addition variable <code>p</code> and assigning <code>actualNumberOfChromosomes</code> to it and changing the loop so that <code>i</code> was equal to <code>p</code>.</p>