Main navigation

How to use the FFTW Library

Using FFTW 3 from C and C++

In your program include:

#include <fftw3.h>

and call the appropriate fftw3 functions.

You may also include:

#include <complex.h>

to handle complex numbers.

There are three versions of the fftw3 library depending on precision. The APIs for each differ slightly because of the precision differences:

Precision Library Example Program (FFT of a sine wave)
Double fftw3 fftw3-test.c
Single fftw3f fftw3f-test.c
Long Double fftw3l fftw3l-test.c

To compile and link either enter:

icc pgm.c -I$FFTW3_HOME/include -L$FFTW3_HOME/lib -llib [-static-intel] -o pgm

or:

gcc -std=c99 pgm.c -I$FFTW3_HOME/include -L$FFTW3_HOME/lib -llib -lm [-static] -o pgm

depending upon the compiler you want to use.

  • Replace pgm.c with the name of the file containing your source code
  • Replace pgm with the name of the executable to be created
  • Replace lib with one of the three fftw3 libraries: fftw3, fftw3f or fftw3l
  • Set FFTW3_HOME /u/local/apps/fftw3/current

If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $FFTW_HOME/lib.

You can either set an environment variable or replace $FFTW3_HOME in the command shown above.

Using FFTW 3 from Fortran

In your program include:

include 'fftw3.f'

and call the appropriate fftw3 functions but note the differences in subroutine names and argument lists for Fortran.

To compile and link enter:

ifort -fr pgm.f90 -I$FFTW3_HOME/include -L$FFTW3_HOME/lib -llib [-static] -o pgm

  • Replace pgm.f90 with the name of the file containing your source code
  • Replace lib with one of the three fftw3 libraries: fftw3, fftw3f or fftw3l
  • Replace pgm with the name of the executable to be created
  • Set FFTW3_HOME /u/local/apps/fftw3/current

If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $FFTW_HOME/lib.

You can either set an environment variable or replace $FFTW3_HOME in the command shown above.

 

FFTW 2 (legacy API)

FFTW Version 2 is a legacy FFTW API. FFTW Version 3 is a major rewrite and the API’s are not compatible. If your code already uses this version of the API, you are welcome to use it. All new codes should be written to use FFTW Version 3.

Report Typos and Errors
UCLA OIT

© 2016 UC REGENTS TERMS OF USE & PRIVACY POLICY