annotate src/fftw-3.3.8/doc/html/Upgrading-from-FFTW-version-2.html @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
rev   line source
cannam@167 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
cannam@167 2 <html>
cannam@167 3 <!-- This manual is for FFTW
cannam@167 4 (version 3.3.8, 24 May 2018).
cannam@167 5
cannam@167 6 Copyright (C) 2003 Matteo Frigo.
cannam@167 7
cannam@167 8 Copyright (C) 2003 Massachusetts Institute of Technology.
cannam@167 9
cannam@167 10 Permission is granted to make and distribute verbatim copies of this
cannam@167 11 manual provided the copyright notice and this permission notice are
cannam@167 12 preserved on all copies.
cannam@167 13
cannam@167 14 Permission is granted to copy and distribute modified versions of this
cannam@167 15 manual under the conditions for verbatim copying, provided that the
cannam@167 16 entire resulting derived work is distributed under the terms of a
cannam@167 17 permission notice identical to this one.
cannam@167 18
cannam@167 19 Permission is granted to copy and distribute translations of this manual
cannam@167 20 into another language, under the above conditions for modified versions,
cannam@167 21 except that this permission notice may be stated in a translation
cannam@167 22 approved by the Free Software Foundation. -->
cannam@167 23 <!-- Created by GNU Texinfo 6.3, http://www.gnu.org/software/texinfo/ -->
cannam@167 24 <head>
cannam@167 25 <title>FFTW 3.3.8: Upgrading from FFTW version 2</title>
cannam@167 26
cannam@167 27 <meta name="description" content="FFTW 3.3.8: Upgrading from FFTW version 2">
cannam@167 28 <meta name="keywords" content="FFTW 3.3.8: Upgrading from FFTW version 2">
cannam@167 29 <meta name="resource-type" content="document">
cannam@167 30 <meta name="distribution" content="global">
cannam@167 31 <meta name="Generator" content="makeinfo">
cannam@167 32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
cannam@167 33 <link href="index.html#Top" rel="start" title="Top">
cannam@167 34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
cannam@167 35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
cannam@167 36 <link href="index.html#Top" rel="up" title="Top">
cannam@167 37 <link href="Installation-and-Customization.html#Installation-and-Customization" rel="next" title="Installation and Customization">
cannam@167 38 <link href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f" rel="prev" title="Wisdom of Fortran?">
cannam@167 39 <style type="text/css">
cannam@167 40 <!--
cannam@167 41 a.summary-letter {text-decoration: none}
cannam@167 42 blockquote.indentedblock {margin-right: 0em}
cannam@167 43 blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
cannam@167 44 blockquote.smallquotation {font-size: smaller}
cannam@167 45 div.display {margin-left: 3.2em}
cannam@167 46 div.example {margin-left: 3.2em}
cannam@167 47 div.lisp {margin-left: 3.2em}
cannam@167 48 div.smalldisplay {margin-left: 3.2em}
cannam@167 49 div.smallexample {margin-left: 3.2em}
cannam@167 50 div.smalllisp {margin-left: 3.2em}
cannam@167 51 kbd {font-style: oblique}
cannam@167 52 pre.display {font-family: inherit}
cannam@167 53 pre.format {font-family: inherit}
cannam@167 54 pre.menu-comment {font-family: serif}
cannam@167 55 pre.menu-preformatted {font-family: serif}
cannam@167 56 pre.smalldisplay {font-family: inherit; font-size: smaller}
cannam@167 57 pre.smallexample {font-size: smaller}
cannam@167 58 pre.smallformat {font-family: inherit; font-size: smaller}
cannam@167 59 pre.smalllisp {font-size: smaller}
cannam@167 60 span.nolinebreak {white-space: nowrap}
cannam@167 61 span.roman {font-family: initial; font-weight: normal}
cannam@167 62 span.sansserif {font-family: sans-serif; font-weight: normal}
cannam@167 63 ul.no-bullet {list-style: none}
cannam@167 64 -->
cannam@167 65 </style>
cannam@167 66
cannam@167 67
cannam@167 68 </head>
cannam@167 69
cannam@167 70 <body lang="en">
cannam@167 71 <a name="Upgrading-from-FFTW-version-2"></a>
cannam@167 72 <div class="header">
cannam@167 73 <p>
cannam@167 74 Next: <a href="Installation-and-Customization.html#Installation-and-Customization" accesskey="n" rel="next">Installation and Customization</a>, Previous: <a href="Calling-FFTW-from-Legacy-Fortran.html#Calling-FFTW-from-Legacy-Fortran" accesskey="p" rel="prev">Calling FFTW from Legacy Fortran</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
cannam@167 75 </div>
cannam@167 76 <hr>
cannam@167 77 <a name="Upgrading-from-FFTW-version-2-1"></a>
cannam@167 78 <h2 class="chapter">9 Upgrading from FFTW version 2</h2>
cannam@167 79
cannam@167 80 <p>In this chapter, we outline the process for updating codes designed for
cannam@167 81 the older FFTW 2 interface to work with FFTW 3. The interface for FFTW
cannam@167 82 3 is not backwards-compatible with the interface for FFTW 2 and earlier
cannam@167 83 versions; codes written to use those versions will fail to link with
cannam@167 84 FFTW 3. Nor is it possible to write &ldquo;compatibility wrappers&rdquo; to
cannam@167 85 bridge the gap (at least not efficiently), because FFTW 3 has different
cannam@167 86 semantics from previous versions. However, upgrading should be a
cannam@167 87 straightforward process because the data formats are identical and the
cannam@167 88 overall style of planning/execution is essentially the same.
cannam@167 89 </p>
cannam@167 90 <p>Unlike FFTW 2, there are no separate header files for real and complex
cannam@167 91 transforms (or even for different precisions) in FFTW 3; all interfaces
cannam@167 92 are defined in the <code>&lt;fftw3.h&gt;</code> header file.
cannam@167 93 </p>
cannam@167 94 <a name="Numeric-Types"></a>
cannam@167 95 <h3 class="heading">Numeric Types</h3>
cannam@167 96
cannam@167 97 <p>The main difference in data types is that <code>fftw_complex</code> in FFTW 2
cannam@167 98 was defined as a <code>struct</code> with macros <code>c_re</code> and <code>c_im</code>
cannam@167 99 for accessing the real/imaginary parts. (This is binary-compatible with
cannam@167 100 FFTW 3 on any machine except perhaps for some older Crays in single
cannam@167 101 precision.) The equivalent macros for FFTW 3 are:
cannam@167 102 </p>
cannam@167 103 <div class="example">
cannam@167 104 <pre class="example">#define c_re(c) ((c)[0])
cannam@167 105 #define c_im(c) ((c)[1])
cannam@167 106 </pre></div>
cannam@167 107
cannam@167 108 <p>This does not work if you are using the C99 complex type, however,
cannam@167 109 unless you insert a <code>double*</code> typecast into the above macros
cannam@167 110 (see <a href="Complex-numbers.html#Complex-numbers">Complex numbers</a>).
cannam@167 111 </p>
cannam@167 112 <p>Also, FFTW 2 had an <code>fftw_real</code> typedef that was an alias for
cannam@167 113 <code>double</code> (in double precision). In FFTW 3 you should just use
cannam@167 114 <code>double</code> (or whatever precision you are employing).
cannam@167 115 </p>
cannam@167 116 <a name="Plans"></a>
cannam@167 117 <h3 class="heading">Plans</h3>
cannam@167 118
cannam@167 119 <p>The major difference between FFTW 2 and FFTW 3 is in the
cannam@167 120 planning/execution division of labor. In FFTW 2, plans were found for a
cannam@167 121 given transform size and type, and then could be applied to <em>any</em>
cannam@167 122 arrays and for <em>any</em> multiplicity/stride parameters. In FFTW 3,
cannam@167 123 you specify the particular arrays, stride parameters, etcetera when
cannam@167 124 creating the plan, and the plan is then executed for <em>those</em> arrays
cannam@167 125 (unless the guru interface is used) and <em>those</em> parameters
cannam@167 126 <em>only</em>. (FFTW 2 had &ldquo;specific planner&rdquo; routines that planned for
cannam@167 127 a particular array and stride, but the plan could still be used for
cannam@167 128 other arrays and strides.) That is, much of the information that was
cannam@167 129 formerly specified at execution time is now specified at planning time.
cannam@167 130 </p>
cannam@167 131 <p>Like FFTW 2&rsquo;s specific planner routines, the FFTW 3 planner overwrites
cannam@167 132 the input/output arrays unless you use <code>FFTW_ESTIMATE</code>.
cannam@167 133 </p>
cannam@167 134 <p>FFTW 2 had separate data types <code>fftw_plan</code>, <code>fftwnd_plan</code>,
cannam@167 135 <code>rfftw_plan</code>, and <code>rfftwnd_plan</code> for complex and real one- and
cannam@167 136 multi-dimensional transforms, and each type had its own &lsquo;<samp>destroy</samp>&rsquo;
cannam@167 137 function. In FFTW 3, all plans are of type <code>fftw_plan</code> and all are
cannam@167 138 destroyed by <code>fftw_destroy_plan(plan)</code>.
cannam@167 139 </p>
cannam@167 140 <p>Where you formerly used <code>fftw_create_plan</code> and <code>fftw_one</code> to
cannam@167 141 plan and compute a single 1d transform, you would now use
cannam@167 142 <code>fftw_plan_dft_1d</code> to plan the transform. If you used the generic
cannam@167 143 <code>fftw</code> function to execute the transform with multiplicity
cannam@167 144 (<code>howmany</code>) and stride parameters, you would now use the advanced
cannam@167 145 interface <code>fftw_plan_many_dft</code> to specify those parameters. The
cannam@167 146 plans are now executed with <code>fftw_execute(plan)</code>, which takes all
cannam@167 147 of its parameters (including the input/output arrays) from the plan.
cannam@167 148 </p>
cannam@167 149 <p>In-place transforms no longer interpret their output argument as scratch
cannam@167 150 space, nor is there an <code>FFTW_IN_PLACE</code> flag. You simply pass the
cannam@167 151 same pointer for both the input and output arguments. (Previously, the
cannam@167 152 output <code>ostride</code> and <code>odist</code> parameters were ignored for
cannam@167 153 in-place transforms; now, if they are specified via the advanced
cannam@167 154 interface, they are significant even in the in-place case, although they
cannam@167 155 should normally equal the corresponding input parameters.)
cannam@167 156 </p>
cannam@167 157 <p>The <code>FFTW_ESTIMATE</code> and <code>FFTW_MEASURE</code> flags have the same
cannam@167 158 meaning as before, although the planning time will differ. You may also
cannam@167 159 consider using <code>FFTW_PATIENT</code>, which is like <code>FFTW_MEASURE</code>
cannam@167 160 except that it takes more time in order to consider a wider variety of
cannam@167 161 algorithms.
cannam@167 162 </p>
cannam@167 163 <p>For multi-dimensional complex DFTs, instead of <code>fftwnd_create_plan</code>
cannam@167 164 (or <code>fftw2d_create_plan</code> or <code>fftw3d_create_plan</code>), followed by
cannam@167 165 <code>fftwnd_one</code>, you would use <code>fftw_plan_dft</code> (or
cannam@167 166 <code>fftw_plan_dft_2d</code> or <code>fftw_plan_dft_3d</code>). followed by
cannam@167 167 <code>fftw_execute</code>. If you used <code>fftwnd</code> to to specify strides
cannam@167 168 etcetera, you would instead specify these via <code>fftw_plan_many_dft</code>.
cannam@167 169 </p>
cannam@167 170 <p>The analogues to <code>rfftw_create_plan</code> and <code>rfftw_one</code> with
cannam@167 171 <code>FFTW_REAL_TO_COMPLEX</code> or <code>FFTW_COMPLEX_TO_REAL</code> directions
cannam@167 172 are <code>fftw_plan_r2r_1d</code> with kind <code>FFTW_R2HC</code> or
cannam@167 173 <code>FFTW_HC2R</code>, followed by <code>fftw_execute</code>. The stride etcetera
cannam@167 174 arguments of <code>rfftw</code> are now in <code>fftw_plan_many_r2r</code>.
cannam@167 175 </p>
cannam@167 176 <p>Instead of <code>rfftwnd_create_plan</code> (or <code>rfftw2d_create_plan</code> or
cannam@167 177 <code>rfftw3d_create_plan</code>) followed by
cannam@167 178 <code>rfftwnd_one_real_to_complex</code> or
cannam@167 179 <code>rfftwnd_one_complex_to_real</code>, you now use <code>fftw_plan_dft_r2c</code>
cannam@167 180 (or <code>fftw_plan_dft_r2c_2d</code> or <code>fftw_plan_dft_r2c_3d</code>) or
cannam@167 181 <code>fftw_plan_dft_c2r</code> (or <code>fftw_plan_dft_c2r_2d</code> or
cannam@167 182 <code>fftw_plan_dft_c2r_3d</code>), respectively, followed by
cannam@167 183 <code>fftw_execute</code>. As usual, the strides etcetera of
cannam@167 184 <code>rfftwnd_real_to_complex</code> or <code>rfftwnd_complex_to_real</code> are no
cannam@167 185 specified in the advanced planner routines,
cannam@167 186 <code>fftw_plan_many_dft_r2c</code> or <code>fftw_plan_many_dft_c2r</code>.
cannam@167 187 </p>
cannam@167 188 <a name="Wisdom-2"></a>
cannam@167 189 <h3 class="heading">Wisdom</h3>
cannam@167 190
cannam@167 191 <p>In FFTW 2, you had to supply the <code>FFTW_USE_WISDOM</code> flag in order to
cannam@167 192 use wisdom; in FFTW 3, wisdom is always used. (You could simulate the
cannam@167 193 FFTW 2 wisdom-less behavior by calling <code>fftw_forget_wisdom</code> after
cannam@167 194 every planner call.)
cannam@167 195 </p>
cannam@167 196 <p>The FFTW 3 wisdom import/export routines are almost the same as before
cannam@167 197 (although the storage format is entirely different). There is one
cannam@167 198 significant difference, however. In FFTW 2, the import routines would
cannam@167 199 never read past the end of the wisdom, so you could store extra data
cannam@167 200 beyond the wisdom in the same file, for example. In FFTW 3, the
cannam@167 201 file-import routine may read up to a few hundred bytes past the end of
cannam@167 202 the wisdom, so you cannot store other data just beyond it.<a name="DOCF11" href="#FOOT11"><sup>11</sup></a>
cannam@167 203 </p>
cannam@167 204 <p>Wisdom has been enhanced by additional humility in FFTW 3: whereas FFTW
cannam@167 205 2 would re-use wisdom for a given transform size regardless of the
cannam@167 206 stride etc., in FFTW 3 wisdom is only used with the strides etc. for
cannam@167 207 which it was created. Unfortunately, this means FFTW 3 has to create
cannam@167 208 new plans from scratch more often than FFTW 2 (in FFTW 2, planning
cannam@167 209 e.g. one transform of size 1024 also created wisdom for all smaller
cannam@167 210 powers of 2, but this no longer occurs).
cannam@167 211 </p>
cannam@167 212 <p>FFTW 3 also has the new routine <code>fftw_import_system_wisdom</code> to
cannam@167 213 import wisdom from a standard system-wide location.
cannam@167 214 </p>
cannam@167 215 <a name="Memory-allocation"></a>
cannam@167 216 <h3 class="heading">Memory allocation</h3>
cannam@167 217
cannam@167 218 <p>In FFTW 3, we recommend allocating your arrays with <code>fftw_malloc</code>
cannam@167 219 and deallocating them with <code>fftw_free</code>; this is not required, but
cannam@167 220 allows optimal performance when SIMD acceleration is used. (Those two
cannam@167 221 functions actually existed in FFTW 2, and worked the same way, but were
cannam@167 222 not documented.)
cannam@167 223 </p>
cannam@167 224 <p>In FFTW 2, there were <code>fftw_malloc_hook</code> and <code>fftw_free_hook</code>
cannam@167 225 functions that allowed the user to replace FFTW&rsquo;s memory-allocation
cannam@167 226 routines (e.g. to implement different error-handling, since by default
cannam@167 227 FFTW prints an error message and calls <code>exit</code> to abort the program
cannam@167 228 if <code>malloc</code> returns <code>NULL</code>). These hooks are not supported in
cannam@167 229 FFTW 3; those few users who require this functionality can just
cannam@167 230 directly modify the memory-allocation routines in FFTW (they are defined
cannam@167 231 in <code>kernel/alloc.c</code>).
cannam@167 232 </p>
cannam@167 233 <a name="Fortran-interface"></a>
cannam@167 234 <h3 class="heading">Fortran interface</h3>
cannam@167 235
cannam@167 236 <p>In FFTW 2, the subroutine names were obtained by replacing &lsquo;<samp>fftw_</samp>&rsquo;
cannam@167 237 with &lsquo;<samp>fftw_f77</samp>&rsquo;; in FFTW 3, you replace &lsquo;<samp>fftw_</samp>&rsquo; with
cannam@167 238 &lsquo;<samp>dfftw_</samp>&rsquo; (or &lsquo;<samp>sfftw_</samp>&rsquo; or &lsquo;<samp>lfftw_</samp>&rsquo;, depending upon the
cannam@167 239 precision).
cannam@167 240 </p>
cannam@167 241 <p>In FFTW 3, we have begun recommending that you always declare the type
cannam@167 242 used to store plans as <code>integer*8</code>. (Too many people didn&rsquo;t notice
cannam@167 243 our instruction to switch from <code>integer</code> to <code>integer*8</code> for
cannam@167 244 64-bit machines.)
cannam@167 245 </p>
cannam@167 246 <p>In FFTW 3, we provide a <code>fftw3.f</code> &ldquo;header file&rdquo; to include in
cannam@167 247 your code (and which is officially installed on Unix systems). (In FFTW
cannam@167 248 2, we supplied a <code>fftw_f77.i</code> file, but it was not installed.)
cannam@167 249 </p>
cannam@167 250 <p>Otherwise, the C-Fortran interface relationship is much the same as it
cannam@167 251 was before (e.g. return values become initial parameters, and
cannam@167 252 multi-dimensional arrays are in column-major order). Unlike FFTW 2, we
cannam@167 253 do provide some support for wisdom import/export in Fortran
cannam@167 254 (see <a href="Wisdom-of-Fortran_003f.html#Wisdom-of-Fortran_003f">Wisdom of Fortran?</a>).
cannam@167 255 </p>
cannam@167 256 <a name="Threads"></a>
cannam@167 257 <h3 class="heading">Threads</h3>
cannam@167 258
cannam@167 259 <p>Like FFTW 2, only the execution routines are thread-safe. All planner
cannam@167 260 routines, etcetera, should be called by only a single thread at a time
cannam@167 261 (see <a href="Thread-safety.html#Thread-safety">Thread safety</a>). <em>Unlike</em> FFTW 2, there is no special
cannam@167 262 <code>FFTW_THREADSAFE</code> flag for the planner to allow a given plan to be
cannam@167 263 usable by multiple threads in parallel; this is now the case by default.
cannam@167 264 </p>
cannam@167 265 <p>The multi-threaded version of FFTW 2 required you to pass the number of
cannam@167 266 threads each time you execute the transform. The number of threads is
cannam@167 267 now stored in the plan, and is specified before the planner is called by
cannam@167 268 <code>fftw_plan_with_nthreads</code>. The threads initialization routine used
cannam@167 269 to be called <code>fftw_threads_init</code> and would return zero on success;
cannam@167 270 the new routine is called <code>fftw_init_threads</code> and returns zero on
cannam@167 271 failure. See <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>.
cannam@167 272 </p>
cannam@167 273 <p>There is no separate threads header file in FFTW 3; all the function
cannam@167 274 prototypes are in <code>&lt;fftw3.h&gt;</code>. However, you still have to link to
cannam@167 275 a separate library (<code>-lfftw3_threads -lfftw3 -lm</code> on Unix), as well as
cannam@167 276 to the threading library (e.g. POSIX threads on Unix).
cannam@167 277 </p>
cannam@167 278 <div class="footnote">
cannam@167 279 <hr>
cannam@167 280 <h4 class="footnotes-heading">Footnotes</h4>
cannam@167 281
cannam@167 282 <h3><a name="FOOT11" href="#DOCF11">(11)</a></h3>
cannam@167 283 <p>We
cannam@167 284 do our own buffering because GNU libc I/O routines are horribly slow for
cannam@167 285 single-character I/O, apparently for thread-safety reasons (whether you
cannam@167 286 are using threads or not).</p>
cannam@167 287 </div>
cannam@167 288 <hr>
cannam@167 289 <div class="header">
cannam@167 290 <p>
cannam@167 291 Next: <a href="Installation-and-Customization.html#Installation-and-Customization" accesskey="n" rel="next">Installation and Customization</a>, Previous: <a href="Calling-FFTW-from-Legacy-Fortran.html#Calling-FFTW-from-Legacy-Fortran" accesskey="p" rel="prev">Calling FFTW from Legacy Fortran</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
cannam@167 292 </div>
cannam@167 293
cannam@167 294
cannam@167 295
cannam@167 296 </body>
cannam@167 297 </html>