 		// launch knn() kernel on GPU
 		computeDist<<<grid, n, n*sizeof(int)>>>(m, n, d_V, D);
 		cudaDeviceSynchronize();
-		knn<<<m, m, m*sizeof(int)>>>(m, n, k, d_V, D, d_out);
+		knn<<<m, m, m*sizeof(int)>>>(m, n, k, d_V, D, d_out, R);
 		// record event and synchronize
 		cudaEventRecord(stop);
 		cudaEventSynchronize(stop);

	int *V, *out;				//host copies
	int *d_V, *d_out;			//device copies
	int *D;						
//	int *dim_D;					//be replaced with shared memory
	FILE *fp;
	if(argc != 2)

   	int j = blockIdx.y;
	int k = threadIdx.x;
	int s;
	// calculate the square of distance per dimensions
	computeDimDist(m, n, V);
	__syncthreads();
	// reduce duplicated calculations since d(i, j) = d(j, i)
	// also, we do not consider the trivial case of d(i, i) = 0
	// so we only compute the square distance when i < j 
	if(i < j)
	{
		// use paralel reduction
		for(s=n/2; s>0; s>>=1)
