 //fused kernel
 //each block solves a A*x=b 
 __global__ void updateXWithCGKernel(float * A, float * x, float * b, const int batchSize, const int f, const float cgIter){
-	__shared__ float smem[404];
+	extern __shared__ float smem[];
 	float *sharedx = &smem[0];
-	float *sharedp = &smem[100];
-	float *sharedr = &smem[200];
-	float *sharedap = &smem[300];
-	float *rsold = &smem[400]; 
-	float *alpha = &smem[401];
-	float *rsnew = &smem[402];
-	float *beta = &smem[403];
+	float *sharedp = &smem[f];
+	float *sharedr = &smem[2*f];
+	float *sharedap = &smem[3*f];
+	float *rsold = &smem[4*f]; 
+	float *alpha = &smem[4*f+1];
+	float *rsnew = &smem[4*f+2];
+	float *beta = &smem[4*f+3];
 
 	//sharedx<--x
 	sharedx[threadIdx.x] = x[blockIdx.x*blockDim.x + threadIdx.x];

		__syncthreads();
		if(threadIdx.x==0){
			printf("***shared memory content before 3rd blockReduceSum:\n");
			for(int i = 0; i < 100; i++)
				printf("%f ", sharedp[i]);
			printf("\n");
			for(int i = 0; i < 100; i++)
				printf("%f ", sharedr[i]);
			printf("\n");
			for(int i = 0; i < 100; i++)
				printf("%f ", sharedap[i]);
			printf("\n");
		}

				printf("%f ", sharedap[i]);
			printf("\n");
			printf("***shared memory content before 2rd blockReduceSum:\n");
			for(int i = 0; i < f; i++)
				printf("%f ", sharedp[i]);
			printf("\n");
			for(int i = 0; i < f; i++)
				printf("%f ", sharedr[i]);
			printf("\n");
			for(int i = 0; i < f; i++)
				printf("%f ", sharedap[i]);
			printf("\n");
		}
