Chris@10: Chris@10:
Chris@10:Chris@10: Next: Other Multi-dimensional Real-data MPI Transforms, Chris@10: Previous: MPI Data Distribution, Chris@10: Up: Distributed-memory FFTW with MPI Chris@10:
FFTW's MPI interface also supports multi-dimensional DFTs of real Chris@10: data, similar to the serial r2c and c2r interfaces. (Parallel Chris@10: one-dimensional real-data DFTs are not currently supported; you must Chris@10: use a complex transform and set the imaginary parts of the inputs to Chris@10: zero.) Chris@10: Chris@10:
The key points to understand for r2c and c2r MPI transforms (compared Chris@10: to the MPI complex DFTs or the serial r2c/c2r transforms), are: Chris@10: Chris@10:
complex data, and then use the same distribution for the real Chris@10: data except that the last complex dimension is replaced by a (padded) Chris@10: real dimension of twice the length. Chris@10: Chris@10:
For example suppose we are performing an out-of-place r2c transform of Chris@10: L × M × N real data [padded to L × M × 2(N/2+1)], Chris@10: resulting in L × M × N/2+1 complex data. Similar to the Chris@10: example in 2d MPI example, we might do something like: Chris@10: Chris@10:
#include <fftw3-mpi.h> Chris@10: Chris@10: int main(int argc, char **argv) Chris@10: { Chris@10: const ptrdiff_t L = ..., M = ..., N = ...; Chris@10: fftw_plan plan; Chris@10: double *rin; Chris@10: fftw_complex *cout; Chris@10: ptrdiff_t alloc_local, local_n0, local_0_start, i, j, k; Chris@10: Chris@10: MPI_Init(&argc, &argv); Chris@10: fftw_mpi_init(); Chris@10: Chris@10: /* get local data size and allocate */ Chris@10: alloc_local = fftw_mpi_local_size_3d(L, M, N/2+1, MPI_COMM_WORLD, Chris@10: &local_n0, &local_0_start); Chris@10: rin = fftw_alloc_real(2 * alloc_local); Chris@10: cout = fftw_alloc_complex(alloc_local); Chris@10: Chris@10: /* create plan for out-of-place r2c DFT */ Chris@10: plan = fftw_mpi_plan_dft_r2c_3d(L, M, N, rin, cout, MPI_COMM_WORLD, Chris@10: FFTW_MEASURE); Chris@10: Chris@10: /* initialize rin to some function my_func(x,y,z) */ Chris@10: for (i = 0; i < local_n0; ++i) Chris@10: for (j = 0; j < M; ++j) Chris@10: for (k = 0; k < N; ++k) Chris@10: rin[(i*M + j) * (2*(N/2+1)) + k] = my_func(local_0_start+i, j, k); Chris@10: Chris@10: /* compute transforms as many times as desired */ Chris@10: fftw_execute(plan); Chris@10: Chris@10: fftw_destroy_plan(plan); Chris@10: Chris@10: MPI_Finalize(); Chris@10: } Chris@10:Chris@10:
Note that we allocated rin
using fftw_alloc_real
with an
Chris@10: argument of 2 * alloc_local
: since alloc_local
is the
Chris@10: number of complex values to allocate, the number of real
Chris@10: values is twice as many. The rin
array is then
Chris@10: local_n0 × M × 2(N/2+1) in row-major order, so its
Chris@10: (i,j,k)
element is at the index (i*M + j) * (2*(N/2+1)) +
Chris@10: k
(see Multi-dimensional Array Format).
Chris@10:
Chris@10:
As for the complex transforms, improved performance can be obtained by
Chris@10: specifying that the output is the transpose of the input or vice versa
Chris@10: (see Transposed distributions). In our L × M × N r2c
Chris@10: example, including FFTW_TRANSPOSED_OUT
in the flags means that
Chris@10: the input would be a padded L × M × 2(N/2+1) real array
Chris@10: distributed over the L
dimension, while the output would be a
Chris@10: M × L × N/2+1 complex array distributed over the M
Chris@10: dimension. To perform the inverse c2r transform with the same data
Chris@10: distributions, you would use the FFTW_TRANSPOSED_IN
flag.
Chris@10:
Chris@10:
Chris@10:
Chris@10: