global void ranksort(int * device_array)
{
int tx = threadIdx.x;
int bx = blockIdx.x;
//s is the rank of the current number
int i, j, s = 0;
int temp = 0;
shared int sharaed_array[BLOCK_SIZE];
sharaed_array[tx] = device_array[bx * blockDim.x + tx];
temp = sharaed_array[tx];
__syncthreads();
//compare the number in the current block
for(j = 0; j < blockDim.x; j++)
if(sharaed_array[j] < temp) //14行
s++; //15行
__syncthreads();
//compare the number before the current block
for(i = 0;i < blockIdx.x; i++)
{
sharaed_array[tx] = device_array[i * blockDim.x + tx];
__syncthreads();
for(j = 0;j < blockDim.x; j++)
{
if(sharaed_array[j] < temp)
s++;
}
__syncthreads();
}
//compare the number after the current block
for(i = blockIdx.x+1; i<gridDim.x; i++)
{
sharaed_array[tx] = device_array[i * blockDim.x + tx];
__syncthreads();
for(j = 0; j < blockDim.x; j++)
{
if(sharaed_array[j] < temp)
s++;
}
}
device_array[s] = temp;
}
这是网上找的一个关于数组排序的kernel程序,想请教一下,14,15行是什么意思,每个线程是怎么样工作的,麻烦高手解答一下,谢谢。