d@0: d@0:
d@0:d@0: d@0: Next: Wisdom of Fortran?, d@0: Previous: FFTW Execution in Fortran, d@0: Up: Calling FFTW from Fortran d@0:
In C, you might have something like the following to transform a d@0: one-dimensional complex array: d@0: d@0:
fftw_complex in[N], out[N]; d@0: fftw_plan plan; d@0: d@0: plan = fftw_plan_dft_1d(N,in,out,FFTW_FORWARD,FFTW_ESTIMATE); d@0: fftw_execute(plan); d@0: fftw_destroy_plan(plan); d@0:d@0:
In Fortran, you would use the following to accomplish the same thing: d@0: d@0:
double complex in, out d@0: dimension in(N), out(N) d@0: integer*8 plan d@0: d@0: call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE) d@0: call dfftw_execute_dft(plan, in, out) d@0: call dfftw_destroy_plan(plan) d@0:d@0:
d@0: Notice how all routines are called as Fortran subroutines, and the
d@0: plan is returned via the first argument to dfftw_plan_dft_1d
.
d@0: Notice also that we changed fftw_execute
to
d@0: dfftw_execute_dft
(see FFTW Execution in Fortran). To do
d@0: the same thing, but using 8 threads in parallel (see Multi-threaded FFTW), you would simply prefix these calls with:
d@0:
d@0:
call dfftw_init_threads d@0: call dfftw_plan_with_nthreads(8) d@0:d@0:
d@0: To transform a three-dimensional array in-place with C, you might do: d@0: d@0:
fftw_complex arr[L][M][N]; d@0: fftw_plan plan; d@0: d@0: plan = fftw_plan_dft_3d(L,M,N, arr,arr, d@0: FFTW_FORWARD, FFTW_ESTIMATE); d@0: fftw_execute(plan); d@0: fftw_destroy_plan(plan); d@0:d@0:
In Fortran, you would use this instead: d@0: d@0:
double complex arr d@0: dimension arr(L,M,N) d@0: integer*8 plan d@0: d@0: call dfftw_plan_dft_3d(plan, L,M,N, arr,arr, d@0: & FFTW_FORWARD, FFTW_ESTIMATE) d@0: call dfftw_execute_dft(plan, arr, arr) d@0: call dfftw_destroy_plan(plan) d@0:d@0:
d@0: Note that we pass the array dimensions in the “natural” order in both C d@0: and Fortran. d@0: d@0:
To transform a one-dimensional real array in Fortran, you might do: d@0: d@0:
double precision in d@0: dimension in(N) d@0: double complex out d@0: dimension out(N/2 + 1) d@0: integer*8 plan d@0: d@0: call dfftw_plan_dft_r2c_1d(plan,N,in,out,FFTW_ESTIMATE) d@0: call dfftw_execute_dft_r2c(plan, in, out) d@0: call dfftw_destroy_plan(plan) d@0:d@0:
d@0: To transform a two-dimensional real array, out of place, you might use d@0: the following: d@0: d@0:
double precision in d@0: dimension in(M,N) d@0: double complex out d@0: dimension out(M/2 + 1, N) d@0: integer*8 plan d@0: d@0: call dfftw_plan_dft_r2c_2d(plan,M,N,in,out,FFTW_ESTIMATE) d@0: call dfftw_execute_dft_r2c(plan, in, out) d@0: call dfftw_destroy_plan(plan) d@0:d@0:
d@0: Important: Notice that it is the first dimension of the d@0: complex output array that is cut in half in Fortran, rather than the d@0: last dimension as in C. This is a consequence of the interface routines d@0: reversing the order of the array dimensions passed to FFTW so that the d@0: Fortran program can use its ordinary column-major order. d@0: d@0: d@0: d@0: d@0: