Search code examples
c++cudaprintfcomplex-numbers

How can I print a variable of type cufftDoubleComplex?


How can I print a variable of type cufftDoubleComplex in CUDA C++, I tried doing this using printf:

cufftDoubleComplex Fd;
printf("%f", Fd); //not working

but I got this error and it didn't work during runtime:

warning C4477: 'printf' : format string '%f' requires an argument of type 'double', but variadic argument 1 has type 'cufftDoubleComplex'

How can I print it? What is the proper format string to use inside printf?


Solution

  • It'll be layout compatible with double[2], so just cast it and print the two fields:

    printf("re: %f  im: %f\n", ((double*)&Fd)[0], ((double*)&Fd)[1]);
    

    This isn't "safe safe" but since CuFFT promises to be compatible with fftw, the layout of the type is guaranteed to be compatible in this way.

    Edit, this is preferable, cufftDoubleComplex is a typedef of cuDoubleComplex which just has two fields x,y (bad names):

    printf("re: %f  im: %f\n", Fd.x, Fd.y);