FFTW - Fastest Fourier Transform in the West
FFTW is a comprehensive collection of fast C routines for computing the discrete Fourier transform (DFT) in one or more dimensions, of both real and complex data, and of arbitrary input size. FFTW also includes parallel transforms for distributed-memory systems. FFTW is usually faster (and sometimes much faster) than all other freely-available Fourier transform programs found on the Net.
Introductory Remarks
Authors of the Library
The FFTW package was developed at MIT by Matteo Frigo and Steven G. Johnson.
Using the FFTW installations at LRZ
FFTW is provided on many LRZ HPC platforms.
To prepare for using the library, first check which environment modules there are for FFTW:
module av fftw # will display several versions
then see what environment variables does it offer, e.g.:
module show fftw # many FFTW-prefixed environment variables will be displayed
then you can load it, e.g.:
module load fftw # mere 'fftw' reverts to the default one
and compile programs or run an FFTW-enabled program using those variables adequately.
We provide several modules for FFTW: to learn details about them, please use `module whatis fftw
`.
To check a module's details (MPI support, threading support, etc), check: `module show fftw..
`.
Here an example compiling a source file by including the FFTW headers:
icc -c $FFTW_INC foo.c
and linking it:
icc -o myprog.exe ... foo.o $FFTW_LIB
The main linking variables exported by an FFTW module are:
Environment Variable | Purpose |
---|---|
| For static linking. |
$FFTW_SHLIB | For dynamic linking. |
$FFTW_OPENMP_LIB | For static linking of OpenMP programs. Only available for vanilla FFTW |
$FFTW_PTHREADS_LIB | For static linking of programs using Posix threads. Only available for vanilla FFTW |
$FFTW_MPI_LIB | Use this in combination with $FFTW_[OPENMP,PTHREADS]_LIB if you wish to use hybrid parallelism. Only for vanilla FFTW |
Further Details and Special Cases
Thread safeness
Some FFTW calls, notably the plan generators, must be called outside any threaded regions.
MPI parallel transforms
An MPI interface is offered for version 3.3 of FFTW. These interfaces are incompatible. The FFTW_LIB
variable contains all libraries necessary to link a non-threaded MPI program:
mpicc -o my_mpi_prog.exe main.o a.o b.o c.o $FFTW_LIB
If you want to link a threaded library (version 3.3 and higher only), use the following link flags e.g., for generating a hybrid MPI + OpenMP executable:
mpicc -qopenmp -o my_mpi_prog.exe main.o a.o b.o c.o $FFTW_MPI_LIB $FFTW_OPENMP_LIB
New Fortran interface
Version 3.3 of FFTW supports a Fortran interface based on the C interoperability features of Fortran 2003 and later. In order to use this interface, you can for example write a small auxiliary module
module fftw use, intrinsic :: iso_c_binding include 'fftw3.f90' end module
which allows you to access the explicit interface for double precision (8 byte real) processing. This allows the compiler to check usage against definition.
FFTW interface to MKL
The Intel MKL contains a partial implementation of the FFTW interface: Please load one of the environment modules from the above table with the last component v3_mkl<version>
to access the corresponding library using the same environment variables as described above. For these module, only the FFTW_LIB
variable will be set, not the FFTW_OPENMP_LIB
or FFTW_PTHREADS_LIB
. Whether purely serial or shared memory mode is used depends on the previously loaded MKL module, and possibly $OMP_NUM_THREADS
.
Example for compiling, linking and running a threaded code
module load mkl/2017 fftw/serial/v3_mkl2017 # mkl/11.3 is threaded
icc -c $FFTW_INC my_prog.c
icc -o my_prog.exe my_prog.c $FFTW_LIB
export OMP_NUM_THREADS=4
./my_prog.exe
Example for compiling, linking and running MPI code (with MPI-parallel FFTW calls)
module load mpi.intel mkl/2017_s fftw/mpi/v3_mkl2017
mpicc -c $FFTW_INC my_prog.c
mpicc -o my_prog.exe my_prog.c $FFTW_LIB
mpiexec -n 4 ./my_prog.exe
Note that it is a good idea to check for a returned NULL pointer after calling a fftw_plan setup routine, otherwise calls to unsupported parts of the FFTW interface will simply crash your code. In particular, using types other than 8 Byte floats (or 16 Byte complex) will not work. Please check the MKL Release Notes for details on which calls are unsupported.
The advantage of using the MKL is that you may obtain improved performance in some cases, even compared with standard FFTW.
Documentation
Please refer to the FFTW home page for documentation
- FFTW Home Page, especially the documentation section
- Frequently Asked Questions on the FFTW site