Ryan Kelly
Ryan Kelly

Reputation: 1

Tips on improving FFTW performance for my Fortran solver?

I use a pseudospectral DNS code for fluid simulations (a code I inherited) and I'm trying to boost performance by replacing the old FFT routines with equivalent FFTW routines. I have done this successfully in that I am getting the correct answers in my test cases, but I feel like I'm doing some things inefficiently, and I would appreciate tips on specific things that might improve my code. I will show a sample code snippet of the FFT routines and then ask specific questions based on what I've observed so far.

Sample Code:

! Complex array u of size (nyp,nz,nx/2) is stored in us and normalized before transform
! mx = (3/2)nx, mz = (3/2)nz for de-aliasing

...

complex(C_DOUBLE_COMPLEX),dimension(nyp,mz,mx) :: us,aspec
real(C_DOUBLE),dimension(nyp,mz,mx) :: up,aphys

...

! Plan FFTW transforms with dummy variables
planZb = fftw_plan_dft_1d(mz,aspec,aspec,FFTW_BACKWARD,FFTW_PATIENT)
planXb = fftw_plan_dft_c2r_1d(mx,aspec,aphys,FFTW_PATIENT)
planY  = fftw_plan_r2r_1d(nyp,aphys,aphys,FFTW_REDFT00,FFTW_PATIENT)

...

! Complex --> Complex z-transform
do k = 1,nxh
    do i = 1,nyp
        call fftw_execute_dft(planZb,us(i,:,k),us(i,:,k))
        .
        .
        .
    end do
end do

! Complex --> Real x-transform
do j = 1,mz
    do i = 1,nyp
        call fftw_execute_dft_c2r(planXb,us(i,j,:),up(i,j,:))
        .
        .
        .
    end do
end do

! Real --> Real y-transform (DCT-I)
do k = 1,mx
    do j = 1,mz
        call fftw_execute_r2r(planY,up(:,j,k),up(:,j,k))
        .
        .
        .
    end do
end do

! Do stuff here

! Inverse transforms here, reverse process above + normalizations

Notes:

For the sake of having a single, consolidated question:

Is it worth using FFTW's advanced/guru interface to replace these FFT loops? It seems this requires data shuffling which is quite expensive, but I'm not sure if FFTW has a good way of handling that.

Thanks!

Upvotes: 0

Views: 84

Answers (0)

Related Questions