I have a for loop in the following code.
int min = -1;
int pos;
int array[100];
for(i = 0; i < 100; i++){
if(array[i] < min || min == -1){
min = array[i];
pos = i;
}
}
I think that the following code is a correct implementation with openMP but it is too slow.
int min = -1;
int pos;
int array[100];
#pragma omp parallel for default(none) shared(array, min)
for(i = 0; i < 100; i++){
#pragma omp critical
{
if(array[i] < min || min == -1){
min = array[i];
pos = i;
}
}
}
I think that could be data hazards if i put the critical section inside the condition instead of outside. There is a smart way to implement it? Some suggestions?
min = -1shouldn't this bemin == -1?ints? You might start to see speed up if you properly parallelized the loop and used it on a much larger array.