cannam@95: cannam@95: cannam@95: Upgrading from FFTW version 2 - FFTW 3.3.3 cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95:
cannam@95: cannam@95:

cannam@95: Next: , cannam@95: Previous: Calling FFTW from Legacy Fortran, cannam@95: Up: Top cannam@95:


cannam@95:
cannam@95: cannam@95:

9 Upgrading from FFTW version 2

cannam@95: cannam@95:

In this chapter, we outline the process for updating codes designed for cannam@95: the older FFTW 2 interface to work with FFTW 3. The interface for FFTW cannam@95: 3 is not backwards-compatible with the interface for FFTW 2 and earlier cannam@95: versions; codes written to use those versions will fail to link with cannam@95: FFTW 3. Nor is it possible to write “compatibility wrappers” to cannam@95: bridge the gap (at least not efficiently), because FFTW 3 has different cannam@95: semantics from previous versions. However, upgrading should be a cannam@95: straightforward process because the data formats are identical and the cannam@95: overall style of planning/execution is essentially the same. cannam@95: cannam@95:

Unlike FFTW 2, there are no separate header files for real and complex cannam@95: transforms (or even for different precisions) in FFTW 3; all interfaces cannam@95: are defined in the <fftw3.h> header file. cannam@95: cannam@95:

Numeric Types

cannam@95: cannam@95:

The main difference in data types is that fftw_complex in FFTW 2 cannam@95: was defined as a struct with macros c_re and c_im cannam@95: for accessing the real/imaginary parts. (This is binary-compatible with cannam@95: FFTW 3 on any machine except perhaps for some older Crays in single cannam@95: precision.) The equivalent macros for FFTW 3 are: cannam@95: cannam@95:

     #define c_re(c) ((c)[0])
cannam@95:      #define c_im(c) ((c)[1])
cannam@95: 
cannam@95:

This does not work if you are using the C99 complex type, however, cannam@95: unless you insert a double* typecast into the above macros cannam@95: (see Complex numbers). cannam@95: cannam@95:

Also, FFTW 2 had an fftw_real typedef that was an alias for cannam@95: double (in double precision). In FFTW 3 you should just use cannam@95: double (or whatever precision you are employing). cannam@95: cannam@95:

Plans

cannam@95: cannam@95:

The major difference between FFTW 2 and FFTW 3 is in the cannam@95: planning/execution division of labor. In FFTW 2, plans were found for a cannam@95: given transform size and type, and then could be applied to any cannam@95: arrays and for any multiplicity/stride parameters. In FFTW 3, cannam@95: you specify the particular arrays, stride parameters, etcetera when cannam@95: creating the plan, and the plan is then executed for those arrays cannam@95: (unless the guru interface is used) and those parameters cannam@95: only. (FFTW 2 had “specific planner” routines that planned for cannam@95: a particular array and stride, but the plan could still be used for cannam@95: other arrays and strides.) That is, much of the information that was cannam@95: formerly specified at execution time is now specified at planning time. cannam@95: cannam@95:

Like FFTW 2's specific planner routines, the FFTW 3 planner overwrites cannam@95: the input/output arrays unless you use FFTW_ESTIMATE. cannam@95: cannam@95:

FFTW 2 had separate data types fftw_plan, fftwnd_plan, cannam@95: rfftw_plan, and rfftwnd_plan for complex and real one- and cannam@95: multi-dimensional transforms, and each type had its own ‘destroy’ cannam@95: function. In FFTW 3, all plans are of type fftw_plan and all are cannam@95: destroyed by fftw_destroy_plan(plan). cannam@95: cannam@95:

Where you formerly used fftw_create_plan and fftw_one to cannam@95: plan and compute a single 1d transform, you would now use cannam@95: fftw_plan_dft_1d to plan the transform. If you used the generic cannam@95: fftw function to execute the transform with multiplicity cannam@95: (howmany) and stride parameters, you would now use the advanced cannam@95: interface fftw_plan_many_dft to specify those parameters. The cannam@95: plans are now executed with fftw_execute(plan), which takes all cannam@95: of its parameters (including the input/output arrays) from the plan. cannam@95: cannam@95:

