annotate fft/fftw/fftw-3.3.4/doc/html/Usage-of-Multi_002dthreaded-FFTW.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>Usage of Multi-threaded FFTW - 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="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" title="Multi-threaded FFTW">
Chris@19 9 <link rel="prev" href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" title="Installation and Supported Hardware/Software">
Chris@19 10 <link rel="next" href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" title="How Many Threads to Use?">
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="Usage-of-Multi-threaded-FFTW"></a>
Chris@19 50 <a name="Usage-of-Multi_002dthreaded-FFTW"></a>
Chris@19 51 <p>
Chris@19 52 Next:&nbsp;<a rel="next" accesskey="n" href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f">How Many Threads to Use?</a>,
Chris@19 53 Previous:&nbsp;<a rel="previous" accesskey="p" href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware">Installation and Supported Hardware/Software</a>,
Chris@19 54 Up:&nbsp;<a rel="up" accesskey="u" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>
Chris@19 55 <hr>
Chris@19 56 </div>
Chris@19 57
Chris@19 58 <h3 class="section">5.2 Usage of Multi-threaded FFTW</h3>
Chris@19 59
Chris@19 60 <p>Here, it is assumed that the reader is already familiar with the usage
Chris@19 61 of the uniprocessor FFTW routines, described elsewhere in this manual.
Chris@19 62 We only describe what one has to change in order to use the
Chris@19 63 multi-threaded routines.
Chris@19 64
Chris@19 65 <p><a name="index-OpenMP-335"></a>First, programs using the parallel complex transforms should be linked
Chris@19 66 with <code>-lfftw3_threads -lfftw3 -lm</code> on Unix, or <code>-lfftw3_omp
Chris@19 67 -lfftw3 -lm</code> if you compiled with OpenMP. You will also need to link
Chris@19 68 with whatever library is responsible for threads on your system
Chris@19 69 (e.g. <code>-lpthread</code> on GNU/Linux) or include whatever compiler flag
Chris@19 70 enables OpenMP (e.g. <code>-fopenmp</code> with gcc).
Chris@19 71 <a name="index-linking-on-Unix-336"></a>
Chris@19 72
Chris@19 73 <p>Second, before calling <em>any</em> FFTW routines, you should call the
Chris@19 74 function:
Chris@19 75
Chris@19 76 <pre class="example"> int fftw_init_threads(void);
Chris@19 77 </pre>
Chris@19 78 <p><a name="index-fftw_005finit_005fthreads-337"></a>
Chris@19 79 This function, which need only be called once, performs any one-time
Chris@19 80 initialization required to use threads on your system. It returns zero
Chris@19 81 if there was some error (which should not happen under normal
Chris@19 82 circumstances) and a non-zero value otherwise.
Chris@19 83
Chris@19 84 <p>Third, before creating a plan that you want to parallelize, you should
Chris@19 85 call:
Chris@19 86
Chris@19 87 <pre class="example"> void fftw_plan_with_nthreads(int nthreads);
Chris@19 88 </pre>
Chris@19 89 <p><a name="index-fftw_005fplan_005fwith_005fnthreads-338"></a>
Chris@19 90 The <code>nthreads</code> argument indicates the number of threads you want
Chris@19 91 FFTW to use (or actually, the maximum number). All plans subsequently
Chris@19 92 created with any planner routine will use that many threads. You can
Chris@19 93 call <code>fftw_plan_with_nthreads</code>, create some plans, call
Chris@19 94 <code>fftw_plan_with_nthreads</code> again with a different argument, and
Chris@19 95 create some more plans for a new number of threads. Plans already created
Chris@19 96 before a call to <code>fftw_plan_with_nthreads</code> are unaffected. If you
Chris@19 97 pass an <code>nthreads</code> argument of <code>1</code> (the default), threads are
Chris@19 98 disabled for subsequent plans.
Chris@19 99
Chris@19 100 <p><a name="index-OpenMP-339"></a>With OpenMP, to configure FFTW to use all of the currently running
Chris@19 101 OpenMP threads (set by <code>omp_set_num_threads(nthreads)</code> or by the
Chris@19 102 <code>OMP_NUM_THREADS</code> environment variable), you can do:
Chris@19 103 <code>fftw_plan_with_nthreads(omp_get_max_threads())</code>. (The &lsquo;<samp><span class="samp">omp_</span></samp>&rsquo;
Chris@19 104 OpenMP functions are declared via <code>#include &lt;omp.h&gt;</code>.)
Chris@19 105
Chris@19 106 <p><a name="index-thread-safety-340"></a>Given a plan, you then execute it as usual with
Chris@19 107 <code>fftw_execute(plan)</code>, and the execution will use the number of
Chris@19 108 threads specified when the plan was created. When done, you destroy
Chris@19 109 it as usual with <code>fftw_destroy_plan</code>. As described in
Chris@19 110 <a href="Thread-safety.html#Thread-safety">Thread safety</a>, plan <em>execution</em> is thread-safe, but plan
Chris@19 111 creation and destruction are <em>not</em>: you should create/destroy
Chris@19 112 plans only from a single thread, but can safely execute multiple plans
Chris@19 113 in parallel.
Chris@19 114
Chris@19 115 <p>There is one additional routine: if you want to get rid of all memory
Chris@19 116 and other resources allocated internally by FFTW, you can call:
Chris@19 117
Chris@19 118 <pre class="example"> void fftw_cleanup_threads(void);
Chris@19 119 </pre>
Chris@19 120 <p><a name="index-fftw_005fcleanup_005fthreads-341"></a>
Chris@19 121 which is much like the <code>fftw_cleanup()</code> function except that it
Chris@19 122 also gets rid of threads-related data. You must <em>not</em> execute any
Chris@19 123 previously created plans after calling this function.
Chris@19 124
Chris@19 125 <p>We should also mention one other restriction: if you save wisdom from a
Chris@19 126 program using the multi-threaded FFTW, that wisdom <em>cannot be used</em>
Chris@19 127 by a program using only the single-threaded FFTW (i.e. not calling
Chris@19 128 <code>fftw_init_threads</code>). See <a href="Words-of-Wisdom_002dSaving-Plans.html#Words-of-Wisdom_002dSaving-Plans">Words of Wisdom-Saving Plans</a>.
Chris@19 129
Chris@19 130 <!-- -->
Chris@19 131 </body></html>
Chris@19 132