Find the max location for each thread

int maxloc[MAX_THREADS], mloc;
double maxval[MAX_THREADS], mval; 
#pragma omp parallel shared(maxval,maxloc)
{
  int id = omp_get_thread_num(); 
  maxval[id] = -1.0e30;
#pragma omp for
   for (int i=0; i<n; i++) {
       if (x[i] > maxval[id]) { 
           maxloc[id] = i;
           maxval[id] = x[i]; 
       }
    }
}