Chris@19: @node Installation and Customization, Acknowledgments, Upgrading from FFTW version 2, Top Chris@19: @chapter Installation and Customization Chris@19: @cindex installation Chris@19: Chris@19: This chapter describes the installation and customization of FFTW, the Chris@19: latest version of which may be downloaded from Chris@19: @uref{http://www.fftw.org, the FFTW home page}. Chris@19: Chris@19: In principle, FFTW should work on any system with an ANSI C compiler Chris@19: (@code{gcc} is fine). However, planner time is drastically reduced if Chris@19: FFTW can exploit a hardware cycle counter; FFTW comes with cycle-counter Chris@19: support for all modern general-purpose CPUs, but you may need to add a Chris@19: couple of lines of code if your compiler is not yet supported Chris@19: (@pxref{Cycle Counters}). (On Unix, there will be a warning at the end Chris@19: of the @code{configure} output if no cycle counter is found.) Chris@19: @cindex cycle counter Chris@19: @cindex compiler Chris@19: @cindex portability Chris@19: Chris@19: Chris@19: Installation of FFTW is simplest if you have a Unix or a GNU system, Chris@19: such as GNU/Linux, and we describe this case in the first section below, Chris@19: including the use of special configuration options to e.g. install Chris@19: different precisions or exploit optimizations for particular Chris@19: architectures (e.g. SIMD). Compilation on non-Unix systems is a more Chris@19: manual process, but we outline the procedure in the second section. It Chris@19: is also likely that pre-compiled binaries will be available for popular Chris@19: systems. Chris@19: Chris@19: Finally, we describe how you can customize FFTW for particular needs by Chris@19: generating @emph{codelets} for fast transforms of sizes not supported Chris@19: efficiently by the standard FFTW distribution. Chris@19: @cindex codelet Chris@19: Chris@19: @menu Chris@19: * Installation on Unix:: Chris@19: * Installation on non-Unix systems:: Chris@19: * Cycle Counters:: Chris@19: * Generating your own code:: Chris@19: @end menu Chris@19: Chris@19: @c ------------------------------------------------------------ Chris@19: Chris@19: @node Installation on Unix, Installation on non-Unix systems, Installation and Customization, Installation and Customization Chris@19: @section Installation on Unix Chris@19: Chris@19: FFTW comes with a @code{configure} program in the GNU style. Chris@19: Installation can be as simple as: Chris@19: @fpindex configure Chris@19: Chris@19: @example Chris@19: ./configure Chris@19: make Chris@19: make install Chris@19: @end example Chris@19: Chris@19: This will build the uniprocessor complex and real transform libraries Chris@19: along with the test programs. (We recommend that you use GNU Chris@19: @code{make} if it is available; on some systems it is called Chris@19: @code{gmake}.) The ``@code{make install}'' command installs the fftw Chris@19: and rfftw libraries in standard places, and typically requires root Chris@19: privileges (unless you specify a different install directory with the Chris@19: @code{--prefix} flag to @code{configure}). You can also type Chris@19: ``@code{make check}'' to put the FFTW test programs through their paces. Chris@19: If you have problems during configuration or compilation, you may want Chris@19: to run ``@code{make distclean}'' before trying again; this ensures that Chris@19: you don't have any stale files left over from previous compilation Chris@19: attempts. Chris@19: Chris@19: The @code{configure} script chooses the @code{gcc} compiler by default, Chris@19: if it is available; you can select some other compiler with: Chris@19: @example Chris@19: ./configure CC="@r{@i{}}" Chris@19: @end example Chris@19: Chris@19: The @code{configure} script knows good @code{CFLAGS} (C compiler flags) Chris@19: @cindex compiler flags Chris@19: for a few systems. If your system is not known, the @code{configure} Chris@19: script will print out a warning. In this case, you should re-configure Chris@19: FFTW with the command Chris@19: @example Chris@19: ./configure CFLAGS="@r{@i{}}" Chris@19: @end example Chris@19: and then compile as usual. If you do find an optimal set of Chris@19: @code{CFLAGS} for your system, please let us know what they are (along Chris@19: with the output of @code{config.guess}) so that we can include them in Chris@19: future releases. Chris@19: Chris@19: @code{configure} supports all the standard flags defined by the GNU Chris@19: Coding Standards; see the @code{INSTALL} file in FFTW or Chris@19: @uref{http://www.gnu.org/prep/standards/html_node/index.html, the GNU web page}. Chris@19: Note especially @code{--help} to list all flags and Chris@19: @code{--enable-shared} to create shared, rather than static, libraries. Chris@19: @code{configure} also accepts a few FFTW-specific flags, particularly: Chris@19: Chris@19: @itemize @bullet Chris@19: Chris@19: @item Chris@19: @cindex precision Chris@19: @code{--enable-float}: Produces a single-precision version of FFTW Chris@19: (@code{float}) instead of the default double-precision (@code{double}). Chris@19: @xref{Precision}. Chris@19: Chris@19: @item Chris@19: @cindex precision Chris@19: @code{--enable-long-double}: Produces a long-double precision version of Chris@19: FFTW (@code{long double}) instead of the default double-precision Chris@19: (@code{double}). The @code{configure} script will halt with an error Chris@19: message if @code{long double} is the same size as @code{double} on your Chris@19: machine/compiler. @xref{Precision}. Chris@19: Chris@19: @item Chris@19: @cindex precision Chris@19: @code{--enable-quad-precision}: Produces a quadruple-precision version Chris@19: of FFTW using the nonstandard @code{__float128} type provided by Chris@19: @code{gcc} 4.6 or later on x86, x86-64, and Itanium architectures, Chris@19: instead of the default double-precision (@code{double}). The Chris@19: @code{configure} script will halt with an error message if the Chris@19: compiler is not @code{gcc} version 4.6 or later or if @code{gcc}'s Chris@19: @code{libquadmath} library is not installed. @xref{Precision}. Chris@19: Chris@19: @item Chris@19: @cindex threads Chris@19: @code{--enable-threads}: Enables compilation and installation of the Chris@19: FFTW threads library (@pxref{Multi-threaded FFTW}), which provides a Chris@19: simple interface to parallel transforms for SMP systems. By default, Chris@19: the threads routines are not compiled. Chris@19: Chris@19: @item Chris@19: @code{--enable-openmp}: Like @code{--enable-threads}, but using OpenMP Chris@19: compiler directives in order to induce parallelism rather than Chris@19: spawning its own threads directly, and installing an @samp{fftw3_omp} library Chris@19: rather than an @samp{fftw3_threads} library (@pxref{Multi-threaded Chris@19: FFTW}). You can use both @code{--enable-openmp} and @code{--enable-threads} Chris@19: since they compile/install libraries with different names. By default, Chris@19: the OpenMP routines are not compiled. Chris@19: Chris@19: @item Chris@19: @code{--with-combined-threads}: By default, if @code{--enable-threads} Chris@19: is used, the threads support is compiled into a separate library that Chris@19: must be linked in addition to the main FFTW library. This is so that Chris@19: users of the serial library do not need to link the system threads Chris@19: libraries. If @code{--with-combined-threads} is specified, however, Chris@19: then no separate threads library is created, and threads are included Chris@19: in the main FFTW library. This is mainly useful under Windows, where Chris@19: no system threads library is required and inter-library dependencies Chris@19: are problematic. Chris@19: Chris@19: @item Chris@19: @cindex MPI Chris@19: @code{--enable-mpi}: Enables compilation and installation of the FFTW Chris@19: MPI library (@pxref{Distributed-memory FFTW with MPI}), which provides Chris@19: parallel transforms for distributed-memory systems with MPI. (By Chris@19: default, the MPI routines are not compiled.) @xref{FFTW MPI Chris@19: Installation}. Chris@19: Chris@19: @item Chris@19: @cindex Fortran-callable wrappers Chris@19: @code{--disable-fortran}: Disables inclusion of legacy-Fortran Chris@19: wrapper routines (@pxref{Calling FFTW from Legacy Fortran}) in the standard Chris@19: FFTW libraries. These wrapper routines increase the library size by Chris@19: only a negligible amount, so they are included by default as long as Chris@19: the @code{configure} script finds a Fortran compiler on your system. Chris@19: (To specify a particular Fortran compiler @i{foo}, pass Chris@19: @code{F77=}@i{foo} to @code{configure}.) Chris@19: Chris@19: @item Chris@19: @code{--with-g77-wrappers}: By default, when Fortran wrappers are Chris@19: included, the wrappers employ the linking conventions of the Fortran Chris@19: compiler detected by the @code{configure} script. If this compiler is Chris@19: GNU @code{g77}, however, then @emph{two} versions of the wrappers are Chris@19: included: one with @code{g77}'s idiosyncratic convention of appending Chris@19: two underscores to identifiers, and one with the more common Chris@19: convention of appending only a single underscore. This way, the same Chris@19: FFTW library will work with both @code{g77} and other Fortran Chris@19: compilers, such as GNU @code{gfortran}. However, the converse is not Chris@19: true: if you configure with a different compiler, then the Chris@19: @code{g77}-compatible wrappers are not included. By specifying Chris@19: @code{--with-g77-wrappers}, the @code{g77}-compatible wrappers are Chris@19: included in addition to wrappers for whatever Fortran compiler Chris@19: @code{configure} finds. Chris@19: @fpindex g77 Chris@19: Chris@19: @item Chris@19: @code{--with-slow-timer}: Disables the use of hardware cycle counters, Chris@19: and falls back on @code{gettimeofday} or @code{clock}. This greatly Chris@19: worsens performance, and should generally not be used (unless you don't Chris@19: have a cycle counter but still really want an optimized plan regardless Chris@19: of the time). @xref{Cycle Counters}. Chris@19: Chris@19: @item Chris@19: @code{--enable-sse}, @code{--enable-sse2}, @code{--enable-avx}, Chris@19: @code{--enable-altivec}, @code{--enable-neon}: Enable the compilation of Chris@19: SIMD code for SSE (Pentium III+), SSE2 (Pentium IV+), AVX (Sandy Bridge, Chris@19: Interlagos), AltiVec (PowerPC G4+), NEON (some ARM processors). SSE, Chris@19: AltiVec, and NEON only work with @code{--enable-float} (above). SSE2 Chris@19: works in both single and double precision (and is simply SSE in single Chris@19: precision). The resulting code will @emph{still work} on earlier CPUs Chris@19: lacking the SIMD extensions (SIMD is automatically disabled, although Chris@19: the FFTW library is still larger). Chris@19: @itemize @minus Chris@19: @item Chris@19: These options require a compiler supporting SIMD extensions, and Chris@19: compiler support is always a bit flaky: see the FFTW FAQ for a list of Chris@19: compiler versions that have problems compiling FFTW. Chris@19: @item Chris@19: With AltiVec and @code{gcc}, you may have to use the Chris@19: @code{-mabi=altivec} option when compiling any code that links to FFTW, Chris@19: in order to properly align the stack; otherwise, FFTW could crash when Chris@19: it tries to use an AltiVec feature. (This is not necessary on MacOS X.) Chris@19: @item Chris@19: With SSE/SSE2 and @code{gcc}, you should use a version of gcc that Chris@19: properly aligns the stack when compiling any code that links to FFTW. Chris@19: By default, @code{gcc} 2.95 and later versions align the stack as Chris@19: needed, but you should not compile FFTW with the @code{-Os} option or the Chris@19: @code{-mpreferred-stack-boundary} option with an argument less than 4. Chris@19: @item Chris@19: Because of the large variety of ARM processors and ABIs, FFTW Chris@19: does not attempt to guess the correct @code{gcc} flags for generating Chris@19: NEON code. In general, you will have to provide them on the command line. Chris@19: This command line is known to have worked at least once: Chris@19: @example Chris@19: ./configure --with-slow-timer --host=arm-linux-gnueabi \ Chris@19: --enable-single --enable-neon \ Chris@19: "CC=arm-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=softfp" Chris@19: @end example Chris@19: @end itemize Chris@19: Chris@19: @end itemize Chris@19: Chris@19: @cindex compiler Chris@19: To force @code{configure} to use a particular C compiler @i{foo} Chris@19: (instead of the default, usually @code{gcc}), pass @code{CC=}@i{foo} to the Chris@19: @code{configure} script; you may also need to set the flags via the variable Chris@19: @code{CFLAGS} as described above. Chris@19: @cindex compiler flags Chris@19: Chris@19: @c ------------------------------------------------------------ Chris@19: @node Installation on non-Unix systems, Cycle Counters, Installation on Unix, Installation and Customization Chris@19: @section Installation on non-Unix systems Chris@19: Chris@19: It should be relatively straightforward to compile FFTW even on non-Unix Chris@19: systems lacking the niceties of a @code{configure} script. Basically, Chris@19: you need to edit the @code{config.h} header (copy it from Chris@19: @code{config.h.in}) to @code{#define} the various options and compiler Chris@19: characteristics, and then compile all the @samp{.c} files in the Chris@19: relevant directories. Chris@19: Chris@19: The @code{config.h} header contains about 100 options to set, each one Chris@19: initially an @code{#undef}, each documented with a comment, and most of Chris@19: them fairly obvious. For most of the options, you should simply Chris@19: @code{#define} them to @code{1} if they are applicable, although a few Chris@19: options require a particular value (e.g. @code{SIZEOF_LONG_LONG} should Chris@19: be defined to the size of the @code{long long} type, in bytes, or zero Chris@19: if it is not supported). We will likely post some sample Chris@19: @code{config.h} files for various operating systems and compilers for Chris@19: you to use (at least as a starting point). Please let us know if you Chris@19: have to hand-create a configuration file (and/or a pre-compiled binary) Chris@19: that you want to share. Chris@19: Chris@19: To create the FFTW library, you will then need to compile all of the Chris@19: @samp{.c} files in the @code{kernel}, @code{dft}, @code{dft/scalar}, Chris@19: @code{dft/scalar/codelets}, @code{rdft}, @code{rdft/scalar}, Chris@19: @code{rdft/scalar/r2cf}, @code{rdft/scalar/r2cb}, Chris@19: @code{rdft/scalar/r2r}, @code{reodft}, and @code{api} directories. Chris@19: If you are compiling with SIMD support (e.g. you defined Chris@19: @code{HAVE_SSE2} in @code{config.h}), then you also need to compile Chris@19: the @code{.c} files in the @code{simd-support}, Chris@19: @code{@{dft,rdft@}/simd}, @code{@{dft,rdft@}/simd/*} directories. Chris@19: Chris@19: Once these files are all compiled, link them into a library, or a shared Chris@19: library, or directly into your program. Chris@19: Chris@19: To compile the FFTW test program, additionally compile the code in the Chris@19: @code{libbench2/} directory, and link it into a library. Then compile Chris@19: the code in the @code{tests/} directory and link it to the Chris@19: @code{libbench2} and FFTW libraries. To compile the @code{fftw-wisdom} Chris@19: (command-line) tool (@pxref{Wisdom Utilities}), compile Chris@19: @code{tools/fftw-wisdom.c} and link it to the @code{libbench2} and FFTW Chris@19: libraries Chris@19: Chris@19: @c ------------------------------------------------------------ Chris@19: @node Cycle Counters, Generating your own code, Installation on non-Unix systems, Installation and Customization Chris@19: @section Cycle Counters Chris@19: @cindex cycle counter Chris@19: Chris@19: FFTW's planner actually executes and times different possible FFT Chris@19: algorithms in order to pick the fastest plan for a given @math{n}. In Chris@19: order to do this in as short a time as possible, however, the timer must Chris@19: have a very high resolution, and to accomplish this we employ the Chris@19: hardware @dfn{cycle counters} that are available on most CPUs. Chris@19: Currently, FFTW supports the cycle counters on x86, PowerPC/POWER, Alpha, Chris@19: UltraSPARC (SPARC v9), IA64, PA-RISC, and MIPS processors. Chris@19: Chris@19: @cindex compiler Chris@19: Access to the cycle counters, unfortunately, is a compiler and/or Chris@19: operating-system dependent task, often requiring inline assembly Chris@19: language, and it may be that your compiler is not supported. If you are Chris@19: @emph{not} supported, FFTW will by default fall back on its estimator Chris@19: (effectively using @code{FFTW_ESTIMATE} for all plans). Chris@19: @ctindex FFTW_ESTIMATE Chris@19: Chris@19: You can add support by editing the file @code{kernel/cycle.h}; normally, Chris@19: this will involve adapting one of the examples already present in order Chris@19: to use the inline-assembler syntax for your C compiler, and will only Chris@19: require a couple of lines of code. Anyone adding support for a new Chris@19: system to @code{cycle.h} is encouraged to email us at @email{fftw@@fftw.org}. Chris@19: Chris@19: If a cycle counter is not available on your system (e.g. some embedded Chris@19: processor), and you don't want to use estimated plans, as a last resort Chris@19: you can use the @code{--with-slow-timer} option to @code{configure} (on Chris@19: Unix) or @code{#define WITH_SLOW_TIMER} in @code{config.h} (elsewhere). Chris@19: This will use the much lower-resolution @code{gettimeofday} function, or even Chris@19: @code{clock} if the former is unavailable, and planning will be Chris@19: extremely slow. Chris@19: Chris@19: @c ------------------------------------------------------------ Chris@19: @node Generating your own code, , Cycle Counters, Installation and Customization Chris@19: @section Generating your own code Chris@19: @cindex code generator Chris@19: Chris@19: The directory @code{genfft} contains the programs that were used to Chris@19: generate FFTW's ``codelets,'' which are hard-coded transforms of small Chris@19: sizes. Chris@19: @cindex codelet Chris@19: We do not expect casual users to employ the generator, which is a rather Chris@19: sophisticated program that generates directed acyclic graphs of FFT Chris@19: algorithms and performs algebraic simplifications on them. It was Chris@19: written in Objective Caml, a dialect of ML, which is available at Chris@19: @uref{http://caml.inria.fr/ocaml/index.en.html}. Chris@19: @cindex Caml Chris@19: Chris@19: Chris@19: If you have Objective Caml installed (along with recent versions of Chris@19: GNU @code{autoconf}, @code{automake}, and @code{libtool}), then you Chris@19: can change the set of codelets that are generated or play with the Chris@19: generation options. The set of generated codelets is specified by the Chris@19: @code{@{dft,rdft@}/@{codelets,simd@}/*/Makefile.am} files. For example, you can add Chris@19: efficient REDFT codelets of small sizes by modifying Chris@19: @code{rdft/codelets/r2r/Makefile.am}. Chris@19: @cindex REDFT Chris@19: After you modify any @code{Makefile.am} files, you can type @code{sh Chris@19: bootstrap.sh} in the top-level directory followed by @code{make} to Chris@19: re-generate the files. Chris@19: Chris@19: We do not provide more details about the code-generation process, since Chris@19: we do not expect that most users will need to generate their own code. Chris@19: However, feel free to contact us at @email{fftw@@fftw.org} if Chris@19: you are interested in the subject. Chris@19: Chris@19: @cindex monadic programming Chris@19: You might find it interesting to learn Caml and/or some modern Chris@19: programming techniques that we used in the generator (including monadic Chris@19: programming), especially if you heard the rumor that Java and Chris@19: object-oriented programming are the latest advancement in the field. Chris@19: The internal operation of the codelet generator is described in the Chris@19: paper, ``A Fast Fourier Transform Compiler,'' by M. Frigo, which is Chris@19: available from the @uref{http://www.fftw.org,FFTW home page} and also Chris@19: appeared in the @cite{Proceedings of the 1999 ACM SIGPLAN Conference on Chris@19: Programming Language Design and Implementation (PLDI)}. Chris@19: