[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
7.1 Overview of Fortran interface
FFTW provides a file fftw3.f03
that defines Fortran 2003
interfaces for all of its C routines, except for the MPI routines
described elsewhere, which can be found in the same directory as
fftw3.h
(the C header file). In any Fortran subroutine where
you want to use FFTW functions, you should begin with:
use, intrinsic :: iso_c_binding include 'fftw3.f03'
This includes the interface definitions and the standard
iso_c_binding
module (which defines the equivalents of C
types). You can also put the FFTW functions into a module if you
prefer (see section Defining an FFTW module).
At this point, you can now call anything in the FFTW C interface directly, almost exactly as in C other than minor changes in syntax. For example:
type(C_PTR) :: plan complex(C_DOUBLE_COMPLEX), dimension(1024,1000) :: in, out plan = fftw_plan_dft_2d(1000,1024, in,out, FFTW_FORWARD,FFTW_ESTIMATE) ... call fftw_execute_dft(plan, in, out) ... call fftw_destroy_plan(plan)
A few important things to keep in mind are:
-
FFTW plans are
type(C_PTR)
. Other C types are mapped in the obvious way via theiso_c_binding
standard:int
turns intointeger(C_INT)
,fftw_complex
turns intocomplex(C_DOUBLE_COMPLEX)
,double
turns intoreal(C_DOUBLE)
, and so on. See section FFTW Fortran type reference. - Functions in C become functions in Fortran if they have a return value, and subroutines in Fortran otherwise.
- The ordering of the Fortran array dimensions must be reversed when they are passed to the FFTW plan creation, thanks to differences in array indexing conventions (see section Multi-dimensional Array Format). This is unlike the legacy Fortran interface (see section Fortran-interface routines), which reversed the dimensions for you. See section Reversing array dimensions.
- Using ordinary Fortran array declarations like this works, but may yield suboptimal performance because the data may not be not aligned to exploit SIMD instructions on modern proessors (see section SIMD alignment and fftw_malloc). Better performance will often be obtained by allocating with ‘fftw_alloc’. See section Allocating aligned memory in Fortran.
-
Similar to the legacy Fortran interface (see section FFTW Execution in Fortran), we currently recommend not using
fftw_execute
but rather using the more specialized functions likefftw_execute_dft
(see section New-array Execute Functions). However, you should execute the plan on thesame arrays
as the ones for which you created the plan, unless you are especially careful. See section Plan execution in Fortran. To prevent you from usingfftw_execute
by mistake, thefftw3.f03
file does not provide anfftw_execute
interface declaration. -
Multiple planner flags are combined with
ior
(equivalent to ‘|’ in C). e.g.FFTW_MEASURE | FFTW_DESTROY_INPUT
becomesior(FFTW_MEASURE, FFTW_DESTROY_INPUT)
. (You can also use ‘+’ as long as you don’t try to include a given flag more than once.)
7.1.1 Extended and quadruple precision in Fortran |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 17, 2014 using texi2html 5.0.