Chris@19: Chris@19:
Chris@19:Chris@19: Next: Multi-dimensional MPI DFTs of Real Data, Chris@19: Previous: 2d MPI example, Chris@19: Up: Distributed-memory FFTW with MPI Chris@19:
Chris@19: The most important concept to understand in using FFTW's MPI interface Chris@19: is the data distribution. With a serial or multithreaded FFT, all of Chris@19: the inputs and outputs are stored as a single contiguous chunk of Chris@19: memory. With a distributed-memory FFT, the inputs and outputs are Chris@19: broken into disjoint blocks, one per process. Chris@19: Chris@19:
In particular, FFTW uses a 1d block distribution of the data, Chris@19: distributed along the first dimension. For example, if you Chris@19: want to perform a 100 × 200 complex DFT, distributed over 4 Chris@19: processes, each process will get a 25 × 200 slice of the data. Chris@19: That is, process 0 will get rows 0 through 24, process 1 will get rows Chris@19: 25 through 49, process 2 will get rows 50 through 74, and process 3 Chris@19: will get rows 75 through 99. If you take the same array but Chris@19: distribute it over 3 processes, then it is not evenly divisible so the Chris@19: different processes will have unequal chunks. FFTW's default choice Chris@19: in this case is to assign 34 rows to processes 0 and 1, and 32 rows to Chris@19: process 2. Chris@19: Chris@19: Chris@19:
FFTW provides several ‘fftw_mpi_local_size’ routines that you can
Chris@19: call to find out what portion of an array is stored on the current
Chris@19: process. In most cases, you should use the default block sizes picked
Chris@19: by FFTW, but it is also possible to specify your own block size. For
Chris@19: example, with a 100 × 200 array on three processes, you can
Chris@19: tell FFTW to use a block size of 40, which would assign 40 rows to
Chris@19: processes 0 and 1, and 20 rows to process 2. FFTW's default is to
Chris@19: divide the data equally among the processes if possible, and as best
Chris@19: it can otherwise. The rows are always assigned in “rank order,”
Chris@19: i.e. process 0 gets the first block of rows, then process 1, and so
Chris@19: on. (You can change this by using MPI_Comm_split
to create a
Chris@19: new communicator with re-ordered processes.) However, you should
Chris@19: always call the ‘fftw_mpi_local_size’ routines, if possible,
Chris@19: rather than trying to predict FFTW's distribution choices.
Chris@19:
Chris@19:
In particular, it is critical that you allocate the storage size that Chris@19: is returned by ‘fftw_mpi_local_size’, which is not Chris@19: necessarily the size of the local slice of the array. The reason is Chris@19: that intermediate steps of FFTW's algorithms involve transposing the Chris@19: array and redistributing the data, so at these intermediate steps FFTW Chris@19: may require more local storage space (albeit always proportional to Chris@19: the total size divided by the number of processes). The Chris@19: ‘fftw_mpi_local_size’ functions know how much storage is required Chris@19: for these intermediate steps and tell you the correct amount to Chris@19: allocate. Chris@19: Chris@19:
Chris@19: Chris@19: Chris@19: