d@0: d@0:
d@0:d@0: d@0: Next: Installation and Customization, d@0: Previous: Calling FFTW from Fortran, d@0: Up: Top d@0:
In this chapter, we outline the process for updating codes designed for d@0: the older FFTW 2 interface to work with FFTW 3. The interface for FFTW d@0: 3 is not backwards-compatible with the interface for FFTW 2 and earlier d@0: versions; codes written to use those versions will fail to link with d@0: FFTW 3. Nor is it possible to write “compatibility wrappers” to d@0: bridge the gap (at least not efficiently), because FFTW 3 has different d@0: semantics from previous versions. However, upgrading should be a d@0: straightforward process because the data formats are identical and the d@0: overall style of planning/execution is essentially the same. d@0: d@0:
Unlike FFTW 2, there are no separate header files for real and complex
d@0: transforms (or even for different precisions) in FFTW 3; all interfaces
d@0: are defined in the <fftw3.h>
header file.
d@0:
d@0:
The main difference in data types is that fftw_complex
in FFTW 2
d@0: was defined as a struct
with macros c_re
and c_im
d@0: for accessing the real/imaginary parts. (This is binary-compatible with
d@0: FFTW 3 on any machine except perhaps for some older Crays in single
d@0: precision.) The equivalent macros for FFTW 3 are:
d@0:
d@0:
#define c_re(c) ((c)[0]) d@0: #define c_im(c) ((c)[1]) d@0:d@0:
This does not work if you are using the C99 complex type, however,
d@0: unless you insert a double*
typecast into the above macros
d@0: (see Complex numbers).
d@0:
d@0:
Also, FFTW 2 had an fftw_real
typedef that was an alias for
d@0: double
(in double precision). In FFTW 3 you should just use
d@0: double
(or whatever precision you are employing).
d@0:
d@0:
The major difference between FFTW 2 and FFTW 3 is in the d@0: planning/execution division of labor. In FFTW 2, plans were found for a d@0: given transform size and type, and then could be applied to any d@0: arrays and for any multiplicity/stride parameters. In FFTW 3, d@0: you specify the particular arrays, stride parameters, etcetera when d@0: creating the plan, and the plan is then executed for those arrays d@0: (unless the guru interface is used) and those parameters d@0: only. (FFTW 2 had “specific planner” routines that planned for d@0: a particular array and stride, but the plan could still be used for d@0: other arrays and strides.) That is, much of the information that was d@0: formerly specified at execution time is now specified at planning time. d@0: d@0:
Like FFTW 2's specific planner routines, the FFTW 3 planner overwrites
d@0: the input/output arrays unless you use FFTW_ESTIMATE
.
d@0:
d@0:
FFTW 2 had separate data types fftw_plan
, fftwnd_plan
,
d@0: rfftw_plan
, and rfftwnd_plan
for complex and real one- and
d@0: multi-dimensional transforms, and each type had its own `destroy'
d@0: function. In FFTW 3, all plans are of type fftw_plan
and all are
d@0: destroyed by fftw_destroy_plan(plan)
.
d@0:
d@0:
Where you formerly used fftw_create_plan
and fftw_one
to
d@0: plan and compute a single 1d transform, you would now use
d@0: fftw_plan_dft_1d
to plan the transform. If you used the generic
d@0: fftw
function to execute the transform with multiplicity
d@0: (howmany
) and stride parameters, you would now use the advanced
d@0: interface fftw_plan_many_dft
to specify those parameters. The
d@0: plans are now executed with fftw_execute(plan)
, which takes all
d@0: of its parameters (including the input/output arrays) from the plan.
d@0:
d@0:
In-place transforms no longer interpret their output argument as scratch
d@0: space, nor is there an FFTW_IN_PLACE
flag. You simply pass the
d@0: same pointer for both the input and output arguments. (Previously, the
d@0: output ostride
and odist
parameters were ignored for
d@0: in-place transforms; now, if they are specified via the advanced
d@0: interface, they are significant even in the in-place case, although they
d@0: should normally equal the corresponding input parameters.)
d@0:
d@0:
The FFTW_ESTIMATE
and FFTW_MEASURE
flags have the same
d@0: meaning as before, although the planning time will differ. You may also
d@0: consider using FFTW_PATIENT
, which is like FFTW_MEASURE
d@0: except that it takes more time in order to consider a wider variety of
d@0: algorithms.
d@0:
d@0:
For multi-dimensional complex DFTs, instead of fftwnd_create_plan
d@0: (or fftw2d_create_plan
or fftw3d_create_plan
), followed by
d@0: fftwnd_one
, you would use fftw_plan_dft
(or
d@0: fftw_plan_dft_2d
or fftw_plan_dft_3d
). followed by
d@0: fftw_execute
. If you used fftwnd
to to specify strides
d@0: etcetera, you would instead specify these via fftw_plan_many_dft
.
d@0:
d@0:
The analogues to rfftw_create_plan
and rfftw_one
with
d@0: FFTW_REAL_TO_COMPLEX
or FFTW_COMPLEX_TO_REAL
directions
d@0: are fftw_plan_r2r_1d
with kind FFTW_R2HC
or
d@0: FFTW_HC2R
, followed by fftw_execute
. The stride etcetera
d@0: arguments of rfftw
are now in fftw_plan_many_r2r
.
d@0:
d@0:
Instead of rfftwnd_create_plan
(or rfftw2d_create_plan
or
d@0: rfftw3d_create_plan
) followed by
d@0: rfftwnd_one_real_to_complex
or
d@0: rfftwnd_one_complex_to_real
, you now use fftw_plan_dft_r2c
d@0: (or fftw_plan_dft_r2c_2d
or fftw_plan_dft_r2c_3d
) or
d@0: fftw_plan_dft_c2r
(or fftw_plan_dft_c2r_2d
or
d@0: fftw_plan_dft_c2r_3d
), respectively, followed by
d@0: fftw_execute
. As usual, the strides etcetera of
d@0: rfftwnd_real_to_complex
or rfftwnd_complex_to_real
are no
d@0: specified in the advanced planner routines,
d@0: fftw_plan_many_dft_r2c
or fftw_plan_many_dft_c2r
.
d@0:
d@0:
In FFTW 2, you had to supply the FFTW_USE_WISDOM
flag in order to
d@0: use wisdom; in FFTW 3, wisdom is always used. (You could simulate the
d@0: FFTW 2 wisdom-less behavior by calling fftw_forget_wisdom
after
d@0: every planner call.)
d@0:
d@0:
The FFTW 3 wisdom import/export routines are almost the same as before d@0: (although the storage format is entirely different). There is one d@0: significant difference, however. In FFTW 2, the import routines would d@0: never read past the end of the wisdom, so you could store extra data d@0: beyond the wisdom in the same file, for example. In FFTW 3, the d@0: file-import routine may read up to a few hundred bytes past the end of d@0: the wisdom, so you cannot store other data just beyond it.1 d@0: d@0:
Wisdom has been enhanced by additional humility in FFTW 3: whereas FFTW d@0: 2 would re-use wisdom for a given transform size regardless of the d@0: stride etc., in FFTW 3 wisdom is only used with the strides etc. for d@0: which it was created. Unfortunately, this means FFTW 3 has to create d@0: new plans from scratch more often than FFTW 2 (in FFTW 2, planning d@0: e.g. one transform of size 1024 also created wisdom for all smaller d@0: powers of 2, but this no longer occurs). d@0: d@0:
FFTW 3 also has the new routine fftw_import_system_wisdom
to
d@0: import wisdom from a standard system-wide location.
d@0:
d@0:
In FFTW 3, we recommend allocating your arrays with fftw_malloc
d@0: and deallocating them with fftw_free
; this is not required, but
d@0: allows optimal performance when SIMD acceleration is used. (Those two
d@0: functions actually existed in FFTW 2, and worked the same way, but were
d@0: not documented.)
d@0:
d@0:
In FFTW 2, there were fftw_malloc_hook
and fftw_free_hook
d@0: functions that allowed the user to replace FFTW's memory-allocation
d@0: routines (e.g. to implement different error-handling, since by default
d@0: FFTW prints an error message and calls exit
to abort the program
d@0: if malloc
returns NULL
). These hooks are not supported in
d@0: FFTW 3; those few users who require this functionality can just
d@0: directly modify the memory-allocation routines in FFTW (they are defined
d@0: in kernel/alloc.c
).
d@0:
d@0:
In FFTW 2, the subroutine names were obtained by replacing `fftw_' d@0: with `fftw_f77'; in FFTW 3, you replace `fftw_' with d@0: `dfftw_' (or `sfftw_' or `lfftw_', depending upon the d@0: precision). d@0: d@0:
In FFTW 3, we have begun recommending that you always declare the type
d@0: used to store plans as integer*8
. (Too many people didn't notice
d@0: our instruction to switch from integer
to integer*8
for
d@0: 64-bit machines.)
d@0:
d@0:
In FFTW 3, we provide a fftw3.f
“header file” to include in
d@0: your code (and which is officially installed on Unix systems). (In FFTW
d@0: 2, we supplied a fftw_f77.i
file, but it was not installed.)
d@0:
d@0:
Otherwise, the C-Fortran interface relationship is much the same as it d@0: was before (e.g. return values become initial parameters, and d@0: multi-dimensional arrays are in column-major order). Unlike FFTW 2, we d@0: do provide some support for wisdom import/export in Fortran d@0: (see Wisdom of Fortran?). d@0: d@0:
Like FFTW 2, only the execution routines are thread-safe. All planner
d@0: routines, etcetera, should be called by only a single thread at a time
d@0: (see Thread safety). Unlike FFTW 2, there is no special
d@0: FFTW_THREADSAFE
flag for the planner to allow a given plan to be
d@0: usable by multiple threads in parallel; this is now the case by default.
d@0:
d@0:
The multi-threaded version of FFTW 2 required you to pass the number of
d@0: threads each time you execute the transform. The number of threads is
d@0: now stored in the plan, and is specified before the planner is called by
d@0: fftw_plan_with_nthreads
. The threads initialization routine used
d@0: to be called fftw_threads_init
and would return zero on success;
d@0: the new routine is called fftw_init_threads
and returns zero on
d@0: failure. See Multi-threaded FFTW.
d@0:
d@0:
There is no separate threads header file in FFTW 3; all the function
d@0: prototypes are in <fftw3.h>
. However, you still have to link to
d@0: a separate library (-lfftw3_threads -lfftw3 -lm
on Unix), as well as
d@0: to the threading library (e.g. POSIX threads on Unix).
d@0:
d@0:
d@0:
[1] We d@0: do our own buffering because GNU libc I/O routines are horribly slow for d@0: single-character I/O, apparently for thread-safety reasons (whether you d@0: are using threads or not).
d@0: d@0: