annotate fft/fftw/fftw-3.3.4/doc/html/Multi_002ddimensional-MPI-DFTs-of-Real-Data.html @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 <html lang="en">
Chris@19 2 <head>
Chris@19 3 <title>Multi-dimensional MPI DFTs of Real Data - FFTW 3.3.4</title>
Chris@19 4 <meta http-equiv="Content-Type" content="text/html">
Chris@19 5 <meta name="description" content="FFTW 3.3.4">
Chris@19 6 <meta name="generator" content="makeinfo 4.13">
Chris@19 7 <link title="Top" rel="start" href="index.html#Top">
Chris@19 8 <link rel="up" href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI" title="Distributed-memory FFTW with MPI">
Chris@19 9 <link rel="prev" href="MPI-Data-Distribution.html#MPI-Data-Distribution" title="MPI Data Distribution">
Chris@19 10 <link rel="next" href="Other-Multi_002ddimensional-Real_002ddata-MPI-Transforms.html#Other-Multi_002ddimensional-Real_002ddata-MPI-Transforms" title="Other Multi-dimensional Real-data MPI Transforms">
Chris@19 11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
Chris@19 12 <!--
Chris@19 13 This manual is for FFTW
Chris@19 14 (version 3.3.4, 20 September 2013).
Chris@19 15
Chris@19 16 Copyright (C) 2003 Matteo Frigo.
Chris@19 17
Chris@19 18 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@19 19
Chris@19 20 Permission is granted to make and distribute verbatim copies of
Chris@19 21 this manual provided the copyright notice and this permission
Chris@19 22 notice are preserved on all copies.
Chris@19 23
Chris@19 24 Permission is granted to copy and distribute modified versions of
Chris@19 25 this manual under the conditions for verbatim copying, provided
Chris@19 26 that the entire resulting derived work is distributed under the
Chris@19 27 terms of a permission notice identical to this one.
Chris@19 28
Chris@19 29 Permission is granted to copy and distribute translations of this
Chris@19 30 manual into another language, under the above conditions for
Chris@19 31 modified versions, except that this permission notice may be
Chris@19 32 stated in a translation approved by the Free Software Foundation.
Chris@19 33 -->
Chris@19 34 <meta http-equiv="Content-Style-Type" content="text/css">
Chris@19 35 <style type="text/css"><!--
Chris@19 36 pre.display { font-family:inherit }
Chris@19 37 pre.format { font-family:inherit }
Chris@19 38 pre.smalldisplay { font-family:inherit; font-size:smaller }
Chris@19 39 pre.smallformat { font-family:inherit; font-size:smaller }
Chris@19 40 pre.smallexample { font-size:smaller }
Chris@19 41 pre.smalllisp { font-size:smaller }
Chris@19 42 span.sc { font-variant:small-caps }
Chris@19 43 span.roman { font-family:serif; font-weight:normal; }
Chris@19 44 span.sansserif { font-family:sans-serif; font-weight:normal; }
Chris@19 45 --></style>
Chris@19 46 </head>
Chris@19 47 <body>
Chris@19 48 <div class="node">
Chris@19 49 <a name="Multi-dimensional-MPI-DFTs-of-Real-Data"></a>
Chris@19 50 <a name="Multi_002ddimensional-MPI-DFTs-of-Real-Data"></a>
Chris@19 51 <p>
Chris@19 52 Next:&nbsp;<a rel="next" accesskey="n" href="Other-Multi_002ddimensional-Real_002ddata-MPI-Transforms.html#Other-Multi_002ddimensional-Real_002ddata-MPI-Transforms">Other Multi-dimensional Real-data MPI Transforms</a>,
Chris@19 53 Previous:&nbsp;<a rel="previous" accesskey="p" href="MPI-Data-Distribution.html#MPI-Data-Distribution">MPI Data Distribution</a>,
Chris@19 54 Up:&nbsp;<a rel="up" accesskey="u" href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI">Distributed-memory FFTW with MPI</a>
Chris@19 55 <hr>
Chris@19 56 </div>
Chris@19 57
Chris@19 58 <h3 class="section">6.5 Multi-dimensional MPI DFTs of Real Data</h3>
Chris@19 59
Chris@19 60 <p>FFTW's MPI interface also supports multi-dimensional DFTs of real
Chris@19 61 data, similar to the serial r2c and c2r interfaces. (Parallel
Chris@19 62 one-dimensional real-data DFTs are not currently supported; you must
Chris@19 63 use a complex transform and set the imaginary parts of the inputs to
Chris@19 64 zero.)
Chris@19 65
Chris@19 66 <p>The key points to understand for r2c and c2r MPI transforms (compared
Chris@19 67 to the MPI complex DFTs or the serial r2c/c2r transforms), are:
Chris@19 68
Chris@19 69 <ul>
Chris@19 70 <li>Just as for serial transforms, r2c/c2r DFTs transform n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;n<sub>d-1</sub> real
Chris@19 71 data to/from n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;(n<sub>d-1</sub>/2 + 1) complex data: the last dimension of the
Chris@19 72 complex data is cut in half (rounded down), plus one. As for the
Chris@19 73 serial transforms, the sizes you pass to the &lsquo;<samp><span class="samp">plan_dft_r2c</span></samp>&rsquo; and
Chris@19 74 &lsquo;<samp><span class="samp">plan_dft_c2r</span></samp>&rsquo; are the n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;n<sub>d-1</sub> dimensions of the real data.
Chris@19 75
Chris@19 76 <li><a name="index-padding-389"></a>Although the real data is <em>conceptually</em> n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;n<sub>d-1</sub>, it is
Chris@19 77 <em>physically</em> stored as an n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;[2&nbsp;(n<sub>d-1</sub>/2 + 1)] array, where the last
Chris@19 78 dimension has been <em>padded</em> to make it the same size as the
Chris@19 79 complex output. This is much like the in-place serial r2c/c2r
Chris@19 80 interface (see <a href="Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-DFTs-of-Real-Data">Multi-Dimensional DFTs of Real Data</a>), except that
Chris@19 81 in MPI the padding is required even for out-of-place data. The extra
Chris@19 82 padding numbers are ignored by FFTW (they are <em>not</em> like
Chris@19 83 zero-padding the transform to a larger size); they are only used to
Chris@19 84 determine the data layout.
Chris@19 85
Chris@19 86 <li><a name="index-data-distribution-390"></a>The data distribution in MPI for <em>both</em> the real and complex data
Chris@19 87 is determined by the shape of the <em>complex</em> data. That is, you
Chris@19 88 call the appropriate &lsquo;<samp><span class="samp">local size</span></samp>&rsquo; function for the n<sub>0</sub>&nbsp;&times;&nbsp;n<sub>1</sub>&nbsp;&times;&nbsp;n<sub>2</sub>&nbsp;&times;&nbsp;&hellip;&nbsp;&times;&nbsp;(n<sub>d-1</sub>/2 + 1)
Chris@19 89
Chris@19 90 <p>complex data, and then use the <em>same</em> distribution for the real
Chris@19 91 data except that the last complex dimension is replaced by a (padded)
Chris@19 92 real dimension of twice the length.
Chris@19 93
Chris@19 94 </ul>
Chris@19 95
Chris@19 96 <p>For example suppose we are performing an out-of-place r2c transform of
Chris@19 97 L&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;N real data [padded to L&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;2(N/2+1)],
Chris@19 98 resulting in L&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;N/2+1 complex data. Similar to the
Chris@19 99 example in <a href="2d-MPI-example.html#g_t2d-MPI-example">2d MPI example</a>, we might do something like:
Chris@19 100
Chris@19 101 <pre class="example"> #include &lt;fftw3-mpi.h&gt;
Chris@19 102
Chris@19 103 int main(int argc, char **argv)
Chris@19 104 {
Chris@19 105 const ptrdiff_t L = ..., M = ..., N = ...;
Chris@19 106 fftw_plan plan;
Chris@19 107 double *rin;
Chris@19 108 fftw_complex *cout;
Chris@19 109 ptrdiff_t alloc_local, local_n0, local_0_start, i, j, k;
Chris@19 110
Chris@19 111 MPI_Init(&amp;argc, &amp;argv);
Chris@19 112 fftw_mpi_init();
Chris@19 113
Chris@19 114 /* <span class="roman">get local data size and allocate</span> */
Chris@19 115 alloc_local = fftw_mpi_local_size_3d(L, M, N/2+1, MPI_COMM_WORLD,
Chris@19 116 &amp;local_n0, &amp;local_0_start);
Chris@19 117 rin = fftw_alloc_real(2 * alloc_local);
Chris@19 118 cout = fftw_alloc_complex(alloc_local);
Chris@19 119
Chris@19 120 /* <span class="roman">create plan for out-of-place r2c DFT</span> */
Chris@19 121 plan = fftw_mpi_plan_dft_r2c_3d(L, M, N, rin, cout, MPI_COMM_WORLD,
Chris@19 122 FFTW_MEASURE);
Chris@19 123
Chris@19 124 /* <span class="roman">initialize rin to some function</span> my_func(x,y,z) */
Chris@19 125 for (i = 0; i &lt; local_n0; ++i)
Chris@19 126 for (j = 0; j &lt; M; ++j)
Chris@19 127 for (k = 0; k &lt; N; ++k)
Chris@19 128 rin[(i*M + j) * (2*(N/2+1)) + k] = my_func(local_0_start+i, j, k);
Chris@19 129
Chris@19 130 /* <span class="roman">compute transforms as many times as desired</span> */
Chris@19 131 fftw_execute(plan);
Chris@19 132
Chris@19 133 fftw_destroy_plan(plan);
Chris@19 134
Chris@19 135 MPI_Finalize();
Chris@19 136 }
Chris@19 137 </pre>
Chris@19 138 <p><a name="index-fftw_005falloc_005freal-391"></a><a name="index-row_002dmajor-392"></a>Note that we allocated <code>rin</code> using <code>fftw_alloc_real</code> with an
Chris@19 139 argument of <code>2 * alloc_local</code>: since <code>alloc_local</code> is the
Chris@19 140 number of <em>complex</em> values to allocate, the number of <em>real</em>
Chris@19 141 values is twice as many. The <code>rin</code> array is then
Chris@19 142 local_n0&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;2(N/2+1) in row-major order, so its
Chris@19 143 <code>(i,j,k)</code> element is at the index <code>(i*M + j) * (2*(N/2+1)) +
Chris@19 144 k</code> (see <a href="Multi_002ddimensional-Array-Format.html#Multi_002ddimensional-Array-Format">Multi-dimensional Array Format</a>).
Chris@19 145
Chris@19 146 <p><a name="index-transpose-393"></a><a name="index-FFTW_005fTRANSPOSED_005fOUT-394"></a><a name="index-FFTW_005fTRANSPOSED_005fIN-395"></a>As for the complex transforms, improved performance can be obtained by
Chris@19 147 specifying that the output is the transpose of the input or vice versa
Chris@19 148 (see <a href="Transposed-distributions.html#Transposed-distributions">Transposed distributions</a>). In our L&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;N r2c
Chris@19 149 example, including <code>FFTW_TRANSPOSED_OUT</code> in the flags means that
Chris@19 150 the input would be a padded L&nbsp;&times;&nbsp;M&nbsp;&times;&nbsp;2(N/2+1) real array
Chris@19 151 distributed over the <code>L</code> dimension, while the output would be a
Chris@19 152 M&nbsp;&times;&nbsp;L&nbsp;&times;&nbsp;N/2+1 complex array distributed over the <code>M</code>
Chris@19 153 dimension. To perform the inverse c2r transform with the same data
Chris@19 154 distributions, you would use the <code>FFTW_TRANSPOSED_IN</code> flag.
Chris@19 155
Chris@19 156 <!-- -->
Chris@19 157 </body></html>
Chris@19 158