   // Define block and grid size
   const int y_dim = MAX_THREADS/NUM_THREADS;
   dim3 blockSize(NUM_THREADS,y_dim);
-  const int num_blocks = Q/NUM_THREADS + 1;
+  const int num_blocks = Q/y_dim + 1;
   dim3 gridSize(num_blocks,1);
 /*
   printf("Block size = %d, grid size = %d, number of elements (N) = %d\n", 
           NUM_THREADS, num_blocks, D);
 */
-  // Matrix to prepare the data to pass to device
+/*  // Matrix to prepare the data to pass to device
   double *prepA, *prepB;
   prepA = (double*)malloc(NUM_THREADS*Q*sizeof(double));
   prepB = (double*)malloc(NUM_THREADS*Q*sizeof(double));

 */
/*
  printf("--- Print matrix A ---\n");
  print_GPU_Mat(A,Q*NUM_THREADS);
  printf("--- Print matrix B ---\n");
  print_GPU_Mat(B,Q*NUM_THREADS);
*//*
  printf("--- Print matrix RetMat ---\n");
  print_GPU_Mat(RetMat,D);

  }

  // Save the sum at the appropriate position in the diff vector.
  if (tix == 0) diff[blockIdx.x*blockDim.y + tiy] = Z[0][tiy];

}

