Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > f949c940bce372b03cb072dd0ee090a1 > files > 108

fftw-doc-3.3.3-5.fc18.noarch.rpm

<html lang="en">
<head>
<title>Usage of Multi-threaded FFTW - FFTW 3.3.3</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="FFTW 3.3.3">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" title="Multi-threaded FFTW">
<link rel="prev" href="Installation-and-Supported-Hardware_002fSoftware.html#Installation-and-Supported-Hardware_002fSoftware" title="Installation and Supported Hardware/Software">
<link rel="next" href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" title="How Many Threads to Use?">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
This manual is for FFTW
(version 3.3.3, 25 November 2012).

Copyright (C) 2003 Matteo Frigo.

Copyright (C) 2003 Massachusetts Institute of Technology.

     Permission is granted to make and distribute verbatim copies of
     this manual provided the copyright notice and this permission
     notice are preserved on all copies.

     Permission is granted to copy and distribute modified versions of
     this manual under the conditions for verbatim copying, provided
     that the entire resulting derived work is distributed under the
     terms of a permission notice identical to this one.

     Permission is granted to copy and distribute translations of this
     manual into another language, under the above conditions for
     modified versions, except that this permission notice may be
     stated in a translation approved by the Free Software Foundation.
   -->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Usage-of-Multi-threaded-FFTW"></a>
<a name="Usage-of-Multi_002dthreaded-FFTW"></a>
<p>
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>,
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>,
Up:&nbsp;<a rel="up" accesskey="u" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>
<hr>
</div>

<h3 class="section">5.2 Usage of Multi-threaded FFTW</h3>

<p>Here, it is assumed that the reader is already familiar with the usage
of the uniprocessor FFTW routines, described elsewhere in this manual. 
We only describe what one has to change in order to use the
multi-threaded routines.

   <p><a name="index-OpenMP-332"></a>First, programs using the parallel complex transforms should be linked
with <code>-lfftw3_threads -lfftw3 -lm</code> on Unix, or <code>-lfftw3_omp
-lfftw3 -lm</code> if you compiled with OpenMP. You will also need to link
with whatever library is responsible for threads on your system
(e.g. <code>-lpthread</code> on GNU/Linux) or include whatever compiler flag
enables OpenMP (e.g. <code>-fopenmp</code> with gcc). 
<a name="index-linking-on-Unix-333"></a>

   <p>Second, before calling <em>any</em> FFTW routines, you should call the
function:

<pre class="example">     int fftw_init_threads(void);
</pre>
   <p><a name="index-fftw_005finit_005fthreads-334"></a>
This function, which need only be called once, performs any one-time
initialization required to use threads on your system.  It returns zero
if there was some error (which should not happen under normal
circumstances) and a non-zero value otherwise.

   <p>Third, before creating a plan that you want to parallelize, you should
call:

<pre class="example">     void fftw_plan_with_nthreads(int nthreads);
</pre>
   <p><a name="index-fftw_005fplan_005fwith_005fnthreads-335"></a>
The <code>nthreads</code> argument indicates the number of threads you want
FFTW to use (or actually, the maximum number).  All plans subsequently
created with any planner routine will use that many threads.  You can
call <code>fftw_plan_with_nthreads</code>, create some plans, call
<code>fftw_plan_with_nthreads</code> again with a different argument, and
create some more plans for a new number of threads.  Plans already created
before a call to <code>fftw_plan_with_nthreads</code> are unaffected.  If you
pass an <code>nthreads</code> argument of <code>1</code> (the default), threads are
disabled for subsequent plans.

   <p><a name="index-OpenMP-336"></a>With OpenMP, to configure FFTW to use all of the currently running
OpenMP threads (set by <code>omp_set_num_threads(nthreads)</code> or by the
<code>OMP_NUM_THREADS</code> environment variable), you can do:
<code>fftw_plan_with_nthreads(omp_get_max_threads())</code>. (The &lsquo;<samp><span class="samp">omp_</span></samp>&rsquo;
OpenMP functions are declared via <code>#include &lt;omp.h&gt;</code>.)

   <p><a name="index-thread-safety-337"></a>Given a plan, you then execute it as usual with
<code>fftw_execute(plan)</code>, and the execution will use the number of
threads specified when the plan was created.  When done, you destroy
it as usual with <code>fftw_destroy_plan</code>.  As described in
<a href="Thread-safety.html#Thread-safety">Thread safety</a>, plan <em>execution</em> is thread-safe, but plan
creation and destruction are <em>not</em>: you should create/destroy
plans only from a single thread, but can safely execute multiple plans
in parallel.

   <p>There is one additional routine: if you want to get rid of all memory
and other resources allocated internally by FFTW, you can call:

<pre class="example">     void fftw_cleanup_threads(void);
</pre>
   <p><a name="index-fftw_005fcleanup_005fthreads-338"></a>
which is much like the <code>fftw_cleanup()</code> function except that it
also gets rid of threads-related data.  You must <em>not</em> execute any
previously created plans after calling this function.

   <p>We should also mention one other restriction: if you save wisdom from a
program using the multi-threaded FFTW, that wisdom <em>cannot be used</em>
by a program using only the single-threaded FFTW (i.e. not calling
<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>.

<!--  -->
   </body></html>