I am trying to parallelize this piece of C code with OpenMP:
for (i = 0; i < openSetSize; i++) {
tmpF = arrayCells[openSet[i]].f;
if (tmpF <= arrayCells[openSet[best]].f && tmpF <= arrayCells[bestPath[0]].f){
isThereBest = true;
best = i;
}
}
I tried this way:
#pragma omp parallel {
int best_private = 0;
#pragma omp for nowait
for (int i = 0; i < openSetSize; i++) {
double tmpF = arrayCells[openSet[i]].f;
if (tmpF <= arrayCells[openSet[best_private]].f && tmpF <= arrayCells[bestPath[0]].f) {
isThereBest = true;
best_private = i;
}
}
#pragma omp critical
{
if(best_private > best){
best = best_private;
}
}
}
but the performance are not satisfactory at all (much more time spent with the omp version).
Does anyone have better hints? Or do know where I am wrong? Thank you so much