0
votes

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?

1
A quick glance at an online copy of cuComplex.h suggests the cuCreal() and cuCimag() functions for accessing the real and imaginary parts of a CUDA complex number. Printing those is trivial.Shawn
C++ doesn't define printf format specifiers for complex data types. A complex number comprises a real and imaginary part. You need to retrieve the two parts and print them separately. Header file cuComplex.h exports cuCreal() and cuCimag() for this purpose.njuffa
It worked fine in addition to @gct answer.AbdelAziz AbdelLatef

1 Answers

1
votes

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