FFTW

FFTW

FFTW [1] (Fastest Fourier Transform in the West) is a C subroutine library for computing DFT. FFTW (http://www.fftw.org/) is a portable open source package developed at MIT.

Installed Versions

All the available versions of FFTW for use can be viewed by issuing the following command. This applies for other applications as well.

module spider fftw

output:

Versions:

        fftw/MKL-17

        fftw/3.3.6-pl2

        fftw/3.3.8


The default version is identified by "(default)" behind the module name and can be loaded as:

module load fftw

The other versions of FFTW can be loaded as (check for gcc/intel as appropriate):

module load fftw/<version>

Running FFTW job in HPC Cluster

Some sample codes are available to copy from /usr/local/doc/FFTW/

ls -lrt /usr/local/doc/FFTW
total 288
-rw-r--r-- 1 root root   329 Jan  2  2018 fftomp.slurm
-rw-r--r-- 1 root root 16732 Jan  2  2018 fftomp.c
-rw-r--r-- 1 root root   279 Jan  2  2018 fftmpi.slurm
-rw-r--r-- 1 root root   978 Jan  2  2018 fftmpi.c
-rw-r--r-- 1 root root  2017 Jan  2  2018 fftdemo.c

Serial

Sample Example - fftdemo.c

Interactive

Request a compute node

srun -c 2 --mem=8gb -t 1:00:00 --pty bash

Load the FFTW module

module load fftw

Copy the file "fftdemo.c" in your home directory. The headers and comments are shown below, to highlight the organization of the program:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <fftw3.h>

/*

FFTW_MEASURE: find the optimal plan by actually computing several FFTs

FFTW_ESTIMATE: do not run any FFT and provide a "reasonable" plan

FFTW_OUT_OF_PLACE: a plan assumes that the in and out are distinct

FFTW_IN_PLACE: a plan assumes that the in and out are same

*/

/* command line argument must be size (N) ! */


/* get N from the argument, make sure it is greater than zero */


/* allocate memory for the input and output arrays,


/* construct plans */


/* do forward fft */


/* do backward fft */

Compile (e.g. for fftw3):

gcc –o fftdemo fftdemo.c -lfftw3

Batch

Copy the code below to a slurm script resource.slurm in your directory where you have your executable

#!/bin/bash

#SBATCH --time=2:00    # the job requires essentially no time, don't rely on 10 hour default 

#SBATCH -N 1 -n 1 

#SBATCH -o fftwTest.o%j 

module load fftw

cp fftdemo $PFSDIR

cd $PFSDIR

echo $PFSDIR

./fftdemo 16       # fftdemo is the executable after compilation in previous steps.

cp -r * $SLURM_SUBMIT_DIR

Request resources from Slurm for the job:

sbatch resource.slurm

You will see the following output at an output file fftwtest.o,jobid>

input values:

in 1.000e+00 0.000e+00

...

Forward FFTW plan :

(dft-direct-16 "n2fv_16")

Backward FFTW plan :

(dft-direct-16 "n2bv_16")

FFT output:

out 1.600e+01 0.000e+00

out 0.000e+00 0.000e+00

...

Backward FFT output:

inv 1.600e+01 0.000e+00

inv 1.600e+01 0.000e+00

...

Parallel

Copy the C files fftmpi.c & fftomp.c and job files fftomp.slurm and fftmpi.slurm from /usr/local/doc/FFTW

cp /usr/local/doc/FFTW/fft* .

OpenMP

Note the compiler lines for OpenMP in the job file fftomp.slurm

gcc -fopenmp -o fftomp fftomp.c -lfftw3f_omp

Submit the job

sbatch fftomp.slurm

Find the output at omptest.o<jobID>

...

Minimum distances from node 0:

   0   0

   1  35

   2  15

   3  45

   4  49

   5  41

DIJKSTRA

  Normal end of execution.

...

MPI

Note the compiler lines for MPI in the job file fftmpi.slurm

mpicc -o fftmpi fftmpi.c -lfftw3f_mpi

Also, the instances of fftw_ needs to be replaced with fftwf_ in C file for MPI as we are using fftw/2015 that is installed with float flags.

Submit the job

sbatch fftmpi.slurm

Find the output at mpitest.o<jobID>

2500

2500

2500

2500

finalize

finalize

finalize

finalize

References:

[1] Home Page: http://www.fftw.org/