Micro and Nano Mechanics Group
Revision as of 14:59, 29 January 2009 by Correaa (Talk)

FFTW3 is a library designed to compute discrete Fourier Transforms. As described in the the official FFTW site], there are various versions available, with different features and different levels of maturity. In this tutorial I deal with version 3, including the experimental MPI, however the installation instructions seems to be valid also for version 2 (not tested).

Remarks

As usual we would like to install the libraries in the user space, so we will create a couple of directories for that purpose:

 mkdir $HOME/usr
 mkdir $HOME/soft

To install FFTW3, download the package from the FFTW3 download page and decompress it:

 cd ~/soft
 wget http://www.fftw.org/fftw-3.3alpha1.tar.gz
 tar -zxvf fftw-3.3alpha1.tar.gz
 cd fftw-3.3alpha1

Ubuntu only: If you want to install FFTW3 in your local Ubuntu you can skip this tutorial altogether and just run:

 sudo apt-get install libfftw3-dev libfftw3-doc

However the MPI version (e.g. for testing) will not be installed in this way.

Build and Install (serial version only)

Then configure, make and install:

 ./configure --prefix=$HOME/usr
 make
 make install

The following files will be installed in:

 ~/usr/include/fftw3.h
 ~/usr/include/fftw3.f
 ~/usr/lib/libfftw3.a
 ~/usr/lib/libfftw3.la

The typical compilation options will be

 export LD_RUN_PATH=$HOME/usr/lib  #do this once *before* compiling
 cc -I$HOME/usr/include program.c -L$HOME/usr/lib -lfftw3 -o program

The official tutorial on the usage of FFTW3 (which is different from FFTW 2) is located here.

Using LD_RUN_PATH saves us from having to set path variables before *running* the program, such as LD_LIBRARY_PATH (which is a bad practice). When LD_RUN_PATH is set the created executable will store the search path internally (but will not enforce it). I learned this trick from http://gcc.gnu.org/faq.html#rpath and it works well with gcc at least. Setting this variable before compilation can be annoying, but is better than having to set variables *each* time we *use* the executable. This seems to be the only good option left when using libraries installed in the home directory (does anybody know a better alternative?).

MPI version

To install the experimental MPI version of FFTW3, make sure you downloaded fftw-3.3alpha1 (and not fftw-3.2 for example). Also make sure that there is an MPI compiler available:

 $which mpicc
 /usr/bin/mpicc

If it is not available, you can choose one with the command 'mpi-selector-menu' in wcr. I tested this with the 'openmpi_gcc-1.2.2' compiler.

Do the same procedure of downloading the file and decompressing it, but add the --enable-mpi flag:

 ./configure --prefix=$HOME/usr --enable-mpi
 make install

now the library will be installed in your home directory, besides the files mentioned above, you will find also:

 ~/usr/include/fftw3-mpi.h
 ~/usr/lib/libfftw3_mpi.a
 ~/usr/lib/libfftw3_mpi.la

The typical command line for compilation will be

 export LD_RUN_PATH=$HOME/usr/lib #do this *before* compiling
 mpicc -I$HOME/usr mpi_program.c -L$HOME/usr/lib -lfftw3_mpi -lfftw3 -o mpi_program

Make sure to link *first* to fftw3_mpi and *later* to fftw3.

The official tutorial for the MPI version of FFTW3 can be found here.