I am trying to understand why the barrier is required to remove the race condtion?
#include<omp.h>
#include<stdio.h>
int main()
{
int sum = 0;
#pragma omp parallel num_threads(4)
for(int i = 0;i < 10;i++)
{
#pragma omp parallel for num_threads(4)
for(int j = 0;j < 10;j++)
{
#pragma omp critical
sum += 1;
}
// Uncommenting this barrier removes the race condition. Right now it is non-deterministic.
// #pragma omp barrier
#pragma omp single
sum += 1;
}
printf("%d", sum);
}