FFTW

Overview

FFTW is a C subroutine library (also with Fortran interfaces) for computing the discrete Fourier transform (DFT) in one or more dimensions, of arbitrary input size, and of both real and complex data (as well as of even/odd data, i.e. the discrete cosine/sine transforms or DCT/DST).

Intel Compiler Interface to FFTW3 vs Original FFTW3

Please note: the information in this section is repeated on the CSF Intel Compiler page.

The Intel Compiler’s Math Kernel Library (MKL) comes with an FFTW3 interface built-in, and FFTW2 interfaces (and FFTW3) can be compiled by you if needed to give yourself a local copy of the Intel library (see below). Hence, if you have source code that uses FFTW functions, you can compile and link your application, without source-code changes, to the MKL libraries and it will use Intel’s built-in version of FFTW3 instead of the FFTW libraries discussed on this page.

Hence there are three methods of using the FFTW if your application makes FFTW function calls:

  1. Use the original FFTW libraries as described further down this page
  2. Use the Intel Compiler’s built-in FFTW3 (only) implementation in the Intel Math Kernel Library (MKL) [jump there]
  3. Use the Intel Compiler’s built-in FFTW2 or 3 implementation but compile a local copy of the libfftw{2,3}XX_intel.a library for use in your compilation (some software wants to use this specific library name in the compilation process so it is sometimes easier to compile a local copy then you know you always have it available). [jump there]

You should be able to use either method without changing your source code. Which to use is really a matter of performance and you could compile your app with both versions and do some timing tests to see which is best. The Intel MKL version may run faster on some of the Intel hardware in the CSF but we make no recommendation either way – you must test your own application.

See further below for how to use the original FFTW libraries by loading fftw modulefiles.

All of the examples below assume your C/C++ code contains:

#include <fftw3.h>

Using the Intel MKL Interface to FFTW (without compiling your own local copy)

To compile your application using the Intel built-in FFTW3 library, without referring to a specific libfftw3XX_intel.a library, use the standard Intel compiler MKL flags (note in the example we use the Intel C compiler (icc) but you can also use the Fortran (ifort) or C++ (icpc) compiler with the same flags):

# Load the Intel compiler modulefile
module load compilers/intel/17.0.7

# Compile a serial FFTW application using the MKL built-in FFTW3
icc myfftapp.c -o myfftapp.exe -I${MKLROOT}/include/fftw -mkl=sequential -lm

# Compile an OpenMP (multi-core) application using the MKL built-in FFTW3
icc myfftOMPapp.c -o myfftOMPapp.exe -qopenmp -I${MKLROOT}/include/fftw -mkl -lm 

You should now be able to run your application with just the Intel compiler modulefile loaded – you should not use the fftw modulefiles discussed later on this page.

Using the Intel MKL Interface to FFTW (by compiling your own local copy)

If you wish to use the Intel MKL FFTW2 functions, or you wish to have a local copy of Intel’s interface to FFTW3 (e.g. some apps insist on linking against a libfftw{2,3}XX_intel.a library), you can compile the Intel MKL interface yourself so you have a local copy of the libfftw{2,3}XX_intel libraries. Note: If you are using fftw3 functions and want to use the Intel MKL version, you should not need to do the following compilation steps. But it won’t harm if you do:

# Decide on the name and location of a  folder where you want to compile a local
# copy of the Intel FFTW3 interface. This might be inside your source tree. For example:
export VBASE=$HOME/myfftapp/fftw3_intel

# Add a sub-directory name for the particular flavour of FFTW3 interface (single precision etc):
# and create that entire directory tree. For example we want the fftw3xf_intel.a library:
mkdir -p $VBASE/fftw3xf/lib

# Load the Intel compiler modulefile for your required version. EG:
module load compilers/intel/17.0.7

# Now, go to the Intel compiler central install area so that you can see
# the FFTW interface files that Intel provides:
pushd $INTELROOT/mkl/interfaces/fftw3xf

