annotate src/fftw-3.3.5/doc/html/Usage-of-Multi_002dthreaded-FFTW.html @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 7867fa7e1b6b
children
rev   line source
cannam@127 1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
cannam@127 2 <html>
cannam@127 3 <!-- This manual is for FFTW
cannam@127 4 (version 3.3.5, 30 July 2016).
cannam@127 5
cannam@127 6 Copyright (C) 2003 Matteo Frigo.
cannam@127 7
cannam@127 8 Copyright (C) 2003 Massachusetts Institute of Technology.
cannam@127 9
cannam@127 10 Permission is granted to make and distribute verbatim copies of this
cannam@127 11 manual provided the copyright notice and this permission notice are
cannam@127 12 preserved on all copies.
cannam@127 13
cannam@127 14 Permission is granted to copy and distribute modified versions of this
cannam@127 15 manual under the conditions for verbatim copying, provided that the
cannam@127 16 entire resulting derived work is distributed under the terms of a
cannam@127 17 permission notice identical to this one.
cannam@127 18
cannam@127 19 Permission is granted to copy and distribute translations of this manual
cannam@127 20 into another language, under the above conditions for modified versions,
cannam@127 21 except that this permission notice may be stated in a translation
cannam@127 22 approved by the Free Software Foundation. -->
cannam@127 23 <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
cannam@127 24 <head>
cannam@127 25 <title>FFTW 3.3.5: Usage of Multi-threaded FFTW</title>
cannam@127 26
cannam@127 27 <meta name="description" content="FFTW 3.3.5: Usage of Multi-threaded FFTW">
cannam@127 28 <meta name="keywords" content="FFTW 3.3.5: Usage of Multi-threaded FFTW">
cannam@127 29 <meta name="resource-type" content="document">
cannam@127 30 <meta name="distribution" content="global">
cannam@127 31 <meta name="Generator" content="makeinfo">
cannam@127 32 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
cannam@127 33 <link href="index.html#Top" rel="start" title="Top">
cannam@127 34 <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
cannam@127 35 <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
cannam@127 36 <link href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" rel="up" title="Multi-threaded FFTW">
cannam@127 37 <link href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" rel="next" title="How Many Threads to Use?">
cannam@127 38 <link href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" rel="prev" title="Installation and Supported Hardware/Software">
cannam@127 39 <style type="text/css">
cannam@127 40 <!--
cannam@127 41 a.summary-letter {text-decoration: none}
cannam@127 42 blockquote.smallquotation {font-size: smaller}
cannam@127 43 div.display {margin-left: 3.2em}
cannam@127 44 div.example {margin-left: 3.2em}
cannam@127 45 div.indentedblock {margin-left: 3.2em}
cannam@127 46 div.lisp {margin-left: 3.2em}
cannam@127 47 div.smalldisplay {margin-left: 3.2em}
cannam@127 48 div.smallexample {margin-left: 3.2em}
cannam@127 49 div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
cannam@127 50 div.smalllisp {margin-left: 3.2em}
cannam@127 51 kbd {font-style:oblique}
cannam@127 52 pre.display {font-family: inherit}
cannam@127 53 pre.format {font-family: inherit}
cannam@127 54 pre.menu-comment {font-family: serif}
cannam@127 55 pre.menu-preformatted {font-family: serif}
cannam@127 56 pre.smalldisplay {font-family: inherit; font-size: smaller}
cannam@127 57 pre.smallexample {font-size: smaller}
cannam@127 58 pre.smallformat {font-family: inherit; font-size: smaller}
cannam@127 59 pre.smalllisp {font-size: smaller}
cannam@127 60 span.nocodebreak {white-space:nowrap}
cannam@127 61 span.nolinebreak {white-space:nowrap}
cannam@127 62 span.roman {font-family:serif; font-weight:normal}
cannam@127 63 span.sansserif {font-family:sans-serif; font-weight:normal}
cannam@127 64 ul.no-bullet {list-style: none}
cannam@127 65 -->
cannam@127 66 </style>
cannam@127 67
cannam@127 68
cannam@127 69 </head>
cannam@127 70
cannam@127 71 <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
cannam@127 72 <a name="Usage-of-Multi_002dthreaded-FFTW"></a>
cannam@127 73 <div class="header">
cannam@127 74 <p>
cannam@127 75 Next: <a href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" accesskey="n" rel="next">How Many Threads to Use?</a>, Previous: <a href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" accesskey="p" rel="prev">Installation and Supported Hardware/Software</a>, Up: <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" accesskey="u" rel="up">Multi-threaded FFTW</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
cannam@127 76 </div>
cannam@127 77 <hr>
cannam@127 78 <a name="Usage-of-Multi_002dthreaded-FFTW-1"></a>
cannam@127 79 <h3 class="section">5.2 Usage of Multi-threaded FFTW</h3>
cannam@127 80
cannam@127 81 <p>Here, it is assumed that the reader is already familiar with the usage
cannam@127 82 of the uniprocessor FFTW routines, described elsewhere in this manual.
cannam@127 83 We only describe what one has to change in order to use the
cannam@127 84 multi-threaded routines.
cannam@127 85 </p>
cannam@127 86 <a name="index-OpenMP-1"></a>
cannam@127 87 <p>First, programs using the parallel complex transforms should be linked
cannam@127 88 with <code>-lfftw3_threads -lfftw3 -lm</code> on Unix, or <code>-lfftw3_omp
cannam@127 89 -lfftw3 -lm</code> if you compiled with OpenMP. You will also need to link
cannam@127 90 with whatever library is responsible for threads on your system
cannam@127 91 (e.g. <code>-lpthread</code> on GNU/Linux) or include whatever compiler flag
cannam@127 92 enables OpenMP (e.g. <code>-fopenmp</code> with gcc).
cannam@127 93 <a name="index-linking-on-Unix"></a>
cannam@127 94 </p>
cannam@127 95
cannam@127 96 <p>Second, before calling <em>any</em> FFTW routines, you should call the
cannam@127 97 function:
cannam@127 98 </p>
cannam@127 99 <div class="example">
cannam@127 100 <pre class="example">int fftw_init_threads(void);
cannam@127 101 </pre></div>
cannam@127 102 <a name="index-fftw_005finit_005fthreads"></a>
cannam@127 103
cannam@127 104 <p>This function, which need only be called once, performs any one-time
cannam@127 105 initialization required to use threads on your system. It returns zero
cannam@127 106 if there was some error (which should not happen under normal
cannam@127 107 circumstances) and a non-zero value otherwise.
cannam@127 108 </p>
cannam@127 109 <p>Third, before creating a plan that you want to parallelize, you should
cannam@127 110 call:
cannam@127 111 </p>
cannam@127 112 <div class="example">
cannam@127 113 <pre class="example">void fftw_plan_with_nthreads(int nthreads);
cannam@127 114 </pre></div>
cannam@127 115 <a name="index-fftw_005fplan_005fwith_005fnthreads"></a>
cannam@127 116
cannam@127 117 <p>The <code>nthreads</code> argument indicates the number of threads you want
cannam@127 118 FFTW to use (or actually, the maximum number). All plans subsequently
cannam@127 119 created with any planner routine will use that many threads. You can
cannam@127 120 call <code>fftw_plan_with_nthreads</code>, create some plans, call
cannam@127 121 <code>fftw_plan_with_nthreads</code> again with a different argument, and
cannam@127 122 create some more plans for a new number of threads. Plans already created
cannam@127 123 before a call to <code>fftw_plan_with_nthreads</code> are unaffected. If you
cannam@127 124 pass an <code>nthreads</code> argument of <code>1</code> (the default), threads are
cannam@127 125 disabled for subsequent plans.
cannam@127 126 </p>
cannam@127 127 <a name="index-OpenMP-2"></a>
cannam@127 128 <p>With OpenMP, to configure FFTW to use all of the currently running
cannam@127 129 OpenMP threads (set by <code>omp_set_num_threads(nthreads)</code> or by the
cannam@127 130 <code>OMP_NUM_THREADS</code> environment variable), you can do:
cannam@127 131 <code>fftw_plan_with_nthreads(omp_get_max_threads())</code>. (The &lsquo;<samp>omp_</samp>&rsquo;
cannam@127 132 OpenMP functions are declared via <code>#include &lt;omp.h&gt;</code>.)
cannam@127 133 </p>
cannam@127 134 <a name="index-thread-safety"></a>
cannam@127 135 <p>Given a plan, you then execute it as usual with
cannam@127 136 <code>fftw_execute(plan)</code>, and the execution will use the number of
cannam@127 137 threads specified when the plan was created. When done, you destroy
cannam@127 138 it as usual with <code>fftw_destroy_plan</code>. As described in
cannam@127 139 <a href="Thread-safety.html#Thread-safety">Thread safety</a>, plan <em>execution</em> is thread-safe, but plan
cannam@127 140 creation and destruction are <em>not</em>: you should create/destroy
cannam@127 141 plans only from a single thread, but can safely execute multiple plans
cannam@127 142 in parallel.
cannam@127 143 </p>
cannam@127 144 <p>There is one additional routine: if you want to get rid of all memory
cannam@127 145 and other resources allocated internally by FFTW, you can call:
cannam@127 146 </p>
cannam@127 147 <div class="example">
cannam@127 148 <pre class="example">void fftw_cleanup_threads(void);
cannam@127 149 </pre></div>
cannam@127 150 <a name="index-fftw_005fcleanup_005fthreads"></a>
cannam@127 151
cannam@127 152 <p>which is much like the <code>fftw_cleanup()</code> function except that it
cannam@127 153 also gets rid of threads-related data. You must <em>not</em> execute any
cannam@127 154 previously created plans after calling this function.
cannam@127 155 </p>
cannam@127 156 <p>We should also mention one other restriction: if you save wisdom from a
cannam@127 157 program using the multi-threaded FFTW, that wisdom <em>cannot be used</em>
cannam@127 158 by a program using only the single-threaded FFTW (i.e. not calling
cannam@127 159 <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@127 160 </p>
cannam@127 161 <hr>
cannam@127 162 <div class="header">
cannam@127 163 <p>
cannam@127 164 Next: <a href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" accesskey="n" rel="next">How Many Threads to Use?</a>, Previous: <a href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" accesskey="p" rel="prev">Installation and Supported Hardware/Software</a>, Up: <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" accesskey="u" rel="up">Multi-threaded FFTW</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
cannam@127 165 </div>
cannam@127 166
cannam@127 167
cannam@127 168
cannam@127 169 </body>
cannam@127 170 </html>