FFTW¶
![FFTW](images/logo.gif)
FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) in one or more dimensions, of arbitrary input size, and of both real and complex data (as well as of even/odd data, i.e. the discrete cosine/sine transforms or DCT/DST).
Usage¶
FFTW module¶
FFTW has to be loaded using Lmod prior to running it.
$ module load FFTW
spider
$ module spider FFTW
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FFTW:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Description:
FFTW is a C subroutine library for computing the discrete Fourier transform (DFT) in one or more dimensions, of arbitrary input size, and of both real and complex data.
Versions:
FFTW/3.3.9-gompi-2021a
FFTW/3.3.9-intel-2021a
FFTW/3.3.10-GCC-11.3.0
FFTW/3.3.10-GCC-12.2.0
FFTW/3.3.10-GCC-12.3.0
FFTW/3.3.10-gompi-2021b
FFTW/3.3.10-iimpi-2021b
FFTW/3.3.10-iimpi-2022a
FFTW/3.3.10-iimpi-2022b
Other possible modules matches:
FFTW.MPI imkl-FFTW
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
To find other possible module matches execute:
$ module -r spider '.*FFTW.*'
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
For detailed information about a specific "FFTW" package (including how to load the modules) use the module's full name.
Note that names that have a trailing (E) are extensions provided by other modules.
For example:
$ module spider FFTW/3.3.10-iimpi-2022b
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Software version¶
Here you can check the available versions for FFTW in the different clusters
FFTW/3.2-gompi-2017a
FFTW/3.3.4-gompi-2016b
FFTW/3.3.6-gimkl-2017a
FFTW/3.3.6-gompi-2017a
FFTW/3.3.6-gompi-2017b
FFTW/3.3.6-intel-2017a
FFTW/3.3.6-intel-2017b
FFTW/3.3.7-gompi-2018a
FFTW/3.3.7-intel-2017b
FFTW/3.3.7-intel-2018a
FFTW/3.3.8-gompi-2018b
FFTW/3.3.8-gompi-2019b
FFTW/3.3.8-gompi-2020a
FFTW/3.3.8-gompi-2020b
FFTW/3.3.8-intel-2018b
FFTW/3.3.8-intel-2019a
FFTW/3.3.8-intel-2019b
FFTW/3.3.8-intel-2020a
FFTW/3.3.9-gompi-2021a
FFTW/3.3.9-intel-2020b
FFTW/3.3.9-intel-2021a
FFTW/3.3.10-GCC-11.3.0
FFTW/3.3.10-GCC-12.2.0
FFTW/3.3.10-gompi-2021b
FFTW/3.3.8-GCC-9.3.0-serial
FFTW/3.3.8-gompi-2019b
FFTW/3.3.8-gompi-2020a
FFTW/3.3.8-gompi-2020b
FFTW/3.3.8-gompic-2019b
FFTW/3.3.8-gompic-2020a
FFTW/3.3.8-gompic-2020b
FFTW/3.3.8-intel-2019b
FFTW/3.3.8-intel-2020a
FFTW/3.3.8-intel-2020b
FFTW/3.3.9-gompi-2021a
FFTW/3.3.9-intel-2021a
FFTW/3.3.9-intel-2021b
FFTW/3.3.10-GCC-11.3.0
FFTW/3.3.10-GCC-12.2.0
FFTW/3.3.10-GCC-12.3.0
FFTW/3.3.10-gompi-2021b
FFTW/3.3.10-iimpi-2021b
FFTW/3.3.9-gompi-2021a
FFTW/3.3.9-intel-2021a
FFTW/3.3.10-GCC-11.3.0
FFTW/3.3.10-GCC-12.2.0
FFTW/3.3.10-GCC-12.3.0
FFTW/3.3.10-gompi-2021b
FFTW/3.3.10-iimpi-2021b
FFTW/3.3.10-iimpi-2022a
FFTW/3.3.10-iimpi-2022b
How to use FFTW¶
In order to use it, you will need to compile your code against the library.
Let's see how to use it with an example, using the following code:
Example code using FFTW
#include <fftw3.h>
#include <stdio.h>
int main() {
// Define the size of the input array
int N = 8;
// Allocate memory for the input and output arrays
double *in;
fftw_complex *out;
fftw_plan plan;
in = (double*) fftw_malloc(sizeof(double) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * (N/2 + 1));
// Initialize the input array with some values
for (int i = 0; i < N; i++) {
in[i] = i + 1; // Example: input is 1, 2, 3, ..., N
}
// Create a plan
plan = fftw_plan_dft_r2c_1d(N, in, out, FFTW_ESTIMATE);
// Execute the plan
fftw_execute(plan);
// Print the output
printf("Input:\n");
for (int i = 0; i < N; i++) {
printf("%f ", in[i]);
}
printf("\n");
printf("Output:\n");
for (int i = 0; i < N/2 + 1; i++) {
printf("(%f, %f) ", out[i][0], out[i][1]);
}
printf("\n");
// Clean up
fftw_destroy_plan(plan);
fftw_free(in);
fftw_free(out);
return 0;
}
First, we load the module:
$ module load FFTW/3.3.10-iimpi-2022b
To compile our code, we will use the following line:
$ gcc -o example example.c -lfftw3 -lm
Once compiled, we can execute it using the following submission script:
Batch script for a parallel execution using FFTW
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=FFTW_JOB
#SBATCH --mem=20gb
#SBATCH --cpus-per-task=1
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=5
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err
module load FFTW/3.3.10-iimpi-2022b
mpirun -np 5 ./example
Where:
-np
: number of MPI tasks.