I have the original code:
min = INT_MAX;
for (i=0;i<N;i++)
if (A[i]<min)
min = A[i];
for (i=0;i<N;i++)
A[i]=A[i]-min;
I want to get the parallel version of this and I did this:
min = INT_MAX;
#pragma omp parallel private(i){
minl = INT_MAX;
#pragma omp for
for (i=0;i<N;i++)
if (A[i]<minl)
minl=A[i];
#pragma omp critical{
if (minl<min)
min=minl;
}
#pragma omp for
for (i=0;i<N;i++)
A[i]=A[i]-min;
}
Is the parallel code right? I was wondering if it is necessary to write #pragma omp barrier before #pragma omp critical so that I make sure that all the minimums are calculated before calculating the global minimum.