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