In-place transforms no longer interpret their output argument as scratch cannam@95: space, nor is there an FFTW_IN_PLACE flag. You simply pass the cannam@95: same pointer for both the input and output arguments. (Previously, the cannam@95: output ostride and odist parameters were ignored for cannam@95: in-place transforms; now, if they are specified via the advanced cannam@95: interface, they are significant even in the in-place case, although they cannam@95: should normally equal the corresponding input parameters.) cannam@95: cannam@95:

The FFTW_ESTIMATE and FFTW_MEASURE flags have the same cannam@95: meaning as before, although the planning time will differ. You may also cannam@95: consider using FFTW_PATIENT, which is like FFTW_MEASURE cannam@95: except that it takes more time in order to consider a wider variety of cannam@95: algorithms. cannam@95: cannam@95:

For multi-dimensional complex DFTs, instead of fftwnd_create_plan cannam@95: (or fftw2d_create_plan or fftw3d_create_plan), followed by cannam@95: fftwnd_one, you would use fftw_plan_dft (or cannam@95: fftw_plan_dft_2d or fftw_plan_dft_3d). followed by cannam@95: fftw_execute. If you used fftwnd to to specify strides cannam@95: etcetera, you would instead specify these via fftw_plan_many_dft. cannam@95: cannam@95:

The analogues to rfftw_create_plan and rfftw_one with cannam@95: FFTW_REAL_TO_COMPLEX or FFTW_COMPLEX_TO_REAL directions cannam@95: are fftw_plan_r2r_1d with kind FFTW_R2HC or cannam@95: FFTW_HC2R, followed by fftw_execute. The stride etcetera cannam@95: arguments of rfftw are now in fftw_plan_many_r2r. cannam@95: cannam@95:

Instead of rfftwnd_create_plan (or rfftw2d_create_plan or cannam@95: rfftw3d_create_plan) followed by cannam@95: rfftwnd_one_real_to_complex or cannam@95: rfftwnd_one_complex_to_real, you now use fftw_plan_dft_r2c cannam@95: (or fftw_plan_dft_r2c_2d or fftw_plan_dft_r2c_3d) or cannam@95: fftw_plan_dft_c2r (or fftw_plan_dft_c2r_2d or cannam@95: fftw_plan_dft_c2r_3d), respectively, followed by cannam@95: fftw_execute. As usual, the strides etcetera of cannam@95: rfftwnd_real_to_complex or rfftwnd_complex_to_real are no cannam@95: specified in the advanced planner routines, cannam@95: fftw_plan_many_dft_r2c or fftw_plan_many_dft_c2r. cannam@95: cannam@95:

Wisdom

cannam@95: cannam@95:

In FFTW 2, you had to supply the FFTW_USE_WISDOM flag in order to cannam@95: use wisdom; in FFTW 3, wisdom is always used. (You could simulate the cannam@95: FFTW 2 wisdom-less behavior by calling fftw_forget_wisdom after cannam@95: every planner call.) cannam@95: cannam@95:

The FFTW 3 wisdom import/export routines are almost the same as before cannam@95: (although the storage format is entirely different). There is one cannam@95: significant difference, however. In FFTW 2, the import routines would cannam@95: never read past the end of the wisdom, so you could store extra data cannam@95: beyond the wisdom in the same file, for example. In FFTW 3, the cannam@95: file-import routine may read up to a few hundred bytes past the end of cannam@95: the wisdom, so you cannot store other data just beyond it.1 cannam@95: cannam@95:

Wisdom has been enhanced by additional humility in FFTW 3: whereas FFTW cannam@95: 2 would re-use wisdom for a given transform size regardless of the cannam@95: stride etc., in FFTW 3 wisdom is only used with the strides etc. for cannam@95: which it was created. Unfortunately, this means FFTW 3 has to create cannam@95: new plans from scratch more often than FFTW 2 (in FFTW 2, planning cannam@95: e.g. one transform of size 1024 also created wisdom for all smaller cannam@95: powers of 2, but this no longer occurs). cannam@95: cannam@95:

