annotate src/fftw-3.3.3/doc/html/Usage-of-Multi_002dthreaded-FFTW.html @ 95:89f5e221ed7b

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