       private(i)\
       firstprivate(n_gpus,n_rows,n_cols,gpu_range)\
       shared(partial_pops,radii,coords,sorted_coords,blimits)\
-      num_threads(n_gpus)
+      num_threads(n_gpus)\
+      schedule(dynamic,1)
     for (i=0; i < n_gpus; ++i) {
       // compute partial populations in parallel
       // on all available GPUs

                        , float* nhhd_dist_ndx
                        , unsigned int i_from
                        , unsigned int i_to) {
    extern __shared__ smem[];
    unsigned int bid = blockIdx.x;
    unsigned int tid = threadIdx.x;
    unsigned int bsize = blockDim.x;
    unsigned int gid = bid * bsize + tid;
    if (gid + offset < n_rows) {
      // load frames to compare with into shared memory
      for (unsigned int j=0; j < n_cols; ++j) {
        smem[tid*n_cols+j] = coords[(gid+offset)*n_cols+j];
      }

      for (unsigned int j=0; j < n_cols; ++j) {
        smem[ref_id*n_cols+j] = coords[gid*n_cols+j];
      }
      // load current best mindists into registers
      float nh_mindist = nh_dist_ndx[gid];
      float nhhd_mindist = nh_dist_ndx[gid];
      float nh_minndx = nh_dist_ndx[n_rows+gid];
      float nhhd_minndx = nhhd_dist_ndx[n_rows+gid];
      // compare squared distances of reference
      // to (other) frames in shared mem
      for (unsigned int i=0; i < bsize/2; ++i) {
        float dist2=0.0f;
        for (unsigned int j=0; j < n_cols; ++j) {
          float c = smem[ref_id*n_cols+j] - smem[(i+bsize/2)*n_cols+j];
          dist2 = fma(c, c, dist2);
        }
        // frame with min distance (i.e. nearest neighbor)
        if ((nh_mindist == 0)
         || (dist2 != 0 && dist2 < nh_mindist)) {
          nh_mindist = dist2;
          nh_minndx = i+offset;
        }
        // frame with min distance and lower energy
        if ((nhhd_mindist == 0)
         || (dist2 != 0 && dist2 < nhhd_mindist)) {
          nhhd_mindist = dist2;
          nhhd_minndx = i+offset;
        }
      }
      // write results (dist & ndx) to global buffers
      nh_dist_ndx[gid] = nh_mindist;
      nh_dist_ndx[n_rows+gid] = nh_minndx;
      nhhd_dist_ndx[gid] = nhhd_mindist;
      nhhd_dist_ndx[n_rows+gid] = nhhd_minndx;
    }
  }

