 		cudaFree(d_V);
 		cudaFree(d_out);
 
-//		cudaFree(D);
-		cudaFree(dim_D);
+		cudaFree(D);
+//		cudaFree(dim_D);
 
 		free(V);
 		free(out);

#define INIT_MAX 100
void showResult(int m, int k, int *out);

extern __shared__ int D[];

__device__ void computeDimDist(int m, int n, int *V, int *dim_D)
{
	int i = threadIdx.x;
   	int j = threadIdx.y;
	int k = threadIdx.z;
	dim_D[(i*m+j)*n+k] = (V[i*n+k]-V[j*n+k])*(V[i*n+k]-V[j*n+k]);
}

__device__ void computeDist(int m, int n, int *V, int *dim_D)
{
	int i = threadIdx.x;
   	int j = threadIdx.y;
	int k = threadIdx.z;
	int s = blockDim.y/2;
	int dist = 0;
	//dimention calculation
	computeDimDist(m, n, V, dim_D);
	__syncthreads();
	//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]);
//		}
//	}
	//paralle reduction
	if(i < j)
	{
		for(s=blockDim.y/2; s>0; s>>=1)
		{
			if(k < s)
			{
				dim_D[(i*m+j)*n+k] += dim_D[(i*m+j)*n+k+s];
			}
		}
		__syncthreads();
		dist += dim_D[(i*m+j)*n];
	}
	D[i*m+j] = dist;
}

	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)
