 	hist_type* devHist;
 	int32_t memBytesHist=sizeof(hist_type)*cols*MF_HIST_SIZE;
 
+	cudaSetDevice(1);
+
+	// Allocating host and device memory.
 	hostSrc=(im_type*)malloc(memBytesImage);
 	hostDest=(im_type*)malloc(memBytesImage);
 	hostRef=(im_type*)malloc(memBytesImage);
-
-	readImage("barbara.csv", hostSrc, rows, cols);
-
-
 	CUDA(cudaMalloc((void**)(&devSrc), memBytesImage));
 	CUDA(cudaMalloc((void**)(&devDest), memBytesImage));
 	CUDA(cudaMalloc((void**)(&devHist), memBytesHist));
 
+	// Loading image from file
+	char filename[]="barbara.csv";
+	readImage(filename, hostSrc, rows, cols);
+
+	// Copying data from host to device.
 	CUDA(cudaMemcpy(devSrc,hostSrc,memBytesImage,cudaMemcpyHostToDevice));
+//	CUDA(cudaMemcpy(devDest,hostSrc,memBytesImage,cudaMemcpyHostToDevice));
+	CUDA(cudaMemset(devDest,0,memBytesImage));
+	CUDA(cudaMemset(devHist,0,memBytesHist));
 
 
 	int32_t kernel=5;
 	int32_t r=(kernel-1)/2;
 	int32_t medPos=2*r*r+2*r;
 
+	// Setting CUDA kernel properties.
 	dim3 gridDim; gridDim.x=1;
 	dim3 blockDim; blockDim.x=256;
+
 	cudaEvent_t start,stop; float time;
 	cudaEventCreate(&start); cudaEventCreate(&stop);
 	cudaEventRecord(start,0);

			int32_t f1=im1[r*cols+c];
			int32_t f2=im2[r*cols+c];
			mse+= (f1-f2)*(f1-f2);
		}
	}
	if (mse==0)
		return 100;
	float fmse=mse/(cols*rows);
	return 20*log10(255/sqrt(fmse) );


#include <stdio.h>
#include <inttypes.h>


#define TEST
// THREADS is defined to be the max threads
#define MAX_THREADS 256
