 						}
 				}
 		}
+//		cudaFree(d_m);
+//		cudaFree(d_n);
+//		cudaFree(d_k);
+		cudaFree(d_V);
+		cudaFree(d_out);
+
 		free(V);
 		free(out);
+
+		V = NULL;
+		out = NULL;
 	}
 	fclose(fp);
 	return 0;

	{
		printf("m:%d, n:%d, k:%d\n", m, n, k);

		V = (int *) malloc(m*n*sizeof(int));
		out = (int *) malloc(m*k*sizeof(int));
		for(i=0; i<m*n; i++)
		{
			fscanf(fp, "%d", &V[i]);
		}
		knn(m, n, k, V, out);
		for(i=0; i<m; i++)
		{
				for(j=0; j<k; j++)

			}
		}
	}
//	showResult(m, k, out);
}

//__host__ __device__ void showResult(int m, int k, int *out)
void showResult(int m, int k, int *out)
{
	int i,j;
	for(i=0; i<m; i++)
	{
		for(j=0; j<k; j++)
		{
				printf("%d", out[i*k+j]);
				if(j == k-1)
				{
						printf("\n");
				}
				else
				{
						printf(" ");
				}
		}
	} 
} 
int main(int argc, char *argv[]) 
{ 
	int m,n,k;
//	int *d_m, *d_n, *d_k;
	int i,j;
	int *V, *out;					//host copies
	int *d_V, *d_out;			//device copies
	FILE *fp;
	if(argc != 2)
	{
