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;
}