 		cudaMalloc((void **)&d_out, m*k*sizeof(int));
 
 //		cudaMalloc((void **)&D, m*m*sizeof(int));
+		cudaMalloc((void **)&dim_D, m*m*n*sizeof(int));
 
 		for(i=0; i<m*n; i++)
 		{


extern __shared__ int D[];

__device__ void computeDist(int m, int n, int *V)
{
	int i=threadIdx.x;
   	int j=threadIdx.y;
	int k;
	int dist = 0;
	//reduce duplications
	if(i < j)
	{
		for(k=0; k<n; k++)
		{
			dist += (V[i*n+k]-V[j*n+k])*(V[i*n+k]-V[j*n+k]);
		}
	}
	D[i*m+j] = dist;
}

	return R[0];
}

__global__ void knn(int m, int n, int k, int *V, int *out, int *dim_D)
{
	int i,j;
	int temp;
	int count;
	int num;
	int dist;
	int is_duplicate;
//	__shared__ int D[m*m];

	computeDist(m, n, V, dim_D);
	__syncthreads();
	// let the first thread select the k-min dist
	i = threadIdx.x;
