Some part out CUFFT output is missing.(or inaccurate.)

Hello.

I’ve made some code for 1D FFT.

In short, My code run CUFFT after import data from a txt file.

total size of array is 10000.

During a half, output is good. But after half, outcome is zero or inaccurate number.

What’s the wrong?(I assume that this maybe thread number problem or batch variable. But I don’t know what should I insert number of batch variable.

If you possible, plz explain what’s the real meaning of batch number in CUFFT 1D. And its application for real codes.)

Here’s my code.(Under VS2010&WIN7&64bit machine. GPU - 560ti)

plz, Help me.

#include <stdio.h>

#include <cuda.h>

#include <cuda_runtime.h>

#include <cuda_runtime_api.h>

#include <cufft.h>

#define SizeofArray 10000

host void ArrayGetFromData(float a,const char *name)

{

FILE *cfPtr;

float ca = .0;

int count = 0;

if((cfPtr = fopen(name,"r"))==NULL)

{

	printf("File couldn't be opened.\n");

}

else

{

	while(!feof(cfPtr))

	{

		fscanf(cfPtr,"%f",&ca);

		a[count] = ca;

		count++;

	}

}

fclose(cfPtr);

}

host void ArrayGetToTxt(cufftComplex *odata,const char *name)

{

FILE *cfPtr;

float ca = .0;

int count = 0;

if((cfPtr = fopen(name,"w"))==NULL)

{

	printf("File couldn't be opened.\n");

}

else

{

	for(int i =0; i < SizeofArray; i++)

	{

		fprintf(cfPtr,"%f\t%f\n",odata[i].x,odata[i].y);

	}

}

fclose(cfPtr);

}

int main()

{

float intensity = {0};

ArrayGetFromData(intensity,"Freq_1.txt");

	

printf("%f\n",intensity[8000]);

	

cufftHandle plan;

cufftReal *pdata = 0;

cufftComplex *finaldata = new cufftComplex;

cufftComplex *forodata = new cufftComplex;

cufftReal *idata;

cufftComplex *odata;		

cudaMalloc(&idata,sizeof(cufftReal)*SizeofArray);

cudaMalloc(&odata,sizeof(cufftComplex)*SizeofArray);

cudaMemcpy(idata,intensity,sizeof(cufftReal)*SizeofArray,cudaMemcpyHostToDevice);	

cudaMemcpy(odata,forodata,sizeof(cufftComplex)*SizeofArray,cudaMemcpyHostToDevice);

cufftPlan1d(&plan,SizeofArray,CUFFT_R2C,1);



cufftExecR2C(plan,idata,odata);

cudaMemcpy(finaldata,odata,sizeof(cufftComplex)*SizeofArray,cudaMemcpyDeviceToHost);

printf("%f\n",finaldata[8000].x);



ArrayGetToTxt(finaldata,"OutCome.txt");

	

cufftDestroy(plan);

	

cudaFree(idata);

cudaFree(odata);

delete[] finaldata;



return 0;

}

The real to complex transform only gives out N/2+1 complex numbers, where N is size of the real array. This corresponds to the positive frequencies spectrum, while the negative is just the complex conjugate. It works as it should be.

Thanks pasoleatis! Because of your advice I’ve known output of freq that are just only positive freqs.

And I’ve fixed my outputs. Thanks.