Skip to content

FFTW

The discrete Fourier transform in one or more dimensions, MPI parallel

FFTW is a C subroutine library for computing the discrete Fourier transform in one or more dimensions, of arbitrary input size, and of both real and complex data (as well as of even/odd data, e.g. the discrete cosine/sine transforms or DCT/DST). The FFTW library allows for MPI parallel, in-place discrete Fourier transform, with data distributed over number of nodes.

$ ml av FFTW

---------------------------------------------------- /apps/modules/numlib -----------------------------------------------------
   FFTW/3.3.7-gompi-2018a        FFTW/3.3.8-gompi-2020a    FFTW/3.3.8-gompic-2020b           FFTW/3.3.8
   FFTW/3.3.8-gompi-2020a-amd    FFTW/3.3.8-gompi-2020b    FFTW/3.3.8-iccifort-2020.4.304    FFTW/3.3.9-gompi-2021a (D)

To load the latest version of Octave load the module:

$ ml FFTW

The module sets up environment variables, required for linking and running FFTW enabled applications. Make sure that the choice of FFTW module is consistent with your choice of MPI library. Mixing MPI of different implementations may have unpredictable results.

Example

    #include <fftw3-mpi.h>
    int main(int argc, char **argv)
    {
        const ptrdiff_t N0 = 100, N1 = 1000;
        fftw_plan plan;
        fftw_complex *data;
        ptrdiff_t alloc_local, local_n0, local_0_start, i, j;

        MPI_Init(&argc, &argv);
        fftw_mpi_init();

        /* get local data size and allocate */
        alloc_local = fftw_mpi_local_size_2d(N0, N1, MPI_COMM_WORLD,
                                             &local_n0, &local_0_start);
        data = fftw_alloc_complex(alloc_local);

        /* create plan for in-place forward DFT */
        plan = fftw_mpi_plan_dft_2d(N0, N1, data, data, MPI_COMM_WORLD,
                                    FFTW_FORWARD, FFTW_ESTIMATE);

        /* initialize data  */
        for (i = 0; i < local_n0; ++i) for (j = 0; j < N1; ++j)
        {   data[i*N1 + j][0] = i;
            data[i*N1 + j][1] = j; }

        /* compute transforms, in-place, as many times as desired */
        fftw_execute(plan);

        fftw_destroy_plan(plan);

        MPI_Finalize();
    }

Load modules and compile:

$ ml intel/2020b 3.3.8-iccifort-2020.4.304
$ mpicc testfftw3mpi.c -o testfftw3mpi.x -Wl,-rpath=$LIBRARY_PATH -lfftw3_mpi

Read more on FFTW usage on the FFTW website.