Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: FFTW 3.3.5: Fortran Examples Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42:
Chris@42:

Chris@42: Next: , Previous: , Up: Calling FFTW from Legacy Fortran   [Contents][Index]

Chris@42:
Chris@42:
Chris@42: Chris@42:

8.4 Fortran Examples

Chris@42: Chris@42:

In C, you might have something like the following to transform a Chris@42: one-dimensional complex array: Chris@42:

Chris@42:
Chris@42:
        fftw_complex in[N], out[N];
Chris@42:         fftw_plan plan;
Chris@42: 
Chris@42:         plan = fftw_plan_dft_1d(N,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
Chris@42:         fftw_execute(plan);
Chris@42:         fftw_destroy_plan(plan);
Chris@42: 
Chris@42: Chris@42:

In Fortran, you would use the following to accomplish the same thing: Chris@42:

Chris@42:
Chris@42:
        double complex in, out
Chris@42:         dimension in(N), out(N)
Chris@42:         integer*8 plan
Chris@42: 
Chris@42:         call dfftw_plan_dft_1d(plan,N,in,out,FFTW_FORWARD,FFTW_ESTIMATE)
Chris@42:         call dfftw_execute_dft(plan, in, out)
Chris@42:         call dfftw_destroy_plan(plan)
Chris@42: 
Chris@42: Chris@42: Chris@42: Chris@42: Chris@42:

Notice how all routines are called as Fortran subroutines, and the Chris@42: plan is returned via the first argument to dfftw_plan_dft_1d. Chris@42: Notice also that we changed fftw_execute to Chris@42: dfftw_execute_dft (see FFTW Execution in Fortran). To do Chris@42: the same thing, but using 8 threads in parallel (see Multi-threaded FFTW), you would simply prefix these calls with: Chris@42:

Chris@42:
Chris@42:
        integer iret
Chris@42:         call dfftw_init_threads(iret)
Chris@42:         call dfftw_plan_with_nthreads(8)
Chris@42: 
Chris@42: Chris@42: Chris@42: Chris@42:

(You might want to check the value of iret: if it is zero, it Chris@42: indicates an unlikely error during thread initialization.) Chris@42:

Chris@42:

To transform a three-dimensional array in-place with C, you might do: Chris@42:

Chris@42:
Chris@42:
        fftw_complex arr[L][M][N];
Chris@42:         fftw_plan plan;
Chris@42: 
Chris@42:         plan = fftw_plan_dft_3d(L,M,N, arr,arr,
Chris@42:                                 FFTW_FORWARD, FFTW_ESTIMATE);
Chris@42:         fftw_execute(plan);
Chris@42:         fftw_destroy_plan(plan);
Chris@42: 
Chris@42: Chris@42:

In Fortran, you would use this instead: Chris@42:

Chris@42:
Chris@42:
        double complex arr
Chris@42:         dimension arr(L,M,N)
Chris@42:         integer*8 plan
Chris@42: 
Chris@42:         call dfftw_plan_dft_3d(plan, L,M,N, arr,arr,
Chris@42:        &                       FFTW_FORWARD, FFTW_ESTIMATE)
Chris@42:         call dfftw_execute_dft(plan, arr, arr)
Chris@42:         call dfftw_destroy_plan(plan)
Chris@42: 
Chris@42: Chris@42: Chris@42:

Note that we pass the array dimensions in the “natural” order in both C Chris@42: and Fortran. Chris@42:

Chris@42:

To transform a one-dimensional real array in Fortran, you might do: Chris@42:

Chris@42:
Chris@42:
        double precision in
Chris@42:         dimension in(N)
Chris@42:         double complex out
Chris@42:         dimension out(N/2 + 1)
Chris@42:         integer*8 plan
Chris@42: 
Chris@42:         call dfftw_plan_dft_r2c_1d(plan,N,in,out,FFTW_ESTIMATE)
Chris@42:         call dfftw_execute_dft_r2c(plan, in, out)
Chris@42:         call dfftw_destroy_plan(plan)
Chris@42: 
Chris@42: Chris@42: Chris@42: Chris@42:

To transform a two-dimensional real array, out of place, you might use Chris@42: the following: Chris@42:

Chris@42:
Chris@42:
        double precision in
Chris@42:         dimension in(M,N)
Chris@42:         double complex out
Chris@42:         dimension out(M/2 + 1, N)
Chris@42:         integer*8 plan
Chris@42: 
Chris@42:         call dfftw_plan_dft_r2c_2d(plan,M,N,in,out,FFTW_ESTIMATE)
Chris@42:         call dfftw_execute_dft_r2c(plan, in, out)
Chris@42:         call dfftw_destroy_plan(plan)
Chris@42: 
Chris@42: Chris@42: Chris@42:

Important: Notice that it is the first dimension of the Chris@42: complex output array that is cut in half in Fortran, rather than the Chris@42: last dimension as in C. This is a consequence of the interface routines Chris@42: reversing the order of the array dimensions passed to FFTW so that the Chris@42: Fortran program can use its ordinary column-major order. Chris@42: Chris@42: Chris@42:

Chris@42:
Chris@42:
Chris@42:

Chris@42: Next: , Previous: , Up: Calling FFTW from Legacy Fortran   [Contents][Index]

Chris@42:
Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: