annotate src/fftw-3.3.5/doc/FAQ/fftw-faq.bfnn @ 148:b4bfdf10c4b3

Update Win64 capnp builds to v0.6
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 22 May 2017 18:56:49 +0100
parents 7867fa7e1b6b
children
rev   line source
cannam@127 1 \comment This is the source for the FFTW FAQ list, in
cannam@127 2 \comment the Bizarre Format With No Name. It is turned into Lout
cannam@127 3 \comment input, HTML, plain ASCII and an Info document by a Perl script.
cannam@127 4 \comment
cannam@127 5 \comment The format and scripts come from the Linux FAQ, by
cannam@127 6 \comment Ian Jackson.
cannam@127 7 \set brieftitle FFTW FAQ
cannam@127 8 \set author <A href="http://www.fftw.org">Matteo Frigo and Steven G. Johnson</A> / <A href="mailto:fftw@fftw.org">fftw@fftw.org</A>
cannam@127 9 \set authormail fftw@fftw.org
cannam@127 10 \set title FFTW Frequently Asked Questions with Answers
cannam@127 11 \set copyholder Matteo Frigo and Massachusetts Institute of Technology
cannam@127 12 \call-html startup html.refs2
cannam@127 13 \copyto ASCII
cannam@127 14 FFTW FREQUENTLY ASKED QUESTIONS WITH ANSWERS
cannam@127 15 `date '+%d %h %Y'`
cannam@127 16 Matteo Frigo
cannam@127 17 Steven G. Johnson
cannam@127 18 <fftw@fftw.org>
cannam@127 19
cannam@127 20 \endcopy
cannam@127 21 \copyto INFO
cannam@127 22 INFO-DIR-SECTION Development
cannam@127 23 START-INFO-DIR-ENTRY
cannam@127 24 * FFTW FAQ: (fftw-faq). FFTW Frequently Asked Questions with Answers.
cannam@127 25 END-INFO-DIR-ENTRY
cannam@127 26
cannam@127 27 
cannam@127 28 File: $prefix.info, Node: Top, Next: Question 1.1, Up: (dir)
cannam@127 29
cannam@127 30 FFTW FREQUENTLY ASKED QUESTIONS WITH ANSWERS
cannam@127 31 `date '+%d %h %Y'`
cannam@127 32 Matteo Frigo
cannam@127 33 Steven G. Johnson
cannam@127 34 <fftw@fftw.org>
cannam@127 35
cannam@127 36 \endcopy
cannam@127 37
cannam@127 38 This is the list of Frequently Asked Questions about FFTW, a
cannam@127 39 collection of fast C routines for computing the Discrete Fourier
cannam@127 40 Transform in one or more dimensions.
cannam@127 41
cannam@127 42 \section Index
cannam@127 43
cannam@127 44 \index
cannam@127 45
cannam@127 46 \comment ######################################################################
cannam@127 47
cannam@127 48 \section Introduction and General Information
cannam@127 49
cannam@127 50 \question 26aug:whatisfftw What is FFTW?
cannam@127 51
cannam@127 52 FFTW is a free collection of fast C routines for computing the
cannam@127 53 Discrete Fourier Transform in one or more dimensions. It includes
cannam@127 54 complex, real, symmetric, and parallel transforms, and can handle
cannam@127 55 arbitrary array sizes efficiently. FFTW is typically faster than
cannam@127 56 other publically-available FFT implementations, and is even
cannam@127 57 competitive with vendor-tuned libraries. (See our web page for
cannam@127 58 extensive benchmarks.) To achieve this performance, FFTW uses novel
cannam@127 59 code-generation and runtime self-optimization techniques (along with
cannam@127 60 many other tricks).
cannam@127 61
cannam@127 62 \question 26aug:whereisfftw How do I obtain FFTW?
cannam@127 63
cannam@127 64 FFTW can be found at \docref{the FFTW web page\}. You can also
cannam@127 65 retrieve it from \ftpon ftp.fftw.org in \ftpin /pub/fftw.
cannam@127 66
cannam@127 67 \question 26aug:isfftwfree Is FFTW free software?
cannam@127 68
cannam@127 69 Starting with version 1.3, FFTW is Free Software in the technical
cannam@127 70 sense defined by the Free Software Foundation (see \docref{Categories
cannam@127 71 of Free and Non-Free Software\}), and is distributed under the terms
cannam@127 72 of the GNU General Public License. Previous versions of FFTW were
cannam@127 73 distributed without fee for noncommercial use, but were not
cannam@127 74 technically ``free.''
cannam@127 75
cannam@127 76 Non-free licenses for FFTW are also available that permit different
cannam@127 77 terms of use than the GPL.
cannam@127 78
cannam@127 79 \question 10apr:nonfree What is this about non-free licenses?
cannam@127 80
cannam@127 81 The non-free licenses are for companies that wish to use FFTW in their
cannam@127 82 products but are unwilling to release their software under the GPL
cannam@127 83 (which would require them to release source code and allow free
cannam@127 84 redistribution). Such users can purchase an unlimited-use license
cannam@127 85 from MIT. Contact us for more details.
cannam@127 86
cannam@127 87 We could instead have released FFTW under the LGPL, or even disallowed
cannam@127 88 non-Free usage. Suffice it to say, however, that MIT owns the
cannam@127 89 copyright to FFTW and they only let us GPL it because we convinced
cannam@127 90 them that it would neither affect their licensing revenue nor irritate
cannam@127 91 existing licensees.
cannam@127 92
cannam@127 93 \question 24oct:west In the West? I thought MIT was in the East?
cannam@127 94
cannam@127 95 Not to an Italian. You could say that we're a Spaghetti Western
cannam@127 96 (with apologies to Sergio Leone).
cannam@127 97
cannam@127 98 \comment ######################################################################
cannam@127 99
cannam@127 100 \section Installing FFTW
cannam@127 101
cannam@127 102 \question 26aug:systems Which systems does FFTW run on?
cannam@127 103
cannam@127 104 FFTW is written in ANSI C, and should work on any system with a decent
cannam@127 105 C compiler. (See also \qref runOnWindows, \qref compilerCrashes.)
cannam@127 106 FFTW can also take advantage of certain hardware-specific features,
cannam@127 107 such as cycle counters and SIMD instructions, but this is optional.
cannam@127 108
cannam@127 109 \question 26aug:runOnWindows Does FFTW run on Windows?
cannam@127 110
cannam@127 111 Yes, many people have reported successfully using FFTW on Windows with
cannam@127 112 various compilers. FFTW was not developed on Windows, but the source
cannam@127 113 code is essentially straight ANSI C. See also the \docref{FFTW
cannam@127 114 Windows installation notes\}, \qref compilerCrashes, and \qref
cannam@127 115 vbetalia.
cannam@127 116
cannam@127 117 \question 26aug:compilerCrashes My compiler has trouble with FFTW.
cannam@127 118
cannam@127 119 Complain fiercely to the vendor of the compiler.
cannam@127 120
cannam@127 121 We have successfully used \courier{gcc\} 3.2.x on x86 and PPC, a
cannam@127 122 recent Compaq C compiler for Alpha, version 6 of IBM's \courier{xlc\}
cannam@127 123 compiler for AIX, Intel's \courier{icc\} versions 5-7, and Sun
cannam@127 124 WorkShop \courier{cc\} version 6.
cannam@127 125
cannam@127 126 FFTW is likely to push compilers to their limits, however, and several
cannam@127 127 compiler bugs have been exposed by FFTW. A partial list follows.
cannam@127 128
cannam@127 129 \courier{gcc\} 2.95.x for Solaris/SPARC produces incorrect code for
cannam@127 130 the test program (workaround: recompile the \courier{libbench2\}
cannam@127 131 directory with \courier{-O2\}).
cannam@127 132
cannam@127 133 NetBSD/macppc 1.6 comes with a \courier{gcc\} version that also
cannam@127 134 miscompiles the test program. (Please report a workaround if you know
cannam@127 135 one.)
cannam@127 136
cannam@127 137 \courier{gcc\} 3.2.3 for ARM reportedly crashes during compilation.
cannam@127 138 This bug is reportedly fixed in later versions of \courier{gcc\}.
cannam@127 139
cannam@127 140 Versions 8.0 and 8.1 of Intel's \courier{icc\} falsely claim to be
cannam@127 141 \courier{gcc\}, so you should specify \courier{CC="icc -no-gcc"\};
cannam@127 142 this is automatic in FFTW 3.1. \courier{icc-8.0.066\} reportely
cannam@127 143 produces incorrect code for FFTW 2.1.5, but is fixed in version 8.1.
cannam@127 144 \courier{icc-7.1\} compiler build 20030402Z appears to produce
cannam@127 145 incorrect dependencies, causing the compilation to fail.
cannam@127 146 \courier{icc-7.1\} build 20030307Z appears to work fine. (Use
cannam@127 147 \courier{icc -V\} to check which build you have.) As of 2003/04/18,
cannam@127 148 build 20030402Z appears not to be available any longer on Intel's
cannam@127 149 website, whereas the older build 20030307Z is available.
cannam@127 150
cannam@127 151 \courier{ranlib\} of GNU \courier{binutils\} 2.9.1 on Irix has been
cannam@127 152 observed to corrupt the FFTW libraries, causing a link failure when
cannam@127 153 FFTW is compiled. Since \courier{ranlib\} is completely superfluous
cannam@127 154 on Irix, we suggest deleting it from your system and replacing it with
cannam@127 155 a symbolic link to \courier{/bin/echo\}.
cannam@127 156
cannam@127 157 If support for SIMD instructions is enabled in FFTW, further compiler
cannam@127 158 problems may appear:
cannam@127 159
cannam@127 160 \courier{gcc\} 3.4.[0123] for x86 produces incorrect SSE2 code for
cannam@127 161 FFTW when \courier{-O2\} (the best choice for FFTW) is used, causing
cannam@127 162 FFTW to crash (\courier{make check\} crashes). This bug is fixed in
cannam@127 163 \courier{gcc\} 3.4.4. On x86_64 (amd64/em64t), \courier{gcc\} 3.4.4
cannam@127 164 reportedly still has a similar problem, but this is fixed as of
cannam@127 165 \courier{gcc\} 3.4.6.
cannam@127 166
cannam@127 167 \courier{gcc-3.2\} for x86 produces incorrect SIMD code if
cannam@127 168 \courier{-O3\} is used. The same compiler produces incorrect SIMD
cannam@127 169 code if no optimization is used, too. When using \courier{gcc-3.2\},
cannam@127 170 it is a good idea not to change the default \courier{CFLAGS\} selected
cannam@127 171 by the \courier{configure\} script.
cannam@127 172
cannam@127 173 Some 3.0.x and 3.1.x versions of \courier{gcc\} on \courier{x86\} may
cannam@127 174 crash. \courier{gcc\} so-called 2.96 shipping with RedHat 7.3 crashes
cannam@127 175 when compiling SIMD code. In both cases, please upgrade to
cannam@127 176 \courier{gcc-3.2\} or later.
cannam@127 177
cannam@127 178 Intel's \courier{icc\} 6.0 misaligns SSE constants, but FFTW has a
cannam@127 179 workaround. \courier{icc\} 8.x fails to compile FFTW 3.0.x because it
cannam@127 180 falsely claims to be \courier{gcc\}; we believe this to be a bug in
cannam@127 181 \courier{icc\}, but FFTW 3.1 has a workaround.
cannam@127 182
cannam@127 183 Visual C++ 2003 reportedly produces incorrect code for SSE/SSE2 when
cannam@127 184 compiling FFTW. This bug was reportedly fixed in VC++ 2005;
cannam@127 185 alternatively, you could switch to the Intel compiler. VC++ 6.0 also
cannam@127 186 reportedly produces incorrect code for the file
cannam@127 187 \courier{reodft11e-r2hc-odd.c\} unless optimizations are disabled for
cannam@127 188 that file.
cannam@127 189
cannam@127 190 \courier{gcc\} 2.95 on MacOS X miscompiles AltiVec code (fixed in
cannam@127 191 later versions). \courier{gcc\} 3.2.x miscompiles AltiVec
cannam@127 192 permutations, but FFTW has a workaround. \courier{gcc\} 4.0.1 on
cannam@127 193 MacOS for Intel crashes when compiling FFTW; a workaround is to
cannam@127 194 compile one file without optimization: \courier{cd kernel; make
cannam@127 195 CFLAGS=" " trig.lo\}.
cannam@127 196
cannam@127 197 \courier{gcc\} 4.1.1 reportedly crashes when compiling FFTW for MIPS;
cannam@127 198 the workaround is to compile the file it crashes on
cannam@127 199 (\courier{t2_64.c\}) with a lower optimization level.
cannam@127 200
cannam@127 201 \courier{gcc\} versions 4.1.2 to 4.2.0 for x86 reportedly miscompile
cannam@127 202 FFTW 3.1's test program, causing \courier{make check\} to crash
cannam@127 203 (\courier{gcc\} bug #26528). The bug was reportedly fixed in
cannam@127 204 \courier{gcc\} version 4.2.1 and later. A workaround is to compile
cannam@127 205 \courier{libbench2/verify-lib.c\} without optimization.
cannam@127 206
cannam@127 207 \question 26aug:solarisSucks FFTW does not compile on Solaris, complaining about \courier{const\}.
cannam@127 208
cannam@127 209 We know that at least on Solaris 2.5.x with Sun's compilers 4.2 you
cannam@127 210 might get error messages from \courier{make\} such as
cannam@127 211
cannam@127 212 \courier{"./fftw.h", line 88: warning: const is a keyword in ANSI C\}
cannam@127 213
cannam@127 214 This is the case when the \courier{configure\} script reports that
cannam@127 215 \courier{const\} does not work:
cannam@127 216
cannam@127 217 \courier{checking for working const... (cached) no\}
cannam@127 218
cannam@127 219 You should be aware that Solaris comes with two compilers, namely,
cannam@127 220 \courier{/opt/SUNWspro/SC4.2/bin/cc\} and \courier{/usr/ucb/cc\}. The
cannam@127 221 latter compiler is non-ANSI. Indeed, it is a perverse shell script
cannam@127 222 that calls the real compiler in non-ANSI mode. In order
cannam@127 223 to compile FFTW, change your path so that the right \courier{cc\}
cannam@127 224 is used.
cannam@127 225
cannam@127 226 To know whether your compiler is the right one, type
cannam@127 227 \courier{cc -V\}. If the compiler prints ``\courier{ucbcc\}'',
cannam@127 228 as in
cannam@127 229
cannam@127 230 \courier{ucbcc: WorkShop Compilers 4.2 30 Oct 1996 C 4.2\}
cannam@127 231
cannam@127 232 then the compiler is wrong. The right message is something like
cannam@127 233
cannam@127 234 \courier{cc: WorkShop Compilers 4.2 30 Oct 1996 C 4.2\}
cannam@127 235
cannam@127 236 \question 19mar:3dnow What's the difference between \courier{--enable-3dnow\} and \courier{--enable-k7\}?
cannam@127 237
cannam@127 238 \courier{--enable-k7\} enables 3DNow! instructions on K7 processors
cannam@127 239 (AMD Athlon and its variants). K7 support is provided by assembly
cannam@127 240 routines generated by a special purpose compiler.
cannam@127 241 As of fftw-3.2, --enable-k7 is no longer supported.
cannam@127 242
cannam@127 243 \courier{--enable-3dnow\} enables generic 3DNow! support using
cannam@127 244 \courier{gcc\} builtin functions. This works on earlier AMD
cannam@127 245 processors, but it is not as fast as our special assembly routines.
cannam@127 246 As of fftw-3.1, --enable-3dnow is no longer supported.
cannam@127 247
cannam@127 248 \question 18apr:fma What's the difference between the fma and the non-fma versions?
cannam@127 249
cannam@127 250 The fma version tries to exploit the fused multiply-add instructions
cannam@127 251 implemented in many processors such as PowerPC, ia-64, and MIPS. The
cannam@127 252 two FFTW packages are otherwise identical. In FFTW 3.1, the fma and
cannam@127 253 non-fma versions were merged together into a single package, and the
cannam@127 254 \courier{configure\} script attempts to automatically guess which
cannam@127 255 version to use.
cannam@127 256
cannam@127 257 The FFTW 3.1 \courier{configure\} script enables fma by default on
cannam@127 258 PowerPC, Itanium, and PA-RISC, and disables it otherwise. You can
cannam@127 259 force one or the other by using the \courier{--enable-fma\} or
cannam@127 260 \courier{--disable-fma\} flag for \courier{configure\}.
cannam@127 261
cannam@127 262 Definitely use fma if you have a PowerPC-based system with
cannam@127 263 \courier{gcc\} (or IBM \courier{xlc\}). This includes all GNU/Linux
cannam@127 264 systems for PowerPC and the older PowerPC-based MacOS systems. Also
cannam@127 265 use it on PA-RISC and Itanium with the HP/UX compiler.
cannam@127 266
cannam@127 267 Definitely do not use the fma version if you have an ia-32 processor
cannam@127 268 (Intel, AMD, MacOS on Intel, etcetera).
cannam@127 269
cannam@127 270 For other architectures/compilers, the situation is not so clear. For
cannam@127 271 example, ia-64 has the fma instruction, but \courier{gcc-3.2\} appears
cannam@127 272 not to exploit it correctly. Other compilers may do the right thing,
cannam@127 273 but we have not tried them. Please send us your feedback so that we
cannam@127 274 can update this FAQ entry.
cannam@127 275
cannam@127 276 \question 26aug:languages Which language is FFTW written in?
cannam@127 277
cannam@127 278 FFTW is written in ANSI C. Most of the code, however, was
cannam@127 279 automatically generated by a program called \courier{genfft\}, written
cannam@127 280 in the Objective Caml dialect of ML. You do not need to know ML or to
cannam@127 281 have an Objective Caml compiler in order to use FFTW.
cannam@127 282
cannam@127 283 \courier{genfft\} is provided with the FFTW sources, which means that
cannam@127 284 you can play with the code generator if you want. In this case, you
cannam@127 285 need a working Objective Caml system. Objective Caml is available
cannam@127 286 from \docref{the Caml web page\}.
cannam@127 287
cannam@127 288 \question 26aug:fortran Can I call FFTW from Fortran?
cannam@127 289
cannam@127 290 Yes, FFTW (versions 1.3 and higher) contains a Fortran-callable
cannam@127 291 interface, documented in the FFTW manual.
cannam@127 292
cannam@127 293 By default, FFTW configures its Fortran interface to work with the
cannam@127 294 first compiler it finds, e.g. \courier{g77\}. To configure for a
cannam@127 295 different, incompatible Fortran compiler \courier{foobar\}, use
cannam@127 296 \courier{./configure F77=foobar\} when installing FFTW. (In the case
cannam@127 297 of \courier{g77\}, however, FFTW 3.x also includes an extra set of
cannam@127 298 Fortran-callable routines with one less underscore at the end of
cannam@127 299 identifiers, which should cover most other Fortran compilers on Linux
cannam@127 300 at least.)
cannam@127 301
cannam@127 302 \question 26aug:cplusplus Can I call FFTW from C++?
cannam@127 303
cannam@127 304 Most definitely. FFTW should compile and/or link under any C++
cannam@127 305 compiler. Moreover, it is likely that the C++ \courier{<complex>\}
cannam@127 306 template class is bit-compatible with FFTW's complex-number format
cannam@127 307 (see the FFTW manual for more details).
cannam@127 308
cannam@127 309 \question 26aug:whynotfortran Why isn't FFTW written in Fortran/C++?
cannam@127 310
cannam@127 311 Because we don't like those languages, and neither approaches the
cannam@127 312 portability of C.
cannam@127 313
cannam@127 314 \question 29mar:singleprec How do I compile FFTW to run in single precision?
cannam@127 315
cannam@127 316 On a Unix system: \courier{configure --enable-float\}. On a non-Unix
cannam@127 317 system: edit \courier{config.h\} to \courier{#define\} the symbol
cannam@127 318 \courier{FFTW_SINGLE\} (for FFTW 3.x). In both cases, you must then
cannam@127 319 recompile FFTW. In FFTW 3, all FFTW identifiers will then begin with
cannam@127 320 \courier{fftwf_\} instead of \courier{fftw_\}.
cannam@127 321
cannam@127 322 \question 28mar:64bitk7 --enable-k7 does not work on x86-64
cannam@127 323
cannam@127 324 Support for --enable-k7 was discontinued in fftw-3.2.
cannam@127 325
cannam@127 326 The fftw-3.1 release supports --enable-k7. This option only works on
cannam@127 327 32-bit x86 machines that implement 3DNow!, including the AMD Athlon
cannam@127 328 and the AMD Opteron in 32-bit mode. --enable-k7 does not work on AMD
cannam@127 329 Opteron in 64-bit mode. Use --enable-sse for x86-64 machines.
cannam@127 330
cannam@127 331 FFTW supports 3DNow! by means of assembly code generated by a
cannam@127 332 special-purpose compiler. It is hard to produce assembly code that
cannam@127 333 works in both 32-bit and 64-bit mode.
cannam@127 334
cannam@127 335 \comment ######################################################################
cannam@127 336
cannam@127 337 \section Using FFTW
cannam@127 338
cannam@127 339 \question 15mar:fftw2to3 Why not support the FFTW 2 interface in FFTW 3?
cannam@127 340
cannam@127 341 FFTW 3 has semantics incompatible with earlier versions: its plans can
cannam@127 342 only be used for a given stride, multiplicity, and other
cannam@127 343 characteristics of the input and output arrays; these stronger
cannam@127 344 semantics are necessary for performance reasons. Thus, it is
cannam@127 345 impossible to efficiently emulate the older interface (whose plans can
cannam@127 346 be used for any transform of the same size). We believe that it
cannam@127 347 should be possible to upgrade most programs without any difficulty,
cannam@127 348 however.
cannam@127 349
cannam@127 350 \question 20mar:planperarray Why do FFTW 3 plans encapsulate the input/output arrays and not just the algorithm?
cannam@127 351
cannam@127 352 There are several reasons:
cannam@127 353
cannam@127 354 \call startlist
cannam@127 355 \call item
cannam@127 356 It was important for performance reasons that the plan be specific to
cannam@127 357 array characteristics like the stride (and alignment, for SIMD), and
cannam@127 358 requiring that the user maintain these invariants is error prone.
cannam@127 359 \call item
cannam@127 360 In most high-performance applications, as far as we can tell, you are
cannam@127 361 usually transforming the same array over and over, so FFTW's semantics
cannam@127 362 should not be a burden.
cannam@127 363 \call item
cannam@127 364 If you need to transform another array of the same size, creating a
cannam@127 365 new plan once the first exists is a cheap operation.
cannam@127 366 \call item
cannam@127 367 If you need to transform many arrays of the same size at once, you
cannam@127 368 should really use the \courier{plan_many\} routines in FFTW's "advanced"
cannam@127 369 interface.
cannam@127 370 \call item
cannam@127 371 If the abovementioned array characteristics are the same, you are
cannam@127 372 willing to pay close attention to the documentation, and you really
cannam@127 373 need to, we provide a "new-array execution" interface to apply a plan
cannam@127 374 to a new array.
cannam@127 375 \call endlist
cannam@127 376
cannam@127 377 \question 25may:slow FFTW seems really slow.
cannam@127 378
cannam@127 379 You are probably recreating the plan before every transform, rather
cannam@127 380 than creating it once and reusing it for all transforms of the same
cannam@127 381 size. FFTW is designed to be used in the following way:
cannam@127 382
cannam@127 383 \call startlist
cannam@127 384 \call item
cannam@127 385 First, you create a plan. This will take several seconds.
cannam@127 386 \call item
cannam@127 387 Then, you reuse the plan many times to perform FFTs. These are fast.
cannam@127 388 \call endlist
cannam@127 389
cannam@127 390 If you don't need to compute many transforms and the time for the
cannam@127 391 planner is significant, you have two options. First, you can use the
cannam@127 392 \courier{FFTW_ESTIMATE\} option in the planner, which uses heuristics
cannam@127 393 instead of runtime measurements and produces a good plan in a short
cannam@127 394 time. Second, you can use the wisdom feature to precompute the plan;
cannam@127 395 see \qref savePlans
cannam@127 396
cannam@127 397 \question 22oct:slows FFTW slows down after repeated calls.
cannam@127 398
cannam@127 399 Probably, NaNs or similar are creeping into your data, and the
cannam@127 400 slowdown is due to the resulting floating-point exceptions. For
cannam@127 401 example, be aware that repeatedly FFTing the same array is a diverging
cannam@127 402 process (because FFTW computes the unnormalized transform).
cannam@127 403
cannam@127 404 \question 22oct:segfault An FFTW routine is crashing when I call it.
cannam@127 405
cannam@127 406 Did the FFTW test programs pass (\courier{make check\}, or \courier{cd
cannam@127 407 tests; make bigcheck\} if you want to be paranoid)? If so, you almost
cannam@127 408 certainly have a bug in your own code. For example, you could be
cannam@127 409 passing invalid arguments (such as wrongly-sized arrays) to FFTW, or
cannam@127 410 you could simply have memory corruption elsewhere in your program that
cannam@127 411 causes random crashes later on. Please don't complain to us unless
cannam@127 412 you can come up with a minimal self-contained program (preferably
cannam@127 413 under 30 lines) that illustrates the problem.
cannam@127 414
cannam@127 415 \question 22oct:fortran64 My Fortran program crashes when calling FFTW.
cannam@127 416
cannam@127 417 As described in the manual, on 64-bit machines you must store the
cannam@127 418 plans in variables large enough to hold a pointer, for example
cannam@127 419 \courier{integer*8\}. We recommend using \courier{integer*8\} on
cannam@127 420 32-bit machines as well, to simplify porting.
cannam@127 421
cannam@127 422 \question 24mar:conventions FFTW gives results different from my old FFT.
cannam@127 423
cannam@127 424 People follow many different conventions for the DFT, and you should
cannam@127 425 be sure to know the ones that we use (described in the FFTW manual).
cannam@127 426 In particular, you should be aware that the
cannam@127 427 \courier{FFTW_FORWARD\}/\courier{FFTW_BACKWARD\} directions correspond
cannam@127 428 to signs of -1/+1 in the exponent of the DFT definition.
cannam@127 429 (\italic{Numerical Recipes\} uses the opposite convention.)
cannam@127 430
cannam@127 431 You should also know that we compute an unnormalized transform. In
cannam@127 432 contrast, Matlab is an example of program that computes a normalized
cannam@127 433 transform. See \qref whyscaled.
cannam@127 434
cannam@127 435 Finally, note that floating-point arithmetic is not exact, so
cannam@127 436 different FFT algorithms will give slightly different results (on the
cannam@127 437 order of the numerical accuracy; typically a fractional difference of
cannam@127 438 1e-15 or so in double precision).
cannam@127 439
cannam@127 440 \question 31aug:nondeterministic FFTW gives different results between runs
cannam@127 441
cannam@127 442 If you use \courier{FFTW_MEASURE\} or \courier{FFTW_PATIENT\} mode,
cannam@127 443 then the algorithm FFTW employs is not deterministic: it depends on
cannam@127 444 runtime performance measurements. This will cause the results to vary
cannam@127 445 slightly from run to run. However, the differences should be slight,
cannam@127 446 on the order of the floating-point precision, and therefore should
cannam@127 447 have no practical impact on most applications.
cannam@127 448
cannam@127 449 If you use saved plans (wisdom) or \courier{FFTW_ESTIMATE\} mode,
cannam@127 450 however, then the algorithm is deterministic and the results should be
cannam@127 451 identical between runs.
cannam@127 452
cannam@127 453 \question 26aug:savePlans Can I save FFTW's plans?
cannam@127 454
cannam@127 455 Yes. Starting with version 1.2, FFTW provides the \courier{wisdom\}
cannam@127 456 mechanism for saving plans; see the FFTW manual.
cannam@127 457
cannam@127 458 \question 14sep:whyscaled Why does your inverse transform return a scaled result?
cannam@127 459
cannam@127 460 Computing the forward transform followed by the backward transform (or
cannam@127 461 vice versa) yields the original array scaled by the size of the array.
cannam@127 462 (For multi-dimensional transforms, the size of the array is the
cannam@127 463 product of the dimensions.) We could, instead, have chosen a
cannam@127 464 normalization that would have returned the unscaled array. Or, to
cannam@127 465 accomodate the many conventions in this matter, the transform routines
cannam@127 466 could have accepted a "scale factor" parameter. We did not do this,
cannam@127 467 however, for two reasons. First, we didn't want to sacrifice
cannam@127 468 performance in the common case where the scale factor is 1. Second, in
cannam@127 469 real applications the FFT is followed or preceded by some computation
cannam@127 470 on the data, into which the scale factor can typically be absorbed at
cannam@127 471 little or no cost.
cannam@127 472
cannam@127 473 \question 02dec:centerorigin How can I make FFTW put the origin (zero frequency) at the center of its output?
cannam@127 474
cannam@127 475 For human viewing of a spectrum, it is often convenient to put the
cannam@127 476 origin in frequency space at the center of the output array, rather
cannam@127 477 than in the zero-th element (the default in FFTW). If all of the
cannam@127 478 dimensions of your array are even, you can accomplish this by simply
cannam@127 479 multiplying each element of the input array by (-1)^(i + j + ...),
cannam@127 480 where i, j, etcetera are the indices of the element. (This trick is a
cannam@127 481 general property of the DFT, and is not specific to FFTW.)
cannam@127 482
cannam@127 483 \question 08may:imageaudio How do I FFT an image/audio file in \italic{foobar\} format?
cannam@127 484
cannam@127 485 FFTW performs an FFT on an array of floating-point values. You can
cannam@127 486 certainly use it to compute the transform of an image or audio stream,
cannam@127 487 but you are responsible for figuring out your data format and
cannam@127 488 converting it to the form FFTW requires.
cannam@127 489
cannam@127 490 \question 09apr:linkfails My program does not link (on Unix).
cannam@127 491
cannam@127 492 The libraries must be listed in the correct order (\courier{-lfftw3
cannam@127 493 -lm\} for FFTW 3.x) and \italic{after\} your program sources/objects.
cannam@127 494 (The general rule is that if \italic{A\} uses \italic{B\}, then
cannam@127 495 \italic{A\} must be listed before \italic{B\} in the link command.).
cannam@127 496
cannam@127 497 \question 15mar:linkheader I included your header, but linking still fails.
cannam@127 498
cannam@127 499 You're a C++ programmer, aren't you? You have to compile the FFTW
cannam@127 500 library and link it into your program, not just \courier{#include
cannam@127 501 <fftw3.h>\}. (Yes, this is really a FAQ.)
cannam@127 502
cannam@127 503 \question 22oct:nostack My program crashes, complaining about stack space.
cannam@127 504
cannam@127 505 You cannot declare large arrays with automatic storage (e.g. via
cannam@127 506 \courier{fftw_complex array[N]\}); you should use
cannam@127 507 \courier{fftw_malloc\} (or equivalent) to allocate the arrays you want
cannam@127 508 to transform if they are larger than a few hundred elements.
cannam@127 509
cannam@127 510 \question 13may:leaks FFTW seems to have a memory leak.
cannam@127 511
cannam@127 512 After you create a plan, FFTW caches the information required to
cannam@127 513 quickly recreate the plan. (See \qref savePlans) It also maintains a
cannam@127 514 small amount of other persistent memory. You can deallocate all of
cannam@127 515 FFTW's internally allocated memory, if you wish, by calling
cannam@127 516 \courier{fftw_cleanup()\}, as documented in the manual.
cannam@127 517
cannam@127 518 \question 16may:allzero The output of FFTW's transform is all zeros.
cannam@127 519
cannam@127 520 You should initialize your input array \italic{after\} creating the
cannam@127 521 plan, unless you use \courier{FFTW_ESTIMATE\}: planning with
cannam@127 522 \courier{FFTW_MEASURE\} or \courier{FFTW_PATIENT\} overwrites the
cannam@127 523 input/output arrays, as described in the manual.
cannam@127 524
cannam@127 525 \question 05sep:vbetalia How do I call FFTW from the Microsoft language du jour?
cannam@127 526
cannam@127 527 Please \italic{do not\} ask us Windows-specific questions. We do not
cannam@127 528 use Windows. We know nothing about Visual Basic, Visual C++, or .NET.
cannam@127 529 Please find the appropriate Usenet discussion group and ask your
cannam@127 530 question there. See also \qref runOnWindows.
cannam@127 531
cannam@127 532 \question 15oct:pruned Can I compute only a subset of the DFT outputs?
cannam@127 533
cannam@127 534 In general, no, an FFT intrinsically computes all outputs from all
cannam@127 535 inputs. In principle, there is something called a \italic{pruned
cannam@127 536 FFT\} that can do what you want, but to compute K outputs out of N the
cannam@127 537 complexity is in general O(N log K) instead of O(N log N), thus saving
cannam@127 538 only a small additive factor in the log. (The same argument holds if
cannam@127 539 you instead have only K nonzero inputs.)
cannam@127 540
cannam@127 541 There are some specific cases in which you can get the O(N log K)
cannam@127 542 performance benefits easily, however, by combining a few ordinary
cannam@127 543 FFTs. In particular, the case where you want the first K outputs,
cannam@127 544 where K divides N, can be handled by performing N/K transforms of size
cannam@127 545 K and then summing the outputs multiplied by appropriate phase
cannam@127 546 factors. For more details, see \docref{pruned FFTs with FFTW\}.
cannam@127 547
cannam@127 548 There are also some algorithms that compute pruned transforms
cannam@127 549 \italic{approximately\}, but they are beyond the scope of this FAQ.
cannam@127 550
cannam@127 551 \question 21jan:transpose Can I use FFTW's routines for in-place and out-of-place matrix transposition?
cannam@127 552
cannam@127 553 You can use the FFTW guru interface to create a rank-0 transform of
cannam@127 554 vector rank 2 where the vector strides are transposed. (A rank-0
cannam@127 555 transform is equivalent to a 1D transform of size 1, which. just
cannam@127 556 copies the input into the output.) Specifying the same location for
cannam@127 557 the input and output makes the transpose in-place.
cannam@127 558
cannam@127 559 For double-valued data stored in row-major format, plan creation looks like
cannam@127 560 this:
cannam@127 561
cannam@127 562 \verbatim
cannam@127 563 fftw_plan plan_transpose(int rows, int cols, double *in, double *out)
cannam@127 564 {
cannam@127 565 const unsigned flags = FFTW_ESTIMATE; /* other flags are possible */
cannam@127 566 fftw_iodim howmany_dims[2];
cannam@127 567
cannam@127 568 howmany_dims[0].n = rows;
cannam@127 569 howmany_dims[0].is = cols;
cannam@127 570 howmany_dims[0].os = 1;
cannam@127 571
cannam@127 572 howmany_dims[1].n = cols;
cannam@127 573 howmany_dims[1].is = 1;
cannam@127 574 howmany_dims[1].os = rows;
cannam@127 575
cannam@127 576 return fftw_plan_guru_r2r(/*rank=*/ 0, /*dims=*/ NULL,
cannam@127 577 /*howmany_rank=*/ 2, howmany_dims,
cannam@127 578 in, out, /*kind=*/ NULL, flags);
cannam@127 579 }
cannam@127 580 \endverbatim
cannam@127 581
cannam@127 582 (This entry was written by Rhys Ulerich.)
cannam@127 583
cannam@127 584 \comment ######################################################################
cannam@127 585
cannam@127 586 \section Internals of FFTW
cannam@127 587
cannam@127 588 \question 26aug:howworks How does FFTW work?
cannam@127 589
cannam@127 590 The innovation (if it can be so called) in FFTW consists in having a
cannam@127 591 variety of composable \italic{solvers\}, representing different FFT
cannam@127 592 algorithms and implementation strategies, whose combination into a
cannam@127 593 particular \italic{plan\} for a given size can be determined at
cannam@127 594 runtime according to the characteristics of your machine/compiler.
cannam@127 595 This peculiar software architecture allows FFTW to adapt itself to
cannam@127 596 almost any machine.
cannam@127 597
cannam@127 598 For more details (albeit somewhat outdated), see the paper "FFTW: An
cannam@127 599 Adaptive Software Architecture for the FFT", by M. Frigo and
cannam@127 600 S. G. Johnson, \italic{Proc. ICASSP\} 3, 1381 (1998), also
cannam@127 601 available at \docref{the FFTW web page\}.
cannam@127 602
cannam@127 603 \question 26aug:whyfast Why is FFTW so fast?
cannam@127 604
cannam@127 605 This is a complex question, and there is no simple answer. In fact,
cannam@127 606 the authors do not fully know the answer, either. In addition to many
cannam@127 607 small performance hacks throughout FFTW, there are three general
cannam@127 608 reasons for FFTW's speed.
cannam@127 609
cannam@127 610 \call startlist
cannam@127 611 \call item
cannam@127 612 FFTW uses a variety of FFT algorithms and implementation styles
cannam@127 613 that can be arbitrarily composed to adapt itself to
cannam@127 614 a machine. See \qref howworks.
cannam@127 615 \call item
cannam@127 616 FFTW uses a code generator to produce highly-optimized
cannam@127 617 routines for computing small transforms.
cannam@127 618 \call item
cannam@127 619 FFTW uses explicit divide-and-conquer to take advantage
cannam@127 620 of the memory hierarchy.
cannam@127 621 \call endlist
cannam@127 622
cannam@127 623 For more details (albeit somewhat outdated), see the paper "FFTW: An
cannam@127 624 Adaptive Software Architecture for the FFT", by M. Frigo and
cannam@127 625 S. G. Johnson, \italic{Proc. ICASSP\} 3, 1381 (1998),
cannam@127 626 available along with other references at \docref{the FFTW web page\}.
cannam@127 627
cannam@127 628 \comment ######################################################################
cannam@127 629
cannam@127 630 \section Known bugs
cannam@127 631
cannam@127 632 \question 27aug:rfftwndbug FFTW 1.1 crashes in rfftwnd on Linux.
cannam@127 633
cannam@127 634 This bug was fixed in FFTW 1.2. There was a bug in \courier{rfftwnd\}
cannam@127 635 causing an incorrect amount of memory to be allocated. The bug showed
cannam@127 636 up in Linux with libc-5.3.12 (and nowhere else that we know of).
cannam@127 637
cannam@127 638 \question 15oct:fftwmpibug The MPI transforms in FFTW 1.2 give incorrect results/leak memory.
cannam@127 639
cannam@127 640 These bugs were corrected in FFTW 1.2.1. The MPI transforms (really,
cannam@127 641 just the transpose routines) in FFTW 1.2 had bugs that could cause
cannam@127 642 errors in some situations.
cannam@127 643
cannam@127 644 \question 05nov:testsingbug The test programs in FFTW 1.2.1 fail when I change FFTW to use single precision.
cannam@127 645
cannam@127 646 This bug was fixed in FFTW 1.3. (Older versions of FFTW did
cannam@127 647 work in single precision, but the test programs didn't--the error
cannam@127 648 tolerances in the tests were set for double precision.)
cannam@127 649
cannam@127 650 \question 24mar:teststoobig The test program in FFTW 1.2.1 fails for n > 46340.
cannam@127 651
cannam@127 652 This bug was fixed in FFTW 1.3. FFTW 1.2.1 produced the right answer,
cannam@127 653 but the test program was wrong. For large n, n*n in the naive
cannam@127 654 transform that we used for comparison overflows 32 bit integer
cannam@127 655 precision, breaking the test.
cannam@127 656
cannam@127 657 \question 24aug:linuxthreads The threaded code fails on Linux Redhat 5.0
cannam@127 658
cannam@127 659 We had problems with glibc-2.0.5. The code should work with
cannam@127 660 glibc-2.0.7.
cannam@127 661
cannam@127 662 \question 26sep:bigrfftwnd FFTW 2.0's rfftwnd fails for rank > 1 transforms with a final dimension >= 65536.
cannam@127 663
cannam@127 664 This bug was fixed in FFTW 2.0.1. (There was a 32-bit integer overflow due
cannam@127 665 to a poorly-parenthesized expression.)
cannam@127 666
cannam@127 667 \question 26mar:primebug FFTW 2.0's complex transforms give the wrong results with prime factors 17 to 97.
cannam@127 668
cannam@127 669 There was a bug in the complex transforms that could cause incorrect
cannam@127 670 results under (hopefully rare) circumstances for lengths with
cannam@127 671 intermediate-size prime factors (17-97). This bug was fixed in FFTW
cannam@127 672 2.1.1.
cannam@127 673
cannam@127 674 \question 05apr:mpichbug FFTW 2.1.1's MPI test programs crash with MPICH.
cannam@127 675
cannam@127 676 This bug was fixed in FFTW 2.1.2. The 2.1/2.1.1 MPI test programs crashed
cannam@127 677 when using the MPICH implementation of MPI with the \courier{ch_p4\}
cannam@127 678 device (TCP/IP); the transforms themselves worked fine.
cannam@127 679
cannam@127 680 \question 25may:aixthreadbug FFTW 2.1.2's multi-threaded transforms don't work on AIX.
cannam@127 681
cannam@127 682 This bug was fixed in FFTW 2.1.3. The multi-threaded transforms in
cannam@127 683 previous versions didn't work with AIX's \courier{pthreads\}
cannam@127 684 implementation, which idiosyncratically creates threads in detached
cannam@127 685 (non-joinable) mode by default.
cannam@127 686
cannam@127 687 \question 27sep:bigprimebug FFTW 2.1.2's complex transforms give incorrect results for large prime sizes.
cannam@127 688
cannam@127 689 This bug was fixed in FFTW 2.1.3. FFTW's complex-transform algorithm
cannam@127 690 for prime sizes (in versions 2.0 to 2.1.2) had an integer overflow
cannam@127 691 problem that caused incorrect results for many primes greater than
cannam@127 692 32768 (on 32-bit machines). (Sizes without large prime factors are
cannam@127 693 not affected.)
cannam@127 694
cannam@127 695 \question 25may:solaristhreadbug FFTW 2.1.3's multi-threaded transforms don't give any speedup on Solaris.
cannam@127 696
cannam@127 697 This bug was fixed in FFTW 2.1.4. (By default, Solaris creates
cannam@127 698 threads that do not parallelize over multiple processors, so one has
cannam@127 699 to request the proper behavior specifically.)
cannam@127 700
cannam@127 701 \question 03may:aixflags FFTW 2.1.3 crashes on AIX.
cannam@127 702
cannam@127 703 The FFTW 2.1.3 \courier{configure\} script picked incorrect compiler
cannam@127 704 flags for the \courier{xlc\} compiler on newer IBM processors. This
cannam@127 705 is fixed in FFTW 2.1.4.
cannam@127 706
cannam@127 707 \comment Here it ends!
cannam@127 708