I have simple program:
int index;
unsigned int count = 0;
#pragma omp parallel for
for (index = 0; index < 10000; index++)
{
count++;
}
Problem is that I think count should be equal to 10000. But instead it is usually somewhere around 5000. In about 10% it is equal to 10000.
What is going on here?
count++is not an atomic operation#pragma omp atomicit workedcount++protected byatomicis one well-trodden path to writing serial programs with the overhead of OpenMP. Don't follow that path. Instead, learn how to use OpenMP'sreductionvariables. You'll find enough to get you started by searching here on SO.