annotate src/fftw-3.3.3/doc/html/Usage-of-Multi_002dthreaded-FFTW.html @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
rev   line source
Chris@10 1 <html lang="en">
Chris@10 2 <head>
Chris@10 3 <title>Usage of Multi-threaded FFTW - FFTW 3.3.3</title>
Chris@10 4 <meta http-equiv="Content-Type" content="text/html">
Chris@10 5 <meta name="description" content="FFTW 3.3.3">
Chris@10 6 <meta name="generator" content="makeinfo 4.13">
Chris@10 7 <link title="Top" rel="start" href="index.html#Top">
Chris@10 8 <link rel="up" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" title="Multi-threaded FFTW">
Chris@10 9 <link rel="prev" href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" title="Installation and Supported Hardware/Software">
Chris@10 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@10 11 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
Chris@10 12 <!--
Chris@10 13 This manual is for FFTW
Chris@10 14 (version 3.3.3, 25 November 2012).
Chris@10 15
Chris@10 16 Copyright (C) 2003 Matteo Frigo.
Chris@10 17
Chris@10 18 Copyright (C) 2003 Massachusetts Institute of Technology.
Chris@10 19
Chris@10 20 Permission is granted to make and distribute verbatim copies of
Chris@10 21 this manual provided the copyright notice and this permission
Chris@10 22 notice are preserved on all copies.
Chris@10 23
Chris@10 24 Permission is granted to copy and distribute modified versions of
Chris@10 25 this manual under the conditions for verbatim copying, provided
Chris@10 26 that the entire resulting derived work is distributed under the
Chris@10 27 terms of a permission notice identical to this one.
Chris@10 28
Chris@10 29 Permission is granted to copy and distribute translations of this
Chris@10 30 manual into another language, under the above conditions for
Chris@10 31 modified versions, except that this permission notice may be
Chris@10 32 stated in a translation approved by the Free Software Foundation.
Chris@10 33 -->
Chris@10 34 <meta http-equiv="Content-Style-Type" content="text/css">
Chris@10 35 <style type="text/css"><!--
Chris@10 36 pre.display { font-family:inherit }
Chris@10 37 pre.format { font-family:inherit }
Chris@10 38 pre.smalldisplay { font-family:inherit; font-size:smaller }
Chris@10 39 pre.smallformat { font-family:inherit; font-size:smaller }
Chris@10 40 pre.smallexample { font-size:smaller }
Chris@10 41 pre.smalllisp { font-size:smaller }
Chris@10 42 span.sc { font-variant:small-caps }
Chris@10 43 span.roman { font-family:serif; font-weight:normal; }
Chris@10 44 span.sansserif { font-family:sans-serif; font-weight:normal; }
Chris@10 45 --></style>
Chris@10 46 </head>
Chris@10 47 <body>
Chris@10 48 <div class="node">
Chris@10 49 <a name="Usage-of-Multi-threaded-FFTW"></a>
Chris@10 50 <a name="Usage-of-Multi_002dthreaded-FFTW"></a>
Chris@10 51 <p>
Chris@10 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@10 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@10 54 Up:&nbsp;<a rel="up" accesskey="u" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>
Chris@10 55 <hr>
Chris@10 56 </div>
Chris@10 57
Chris@10 58 <h3 class="section">5.2 Usage of Multi-threaded FFTW</h3>
Chris@10 59
Chris@10 60 <p>Here, it is assumed that the reader is already familiar with the usage
Chris@10 61 of the uniprocessor FFTW routines, described elsewhere in this manual.
Chris@10 62 We only describe what one has to change in order to use the
Chris@10 63 multi-threaded routines.
Chris@10 64
Chris@10 65 <p><a name="index-OpenMP-332"></a>First, programs using the parallel complex transforms should be linked
Chris@10 66 with <code>-lfftw3_threads -lfftw3 -lm</code> on Unix, or <code>-lfftw3_omp
Chris@10 67 -lfftw3 -lm</code> if you compiled with OpenMP. You will also need to link
Chris@10 68 with whatever library is responsible for threads on your system
Chris@10 69 (e.g. <code>-lpthread</code> on GNU/Linux) or include whatever compiler flag
Chris@10 70 enables OpenMP (e.g. <code>-fopenmp</code> with gcc).
Chris@10 71 <a name="index-linking-on-Unix-333"></a>
Chris@10 72
Chris@10 73 <p>Second, before calling <em>any</em> FFTW routines, you should call the
Chris@10 74 function:
Chris@10 75
Chris@10 76 <pre class="example"> int fftw_init_threads(void);
Chris@10 77 </pre>
Chris@10 78 <p><a name="index-fftw_005finit_005fthreads-334"></a>
Chris@10 79 This function, which need only be called once, performs any one-time
Chris@10 80 initialization required to use threads on your system. It returns zero
Chris@10 81 if there was some error (which should not happen under normal
Chris@10 82 circumstances) and a non-zero value otherwise.
Chris@10 83
Chris@10 84 <p>Third, before creating a plan that you want to parallelize, you should
Chris@10 85 call:
Chris@10 86
Chris@10 87 <pre class="example"> void fftw_plan_with_nthreads(int nthreads);
Chris@10 88 </pre>
Chris@10 89 <p><a name="index-fftw_005fplan_005fwith_005fnthreads-335"></a>
Chris@10 90 The <code>nthreads</code> argument indicates the number of threads you want
Chris@10 91 FFTW to use (or actually, the maximum number). All plans subsequently
Chris@10 92 created with any planner routine will use that many threads. You can
Chris@10 93 call <code>fftw_plan_with_nthreads</code>, create some plans, call
Chris@10 94 <code>fftw_plan_with_nthreads</code> again with a different argument, and
Chris@10 95 create some more plans for a new number of threads. Plans already created
Chris@10 96 before a call to <code>fftw_plan_with_nthreads</code> are unaffected. If you
Chris@10 97 pass an <code>nthreads</code> argument of <code>1</code> (the default), threads are
Chris@10 98 disabled for subsequent plans.
Chris@10 99
Chris@10 100 <p><a name="index-OpenMP-336"></a>With OpenMP, to configure FFTW to use all of the currently running
Chris@10 101 OpenMP threads (set by <code>omp_set_num_threads(nthreads)</code> or by the
Chris@10 102 <code>OMP_NUM_THREADS</code> environment variable), you can do:
Chris@10 103 <code>fftw_plan_with_nthreads(omp_get_max_threads())</code>. (The &lsquo;<samp><span class="samp">omp_</span></samp>&rsquo;
Chris@10 104 OpenMP functions are declared via <code>#include &lt;omp.h&gt;</code>.)
Chris@10 105
Chris@10 106 <p><a name="index-thread-safety-337"></a>Given a plan, you then execute it as usual with
Chris@10 107 <code>fftw_execute(plan)</code>, and the execution will use the number of
Chris@10 108 threads specified when the plan was created. When done, you destroy
Chris@10 109 it as usual with <code>fftw_destroy_plan</code>. As described in
Chris@10 110 <a href="Thread-safety.html#Thread-safety">Thread safety</a>, plan <em>execution</em> is thread-safe, but plan
Chris@10 111 creation and destruction are <em>not</em>: you should create/destroy
Chris@10 112 plans only from a single thread, but can safely execute multiple plans
Chris@10 113 in parallel.
Chris@10 114
Chris@10 115 <p>There is one additional routine: if you want to get rid of all memory
Chris@10 116 and other resources allocated internally by FFTW, you can call:
Chris@10 117
Chris@10 118 <pre class="example"> void fftw_cleanup_threads(void);
Chris@10 119 </pre>
Chris@10 120 <p><a name="index-fftw_005fcleanup_005fthreads-338"></a>
Chris@10 121 which is much like the <code>fftw_cleanup()</code> function except that it
Chris@10 122 also gets rid of threads-related data. You must <em>not</em> execute any
Chris@10 123 previously created plans after calling this function.
Chris@10 124
Chris@10 125 <p>We should also mention one other restriction: if you save wisdom from a
Chris@10 126 program using the multi-threaded FFTW, that wisdom <em>cannot be used</em>
Chris@10 127 by a program using only the single-threaded FFTW (i.e. not calling
Chris@10 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@10 129
Chris@10 130 <!-- -->
Chris@10 131 </body></html>
Chris@10 132