How to implement argmax with OpenMP?
I am trying to implement a argmax with OpenMP. If short, I have a function that computes a floating point value: double toOptimize(int val); I can get the integer maximizing the value with: double best = 0; #pragma omp parallel for reduction(max: best) for(int i = 2 ; i < MAX ; ++i) { double v = toOptimize(i); if(v > best) best = v; } Now, how can I get the value i corresponding to the maximum? Edit: I am trying this, but would like to make sure it is valid: double best_value = 0; int best_arg = 0; #pragma omp parallel { double local_best = 0; int ba = 0; #pragma omp for reduction(max: best