Combine the values from each thread

#pragma omp flush (maxloc,maxval)
#pragma omp master
  {
    int nt = omp_get_num_threads(); 
    mloc = maxloc[0]; 
    mval = maxval[0]; 
    for (int i=1; i<nt; i++) {
        if (maxval[i] > mval) { 
           mval = maxval[i]; 
           mloc = maxloc[i];
        } 
     }
   }

Note that we let the master process perform the last operation.