hello !
how to modify reduce example for sorting arrays ?
i wanna know the min/max value in array with its position in array.
i have to try expand float array to float2 array where f.x is value and f.y is position
__global__ void ExpandData(float* indata,int shift,int n,float2* expdata)
{
const unsigned int index=(blockIdx.x*blockDim.x+threadIdx.x);
expdata[index].x=indata[index];
expdata[index].y=index;
}
and sort it with single reduce, but results are wrong …
__global__ void FindSpikeReduce(float2* indata,float* sumdata,int n,int shift,float4* outdata)
{
const unsigned int tid=(blockIdx.x*threadIdx.x);
float2 temp={0,0};
for(unsigned int stride=n/2; stride>0; stride>>=1) //0918728093
{
if (tid < stride)
{
//sumdata[tid].x+=sumdata[tid+stride].x;
if (indata[tid].x<indata[tid+stride].x)
{
temp=indata[tid];
indata[tid]=indata[tid+stride];
indata[tid+stride]=temp;
}
}
__syncthreads();
}
outdata[shift].x=indata[0].x;
outdata[shift].y=indata[0].y;
outdata[shift].z=sumdata[0];
outdata[shift].w=shift;
}
classic loop finding gives correct results :
for (j = 1; j < 8; j++) {
sum+=fp_PowerSpectrum[index+j];
if (fp_PowerSpectrum[index+j] > temp) {
temp = fp_PowerSpectrum[index+j];
tpos=j;
}