Supported FFT libraries and their installation

fftw3 (better to build with OpenMP enabled)

FFTW (Fastest Fourier Transform in the West) is the standard open-source library for discrete Fourier transform.

Todo

Try hybrid OpenMP + MPI…

fftw3_mpi

FFTW provide their parallel MPI implementation.

If a system-wide installation of FFTW with OpenMP and MPI is not available, the user can make a local installation in a user-accessible directory. You can utilize this bash script with some modifications to the first few lines to install the FFTW library.

#!/bin/bash

# Customizable variables
# ----------------------
pkgname='fftw'
# FFTW version
pkgver=3.3.7
# Directory in which the source tarball will be downloaded and extracted
srcdir=$PWD
# Directory to which the compiled FFTW library will be installed
pkgdir="$HOME/.local/"
export MAKEFLAGS="-j$(nproc)"

# Should be no reason to change anything below
# --------------------------------------------
download() {
  mkdir -p ${srcdir}
  cd ${srcdir}

  if [ ! -f ${pkgname}-${pkgver}.tar.gz ]; then
    wget http://www.fftw.org/${pkgname}-${pkgver}.tar.gz
  fi
  tar vxzf $pkgname-$pkgver.tar.gz
}

clean() {
  cd ${srcdir}/${pkgname}-${pkgver}-double
  make distclean

  cd ${srcdir}/${pkgname}-${pkgver}-long-double
  make distclean

  cd ${srcdir}/${pkgname}-${pkgver}-single
  make distclean
}

build() {
  cd ${srcdir}

  cp -a ${pkgname}-${pkgver} ${pkgname}-${pkgver}-double
  cp -a ${pkgname}-${pkgver} ${pkgname}-${pkgver}-long-double
  cp -a ${pkgname}-${pkgver} ${pkgname}-${pkgver}-single


  # use upstream default CFLAGS while keeping our -march/-mtune
  CFLAGS+=" -O3 -fomit-frame-pointer -malign-double -fstrict-aliasing -ffast-math"

  CONFIGURE="./configure F77=gfortran CC=gcc CXX=g++ \
	          --prefix=${pkgdir} \
            --enable-shared \
		        --enable-threads \
		        --enable-openmp \
		        --enable-mpi"

  # build double precision
  cd ${srcdir}/${pkgname}-${pkgver}-double
  $CONFIGURE --enable-sse2 --enable-avx
  make

  # build & install long double precission
  cd ${srcdir}/${pkgname}-${pkgver}-long-double
  $CONFIGURE --enable-long-double
  make

  # build & install single precision
  cd ${srcdir}/${pkgname}-${pkgver}-single
  $CONFIGURE --enable-float --enable-sse --enable-avx
  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}-double
  make check

  cd ${srcdir}/${pkgname}-${pkgver}-long-double
  make check

  cd ${srcdir}/${pkgname}-${pkgver}-single
  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}-double
  make install

  cd ${srcdir}/${pkgname}-${pkgver}-long-double
  make install

  cd ${srcdir}/${pkgname}-${pkgver}-single
  make install
}


# Execute the functions above
# ---------------------------
if [ ! -d  ${srcdir}/${pkgname}-${pkgver} ]
then
  download
fi

clean
build
check
package

MKL library (FFT by intel)

There are wrappers to use the MKL library (FFT by intel) using the FFTW API. See the file site.cfg.mkl.

pfft

“PFFT is a software library for computing massively parallel, fast Fourier transformations on distributed memory architectures. PFFT can be understood as a generalization of FFTW-MPI to multidimensional data decomposition. The library is written in C and MPI.”

You may adapt the shell script given below to install pfft. Some other scripts related to IBM clusters can be found here.

#!/bin/bash

# Customizable variables
# ----------------------
pkgname='pfft'
# PFFT version
pkgver="1.0.8-alpha"
# Directory in which the source git repository will be downloaded
srcdir="${PWD}"
# Directory to which the compiled pfft library will be installed
pkgdir="${HOME}/.local/"
export MAKEFLAGS="-j$(nproc)"

# C and Fortran 90 MPI compilers
CC=mpicc
FC=mpif90

# FFTW
# ----
# FFTW == 3.3.4 requires patching, whereas 3.3.5 and later versions should work
# as it is. See: https://github.com/mpip/pfft#install

# You can configure fftwdir by setting an environment variable outside the script
fftwdir=${fftwdir-"${HOME}/.local/"}

# Alternatively, set fftwdir as an empty string and set fftwinc and fftwlib
fftwinc=${fftwinc-""}
fftwlib=${fftwlib-""}

# Should be no reason to change anything below
# --------------------------------------------
git_clone() {
  git clone https://github.com/mpip/pfft.git ${srcdir}/${pkgname}-${pkgver} --depth=10
}

download() {
  mkdir -p ${srcdir}
  cd ${srcdir}

  if [ ! -f ${pkgname}-${pkgver}.tar.gz ]; then
    wget http://www.tu-chemnitz.de/~potts/workgroup/pippig/software/${pkgname}-${pkgver}.tar.gz
  fi
  tar vxzf ${pkgname}-${pkgver}.tar.gz
}

