Slaton Lipscomb

Slaton's Tips:
Compiling & Optimizing FFTW for SPIDER


Last updated March 31, 2006
Comments/corrections welcome.

SPIDER was developed at the Resource for the Visualization of Biological complexity (RVBC) located in the Wadsworth Laboratories, Albany, New York.

This document describes how to compile and optimize FFTW (Fastest Fourier Transform in the West) for SPIDER on the Linux platform, using the Portland Group's Fortran compiler, pgf90.

Download the FFTW source from http://www.fftw.org. Use the most recent 2.1.x release, currently 2.1.5. The version 3 API is not backwards compatible, and does not yet have support for threads (required for SPIDER's OpenMP parallelism), so we cannot use it.

Unzip/untar the source.

You will need to edit a file. Open the file fftw-2.1.5/threads/rfftw_f77_threads.c in your favorite editor, and add the following lines to the end of the file:

/**-------------------------edit: threads/ rfftw_f77_threads.c----------------*/

/* added by leith to shorten names */

void F77_FUNC_(rfftwnd_f77_threads_one_r_to_c,RFFTWND_F77_THREADS_ONE_REAL_TO_COMPLEX)
(int *nthreads, fftwnd_plan *p, fftw_real *in, fftw_complex *out)
{
    rfftwnd_threads_one_real_to_complex(*nthreads,*p,in,out);
}

void F77_FUNC_(rfftwnd_f77_threads_one_c_to_r,RFFTWND_F77_THREADS_ONE_COMPLEX_TO_REAL)
(int *nthreads, fftwnd_plan *p, fftw_complex *in, fftw_real *out)
{
    rfftwnd_threads_one_complex_to_real(*nthreads,*p,in,out);
}

/* end leith Mar 2000 to shorten names */

/*  ---------------------------------- end of edit ---------------------------*/

Make sure your shell environment is set up for using the Portland compilers. This is easy if you use Environment Modules (included with some Linux distributions).

$ module load pgi

If you don't use Environment Modules, you will have to define some environment variables manually or in your shell resource file. See the Portland Group compiler documentation for more information.

If you wish to compile FFTW with optimization for your CPU type, you'll need to specify the appropriate compiler flags via the CFLAGS environment variable. For a 32-bit Pentium4/Xeon, I use the following flags.

csh

$ setenv CFLAGS "-tp p7 -fast -O3 -Mipa=fast,inline"
$ setenv CXXFLAGS "-tp p7 -fast -O3 -Mipa=fast,inline"
$ setenv FFLAGS "-tp p7 -fast -O3 -Mipa=fast,inline"

bash

$ export CFLAGS="-tp p7 -fast -O3 -Mipa=fast,inline"
$ export CXXFLAGS="-tp p7 -fast -O3 -Mipa=fast,inline"
$ export FFLAGS="-tp p7 -fast -O3 -Mipa=fast,inline"

For 64-bit AMD/Opteron platform, use -tp k8-64 instead of -tp p7.

Now run configure to set the appropriate options for FFTW. Set prefix as desired for your system. enable-shared is actually optional since I recommend using the static libraries when compiling SPIDER.

$ ./configure --enable-threads --enable-float --enable-shared \
  --prefix=/usr/local/fftw/pgi --enable-type-prefix

Now, compile and install FFTW.

$ make
  (su root, if appropriate)
$ make install

→   FFTW is written in C, but has a Fortran wrapper so that its routines can be called from Fortran code. If you have problems later linking SPIDER to the FFTW libraries, you may have accidentally compiled the FFTW Fortran wrapper with the GNU compilers instead of Portland. This is usually because the F77 and F90 environment variables have not been set correctly, for example:

csh

$ setenv F77 pgf90
$ setenv F90 pgf90

bash

$ export F77=pgf90
$ export F90=pgf90

→   If you see errors during configuration that prevent the Fortran interface from being compiled, you may have run into a problem with GNU Libtool, which results in the FLIBS variable being set incorrectly. Before running configure, try setting this variable manually. For example, on a 64-bit Opteron machine machine, I set FLIBS as follows:

csh

$ setenv FLIBS "-L/opt/pgi/linux86-64/6.0/lib -L/usr/lib64 \
  -L/usr/lib/gcc/x86_64-caos-linux/3.4.3 -lm -lpgftnrtl -lnspgc -lpgc"

bash

$ export FLIBS="-L/opt/pgi/linux86-64/6.0/lib -L/usr/lib64 \
  -L/usr/lib/gcc/x86_64-caos-linux/3.4.3 -lm -lpgftnrtl -lnspgc -lpgc"