I want to implement the following function, which marks some elements of an array by 1.
void mark(std::vector<signed char>& marker)
{
#pragma omp parallel for schedule(dynamic, M)
for (int i = 0; i < marker.size; i++)
marker[i] = 0;
#pragma omp parallel for schedule(dynamic, M)
for (int i = 0; i < marker.size; i++)
marker[getIndex(i)] = 1;
}
What happens if we try to simultaneously set the value of one element to 1 in different threads? Will it be normally set to 1, or can this loop lead to unexpected behavior?
source
share