             __syncthreads();
 
             histogramMultipleAdd8(HCoarse,histCoarse, 2*r+1);
-//            __syncthreads();
             int cols_m_1=cols-1;
 
              for(int j=r;j<cols-r;j++){

                histogramMedianPar8LookupOnly(HCoarse,HCoarseScan,medPos, &firstBin,&countAtMed);
                __syncthreads();

                if ( luc[firstBin] <= (j-r))
                {
                    histogramClear32(HFine[firstBin]);
                    for ( luc[firstBin] = j-r; luc[firstBin] < ::min(j+r+1,cols); luc[firstBin]++ ){
                        histogramAdd32(HFine[firstBin], hist+(luc[firstBin]*256+(firstBin<<5) ) );
                    }
                }
                else{
                    for ( ; luc[firstBin] < (j+r+1);luc[firstBin]++ ) {
                        histogramAddAndSub32(HFine[firstBin],
                        hist+(::min(luc[firstBin],cols_m_1)*256+(firstBin<<5) ),
                        hist+(::max(luc[firstBin]-2*r-1,0)*256+(firstBin<<5) ) );
                        __syncthreads();

                    }
                }
                __syncthreads();

                int leftOver=medPos-countAtMed;
                if(leftOver>=0){

                Hscan[tx]=H[tx];
            }
            __syncthreads();
            scanNeighbor(Hscan, 32,  1, tx);
            __syncthreads();
            scanNeighbor(Hscan, 32,  2, tx);
            __syncthreads();
            scanNeighbor(Hscan, 32,  4, tx);
            __syncthreads();
            scanNeighbor(Hscan, 32,  8, tx);
            __syncthreads();
            scanNeighbor(Hscan, 32, 16, tx);
            __syncthreads();

            findMedian(Hscan, 31, tx, retval, countAtMed, medPos);
         }

    __global__ void cuMedianFilterMultiBlock(PtrStepSzb src, PtrStepSzb  dest, PtrStepSzi histPar, PtrStepSzi coarseHistGrid,int r, int medPos_)
