
#include "cg.h"

__kernel void makea_4(__global int *iv,
                      __global int *last_n,
                      __global int *g_ilow,
                      __global int *g_ihigh,
                      int n,
                      int nz)
{

  int myid = get_global_id(0);
  int num_threads = get_global_size(0);
  int ilow = g_ilow[myid];
  if (ilow >= n) return;
  int ihigh = g_ihigh[myid];

  __global int *nzloc = &iv[nz];

  //---------------------------------------------------------------------
  // ... remove empty entries and generate final results
  //---------------------------------------------------------------------
  for (int j = ilow+1; j < ihigh; j++) {
    nzloc[j] = nzloc[j] + nzloc[j-1];
  }
  if (myid < num_threads) last_n[myid] = nzloc[ihigh-1];
}


