FFTW¶
FFTW is a C library for computing discrete Fourier transforms (DFT) in one or more dimensions, supporting real, complex, and even/odd (DCT/DST) data of arbitrary size.
Loading the module¶
module load FFTW/3.3.10-GCC-12.3.0
FFTW is also available through the MPI-aware variant FFTW.MPI and as part of Intel MKL (imkl-FFTW). To see all installed versions across clusters, check the software catalog or run module spider FFTW.
Info
FFTW is loaded automatically as a dependency of many toolchains and applications. Check module list after loading your main module before adding a separate FFTW load.
Compiling against FFTW¶
After loading the module, the headers and libraries are available through standard paths. Link with -lfftw3 (double precision), -lfftw3f (single precision), or -lfftw3_omp / -lfftw3_mpi for threaded/MPI variants:
# Serial
gcc -o fft_example fft_example.c -lfftw3 -lm
# OpenMP threaded
gcc -fopenmp -o fft_example fft_example.c -lfftw3_omp -lfftw3 -lm
# MPI (use the FFTW.MPI module)
mpicc -o fft_example fft_example.c -lfftw3_mpi -lfftw3 -lm
Example: real-to-complex 1D transform
#include <fftw3.h>
#include <stdio.h>
int main() {
int N = 8;
double *in = fftw_malloc(sizeof(double) * N);
fftw_complex *out = fftw_malloc(sizeof(fftw_complex) * (N/2 + 1));
for (int i = 0; i < N; i++)
in[i] = i + 1;
fftw_plan plan = fftw_plan_dft_r2c_1d(N, in, out, FFTW_ESTIMATE);
fftw_execute(plan);
printf("Output:\n");
for (int i = 0; i < N/2 + 1; i++)
printf(" (%f, %f)\n", out[i][0], out[i][1]);
fftw_destroy_plan(plan);
fftw_free(in);
fftw_free(out);
return 0;
}
Batch job example¶
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=fftw
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem=4G
#SBATCH --time=00:30:00
#SBATCH --output=%x.%j.out
#SBATCH --error=%x.%j.err
module load FFTW/3.3.10-GCC-12.3.0
./fft_example
For MPI programs, adjust --ntasks and launch with srun.
See also¶
-
Software catalog
Versions available on each cluster.
-
Intel MKL FFTW wrappers
FFTW interface backed by MKL.
-
FFTW documentation
Official FFTW3 reference manual.