FFTW 3 also has the new routine fftw_import_system_wisdom to cannam@95: import wisdom from a standard system-wide location. cannam@95: cannam@95:

Memory allocation

cannam@95: cannam@95:

In FFTW 3, we recommend allocating your arrays with fftw_malloc cannam@95: and deallocating them with fftw_free; this is not required, but cannam@95: allows optimal performance when SIMD acceleration is used. (Those two cannam@95: functions actually existed in FFTW 2, and worked the same way, but were cannam@95: not documented.) cannam@95: cannam@95:

In FFTW 2, there were fftw_malloc_hook and fftw_free_hook cannam@95: functions that allowed the user to replace FFTW's memory-allocation cannam@95: routines (e.g. to implement different error-handling, since by default cannam@95: FFTW prints an error message and calls exit to abort the program cannam@95: if malloc returns NULL). These hooks are not supported in cannam@95: FFTW 3; those few users who require this functionality can just cannam@95: directly modify the memory-allocation routines in FFTW (they are defined cannam@95: in kernel/alloc.c). cannam@95: cannam@95:

Fortran interface

cannam@95: cannam@95:

In FFTW 2, the subroutine names were obtained by replacing ‘fftw_’ cannam@95: with ‘fftw_f77’; in FFTW 3, you replace ‘fftw_’ with cannam@95: ‘dfftw_’ (or ‘sfftw_’ or ‘lfftw_’, depending upon the cannam@95: precision). cannam@95: cannam@95:

In FFTW 3, we have begun recommending that you always declare the type cannam@95: used to store plans as integer*8. (Too many people didn't notice cannam@95: our instruction to switch from integer to integer*8 for cannam@95: 64-bit machines.) cannam@95: cannam@95:

In FFTW 3, we provide a fftw3.f “header file” to include in cannam@95: your code (and which is officially installed on Unix systems). (In FFTW cannam@95: 2, we supplied a fftw_f77.i file, but it was not installed.) cannam@95: cannam@95:

Otherwise, the C-Fortran interface relationship is much the same as it cannam@95: was before (e.g. return values become initial parameters, and cannam@95: multi-dimensional arrays are in column-major order). Unlike FFTW 2, we cannam@95: do provide some support for wisdom import/export in Fortran cannam@95: (see Wisdom of Fortran?). cannam@95: cannam@95:

Threads

cannam@95: cannam@95:

Like FFTW 2, only the execution routines are thread-safe. All planner cannam@95: routines, etcetera, should be called by only a single thread at a time cannam@95: (see Thread safety). Unlike FFTW 2, there is no special cannam@95: FFTW_THREADSAFE flag for the planner to allow a given plan to be cannam@95: usable by multiple threads in parallel; this is now the case by default. cannam@95: cannam@95:

The multi-threaded version of FFTW 2 required you to pass the number of cannam@95: threads each time you execute the transform. The number of threads is cannam@95: now stored in the plan, and is specified before the planner is called by cannam@95: fftw_plan_with_nthreads. The threads initialization routine used cannam@95: to be called fftw_threads_init and would return zero on success; cannam@95: the new routine is called fftw_init_threads and returns zero on cannam@95: failure. See Multi-threaded FFTW. cannam@95: cannam@95:

There is no separate threads header file in FFTW 3; all the function cannam@95: prototypes are in <fftw3.h>. However, you still have to link to cannam@95: a separate library (-lfftw3_threads -lfftw3 -lm on Unix), as well as cannam@95: to the threading library (e.g. POSIX threads on Unix). cannam@95: cannam@95:

cannam@95:
cannam@95:

Footnotes

[1] We cannam@95: do our own buffering because GNU libc I/O routines are horribly slow for cannam@95: single-character I/O, apparently for thread-safety reasons (whether you cannam@95: are using threads or not).

cannam@95: cannam@95:
cannam@95: cannam@95: cannam@95: