Include cufft.h in Fortran code

Hello to everyone,

I have a Fortran code which has been made to work on CPUs, but I need to accelerate it using GPUs and I chose to do that with OpenACC.
This code uses FFTW libraries when compiled with gfortran. However, as you may know, these libraries cannot be used with nvfortran. So, I have to go with cufft libraries.
Therefore, I used this conversion giude. The problem is, fftw allows users to build a Fortran module with iso_c_binding including the file fftw.f, while cufft does not have this kind of feature and you need to include the cufft.h header.

When compiling with nvfortran (I use -cpp, -Mfree, -lcufft and -l cufftw flags, checked the include and lib directories given to -I and -L flags) I get many errors:

  • The paths in all the #include inside the cufft.h file are wrong and I had to change them manually;
  • All the comments (“//”) in the header files are seen as errors (had to remove them manually);
  • “Label field of continuation line is not blank” errors everywhere in header files, starting from line 2 (in lines 1 I solved that giving 7 spaces - but didn’t I use -Mfree for that?)

Please help me, I don’t think that the right way to do so is to change files manually…

Thanks in advance for helping

I am not that familiar with fftw.f, but in general trying to include a C header file into a Fortran compilation unit seems next to impossible.
We have Fortran interfaces to cufft, documented here. NVIDIA Fortran CUDA Library Interfaces Version 22.3 for ARM, OpenPower, x86
Our package examples we include with our compiler package also contains several examples of using cufft from Fortran, either CUDA Fortran or OpenACC. They are in
a directory like
/Linux_x86_64/22.3/examples/CUDA Libraries/cuFFT