clean() {
  rm -rf ${srcdir}/${pkgname}-${pkgver}
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  export LANG=C
  ./bootstrap.sh
  CONFIGURE="./configure \
            --prefix=${pkgdir} \
            CC=${CC} FC=${FC} MPICC=${CC} MPIFC=${FC} "
  if [ -n "$fftwdir" ]; then
    CONFIGURE+="--with-fftw3=${fftwdir}"
  else
    CONFIGURE+="CPPFLAGS=-I${fftwinc}  LDFLAGS=-L${fftwlib}"
  fi
  echo ${CONFIGURE}
  ${CONFIGURE}
  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make install
}


# Execute the functions above
# ---------------------------
clean
if [ ! -d  ${srcdir}/${pkgname}-${pkgver} ]
then
  ## Use any one of the following
  git_clone
  # download
fi
build
package

This script can be downloaded with:

wget https://foss.heptapod.net/fluiddyn/fluidfft/-/raw/branch/default/doc/install/install_pfft.sh

p3dfft

“Parallel Three-Dimensional Fast Fourier Transforms, dubbed P3DFFT, is a library for large-scale computer simulations on parallel platforms. […] P3DFFT uses 2D, or pencil, decomposition. This overcomes an important limitation to scalability inherent in FFT libraries implementing 1D (or slab) decomposition: the number of processors/tasks used to run this problem in parallel can be as large as N2, where N is the linear problem size.”

To use p3dfft with python binding, we need a shared library (.so) and therefore, we use a modified version of the package. Please follow the process detailed in the INSTALL file of this fork of the official p3dfft github repository : CyrilleBonamy/p3dfft. The process can be summarized as follows :

It can be convenient to link p3dfft with fftw3. A single fftw directory with lib and include directories must exist for this purpose.

For example, on Debian system, you can do that with:

ROOTFFTW=$HOME/opt/fft_gcc
mkdir -p $ROOTFFTW/include
mkdir -p $ROOTFFTW/lib
cp /usr/include/fftw* $ROOTFFTW/include
cp /usr/lib/x86_64-linux-gnu/libfftw3* $ROOTFFTW/lib

And next you can compile p3dfft with the following command:

CC=mpicc CCLD=mpif90 ./configure --enable-fftw --with-fftw=$ROOTFFTW \
    --prefix=/opt/p3dfft/2.7.5

You may adapt the shell script given below to automate this process :

#!/bin/bash

# Customizable variables
# ----------------------
pkgname='p3dfft'
# P3DFFT version
pkgver=2.7.6
# Directory in which the source git repository will be downloaded
srcdir="${PWD}"
# Directory to which the compiled p3dfft library will be installed
pkgdir="${HOME}/.local/"

# C and Fortran 90 MPI compilers
CC=mpicc
FC=mpif90

# FFTW
# ----
# You can configure fftwdir by setting an environment variable outside the script
fftwdir=${fftwdir-"${HOME}/.local/"}

# Should be no reason to change anything below
# --------------------------------------------
git_clone() {
  git clone https://github.com/CyrilleBonamy/p3dfft.git ${srcdir}/${pkgname}-${pkgver} --depth=10
  # git clone https://github.com/sdsc/p3dfft.git ${srcdir}/${pkgname}-${pkgver} --depth=10
}

download() {
  mkdir -p ${srcdir}
  cd ${srcdir}

  if [ ! -f ${pkgname}-${pkgver}.tar.gz ]; then
    wget https://github.com/sdsc/p3dfft/archive/v${pkgver}.tar.gz -O ${pkgname}-${pkgver}.tar.gz
  fi
  tar vxzf ${pkgname}-${pkgver}.tar.gz
}

clean() {
  rm -rf ${srcdir}/${pkgname}-${pkgver}
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  libtoolize && aclocal && autoconf && automake --add-missing
  ## If the above fails, use:
  # autoreconf -fvi
  export FCFLAGS="-fallow-argument-mismatch"
  export FFLAGS="-fallow-argument-mismatch"
  CC=${CC} CCLD=${FC} ./configure \
    --prefix=${pkgdir} \
    --enable-fftw --with-fftw=${fftwdir}

  make
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make install
  ## If the above fails, use (with caution):
  # make -i install
}


# Execute the functions above
# ---------------------------
clean
if [ ! -d  ${srcdir}/${pkgname}-${pkgver} ]
then
  ## Use any one of the following
  git_clone
  # download
fi
build
package

This script can be downloaded with:

wget https://foss.heptapod.net/fluiddyn/fluidfft/-/raw/branch/default/doc/install/install_p3dfft.sh

cuda

Modify fftw.h ! https://github.com/FFTW/fftw3/issues/18

Todo

How can I install Cuda? Link? Advice?

Unsupported libraries

openfft

There is no class of fluidfft to use the library openfft because it does not provide a function for inverse fft.

2decomp

There is no class of fluidfft to use the library 2decomp because we didn’t manage to build their shared libraries.