# Finally, compile their interface code but make
# sure it writes to your installation area created above:
make libintel64 compiler=intel install_to=$VBASE/fftw3xf/lib 2>&1 | tee $VBASE/fftw3xf/lib/make-csf.log

# Go back to where you were previously:
popd

# Check we have a library:
ls $VBASE/fftw3xf/lib/*.a
 #
 # You should see a libfftw3xf_intel.a file listed

# Now, when you compile your source code, you should tell the intel
# compiler where your local copy of the Intel FFTW files are:
icc myfftapp.c -o myfftapp.exe -I${MKLROOT}/include/fftw -L$VBASE/fftw3xf/lib -lfftw3xf_intel

You should now be able to run your application with just the Intel compiler modulefile loaded – you should not use the fftw modulefiles discussed later on this page.

Original FFTW libraries

If you wish to use the original FFTW functions, ignoring the Intel MKL version, please use the modulefile and further instructions below.

Versions

3.3.8 for all Intel nodes – jobs/software using Intel compilers v 17.0.7 and for MPI applications, openmpi 3.1.1. The SMP modules include both the FFTW threads and OpenMP libraries.

Setup procedure

module load libs/intel-17.0/fftw3/openmpi-3.1.3/double/3.3.8
module load libs/intel-17.0/fftw3/openmpi-3.1.3/float/3.3.8
module load libs/intel-17.0/fftw3/openmpi-3.1.3/long-double/3.3.8

module load libs/intel-17.0/fftw3/openmpi-3.1.1/double/3.3.8
module load libs/intel-17.0/fftw3/openmpi-3.1.1/float/3.3.8
module load libs/intel-17.0/fftw3/openmpi-3.1.1/long-double/3.3.8

module load libs/intel-17.0/fftw3/serial/double/3.3.8
module load libs/intel-17.0/fftw3/serial/float/3.3.8
module load libs/intel-17.0/fftw3/serial/long-double/3.3.8

module load libs/intel-17.0/fftw3/smp/double/3.3.8
module load libs/intel-17.0/fftw3/smp/float/3.3.8
module load libs/intel-17.0/fftw3/smp/long-double/3.3.8

Running the application

The fftw-wisdom-to-conf and fftw-wisdom executables for creating pre-optimized FFTs will be available in your path once a modulefile has been loaded.

Most usage will involved including FFTW header files in your source code and linking against the FFTW libraries during compilation. To assist with this the following environment variables are available. They can be used on your compiler command-line or in Makefiles:

The modulefiles will set an environment variable named FFTW which can then be used in your compilation process (e.g., in a Makefile) to access the header and library files:

  • To inform the compiler of the header file directory use: -I$FFTW/include on the command line
  • To inform the compiler of the library files use: -L$FFTW/lib -lnameoflibrary on the command line (see below for nameoflibrary)
  • In a Makefile use $(FFTW) rather than $FFTW.

The nameoflibrary to use on the compilation line depends on the precision of the FFTW version you are using and whether you wish to use the serial, MPI, threads, or OpenMP version of the library.

Precision Library (.a and .so) Compiler flag
Single (float) libfftw3f -lfftw3f
libfftw3f_mpi -lfftw3f_mpi
libfftw3f_threads -lfftw3f_threads
libfftw3f_omp -lfftw3f_omp
Double (the default – do not add
a ‘d’ to the library names!)
libfftw3 -lfftw
libfftw3_mpi -lfftw3_mpi
libfftw3_threads -lfftw3_threads
libfftw3_omp -lfftw3_omp
Long double libfftw3l -lfftwl
libfftw3l_mpi -lfftw3l_mpi
libfftw3l_threads -lfftw3l_threads
libfftw3l_omp -lfftw3l_omp

Both static (.a) and shared/dynamic (.so) versions of the libraries are available.

Further info

Last modified on May 12, 2020 at 4:47 pm by George Leaver