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