Skip to content
Snippets Groups Projects
fftw.md 3.23 KiB
Newer Older
  • Learn to ignore specific revisions
  • David Hrbáč's avatar
    David Hrbáč committed
    # FFTW
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    The discrete Fourier transform in one or more dimensions, MPI parallel
    
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    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.
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    Two versions, **3.3.3** and **2.1.5** of FFTW are available on Anselm, each compiled for **Intel MPI** and **OpenMPI** using **intel** and **gnu** compilers. These are available via modules:
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
    | Version        | Parallelization | module              | linker options                      |
    | -------------- | --------------- | ------------------- | ----------------------------------- |
    | FFTW3 gcc3.3.3 | pthread, OpenMP | fftw3/3.3.3-gcc     | -lfftw3, -lfftw3_threads-lfftw3_omp |
    | FFTW3 icc3.3.3 | pthread, OpenMP | fftw3               | -lfftw3, -lfftw3_threads-lfftw3_omp |
    | FFTW2 gcc2.1.5 | pthread         | fftw2/2.1.5-gcc     | -lfftw, -lfftw_threads              |
    | FFTW2 icc2.1.5 | pthread         | fftw2               | -lfftw, -lfftw_threads              |
    | FFTW3 gcc3.3.3 | OpenMPI         | fftw-mpi3/3.3.3-gcc | -lfftw3_mpi                         |
    | FFTW3 icc3.3.3 | Intel MPI       | fftw3-mpi           | -lfftw3_mpi                         |
    | FFTW2 gcc2.1.5 | OpenMPI         | fftw2-mpi/2.1.5-gcc | -lfftw_mpi                          |
    | FFTW2 gcc2.1.5 | IntelMPI        | fftw2-mpi/2.1.5-gcc | -lfftw_mpi                          |
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```bash
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
        $ module load fftw3
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
    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.
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
    ## Example
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```cpp
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
        #include <fftw3-mpi.h>
        int main(int argc, char **argv)
        {
    
    David Hrbáč's avatar
    David Hrbáč committed
            const ptrdiff_t N0 = 100, N1 = 1000;
            fftw_plan plan;
            fftw_complex *data;
            ptrdiff_t alloc_local, local_n0, local_0_start, i, j;
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            MPI_Init(&argc, &argv);
            fftw_mpi_init();
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            /* 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);
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            /* create plan for in-place forward DFT */
            plan = fftw_mpi_plan_dft_2d(N0, N1, data, data, MPI_COMM_WORLD,
                                        FFTW_FORWARD, FFTW_ESTIMATE);
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            /* 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; }
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            /* compute transforms, in-place, as many times as desired */
            fftw_execute(plan);
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            fftw_destroy_plan(plan);
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    David Hrbáč's avatar
    David Hrbáč committed
            MPI_Finalize();
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
        }
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    Load modules and compile:
    
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```bash
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
        $ module load impi intel
        $ module load fftw3-mpi
    
        $ mpicc testfftw3mpi.c -o testfftw3mpi.x -Wl,-rpath=$LIBRARY_PATH -lfftw3_mpi
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    ```
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    Run the example as [Intel MPI program](../mpi/running-mpich2/).
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    
    Read more on FFTW usage on the [FFTW website.](http://www.fftw.org/fftw3_doc/)