Multi-dimensional transforms work much the same way as one-dimensional
transforms: you allocate arrays of fftw_complex (preferably
using fftw_malloc), create an fftw_plan, execute it as
many times as you want with fftw_execute(plan), and clean up
with fftw_destroy_plan(plan) (and fftw_free). The only
difference is the routine you use to create the plan:
fftw_plan fftw_plan_dft_2d(int n0, int n1,
fftw_complex *in, fftw_complex *out,
int sign, unsigned flags);
fftw_plan fftw_plan_dft_3d(int n0, int n1, int n2,
fftw_complex *in, fftw_complex *out,
int sign, unsigned flags);
fftw_plan fftw_plan_dft(int rank, const int *n,
fftw_complex *in, fftw_complex *out,
int sign, unsigned flags);
These routines create plans for n0 by n1 two-dimensional
(2d) transforms, n0 by n1 by n2 3d transforms,
and arbitrary rank-dimensional transforms, respectively. In the
third case, n is a pointer to an array n[rank] denoting
an n[0] by n[1] by ... by n[rank-1]
transform. All of these transforms operate on contiguous arrays in
the C-standard row-major order, so that the last dimension has
the fastest-varying index in the array. This layout is described
further in Multi-dimensional Array Format.
You may have noticed that all the planner routines described so far
have overlapping functionality. For example, you can plan a 1d or 2d
transform by using fftw_plan_dft with a rank of 1
or 2, or even by calling fftw_plan_dft_3d with n0
and/or n1 equal to 1 (with no loss in efficiency). This
pattern continues, and FFTW's planning routines in general form a
“partial order,” sequences of
interfaces with strictly increasing generality but correspondingly
greater complexity.
fftw_plan_dft is the most general complex-DFT routine that we
describe in this tutorial, but there are also the advanced and guru interfaces,
which allow one to efficiently combine multiple/strided transforms
into a single FFTW plan, transform a subset of a larger
multi-dimensional array, and/or to handle more general complex-number
formats. For more information, see FFTW Reference.