   int blocksPerGrid = (size.z + threadsPerBlock -1) >> 8;
   dim3 DimBlock(threadsPerBlock);
   dim3 DimGrid(blocksPerGrid);
+  int nBlocks = blocksPerGrid;
 
   int threadsPerBlockDim = 16;
   int blocksPerGridX = ((size.x) + threadsPerBlockDim -1) >> 4;
   int blocksPerGridY = ((size.y) + threadsPerBlockDim -1) >> 4;
-  int nBlocks = blocksPerGridX*blocksPerGridY;
   dim3 TwoDimBlock(16,16,1);
   dim3 TwoDimGrid(blocksPerGridX,blocksPerGridY,1);
 

  __shared__ int m;

  int block_tid = blockDim.x * threadIdx.y + threadIdx.x;
  int tid = block_tid + (blockIdx.x*blockDim.x*blockDim.y)+(blockIdx.y*blockDim.x*blockDim.y*gridDim.x);
  
  ///pixel index of this thread
  int2 pos;

  cudaMalloc((void**) &d_modified, (pow2*sizeof(int)));
  CUT_CHECK_ERROR("Memory hysteresis image creation failed");

  int *d_modifsum;
  cudaMalloc((void**) &d_modifsum, (nBlocks*sizeof(int)));
  CUT_CHECK_ERROR("Memory hysteresis image creation failed");

  CUDPPConfiguration config;
  config.op = CUDPP_ADD;
  config.datatype = CUDPP_INT;
  config.algorithm = CUDPP_SCAN;
  config.options = CUDPP_OPTION_BACKWARD | CUDPP_OPTION_INCLUSIVE;

  CUDPPHandle scanplan = 0;
  CUDPPResult result = cudppPlan(&scanplan, config, nBlocks, 1, 0);  

  if (CUDPP_SUCCESS != result){
    printf("Error creating CUDPPPlan\n");
    exit(-1);
  }

  int a;
  int cont[1];
  for(a = 0; a<100; a++){

    kernel_hysteresis_glm1D<<<DimGrid,DimBlock>>>(d_hys, size, d_modified);

    cudppScan(scanplan, d_modifsum, d_modified, nBlocks);
    cudaMemcpy(cont,d_modifsum,sizeof(int),cudaMemcpyDeviceToHost);

    if (!cont[0]) break;

  }
  CUT_CHECK_ERROR("Hysteresis Kernel failed");
  //printf("Histeresis Interations: %d\n",a+1);

  result = cudppDestroyPlan(scanplan);
  if (CUDPP_SUCCESS != result){
    printf("Error destroying CUDPPPlan\n");
    exit(-1);
  }

/*********************** Teste ************************
  int i;
  int img[pow2];
  cudaMemcpy(img,d_modified,pow2*sizeof(int),cudaMemcpyDeviceToHost);
  for(i=0; i<pow2;i++){
      printf("%d ",img[i]);
  }
  printf("\n");
****************** Fim do Teste *********************/

//printf("nBlocks: %d\n", nBlocks);
//printf("pow2: %d\n", pow2);
//printf("sum: %d\n", cont[0]);


  /// bind a texture to the CUDA array
  cudaBindTexture (NULL ,hysTexRef, d_hys);
