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