cannam@95: <html lang="en">
cannam@95: <head>
cannam@95: <title>Thread safety - FFTW 3.3.3</title>
cannam@95: <meta http-equiv="Content-Type" content="text/html">
cannam@95: <meta name="description" content="FFTW 3.3.3">
cannam@95: <meta name="generator" content="makeinfo 4.13">
cannam@95: <link title="Top" rel="start" href="index.html#Top">
cannam@95: <link rel="up" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" title="Multi-threaded FFTW">
cannam@95: <link rel="prev" href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" title="How Many Threads to Use?">
cannam@95: <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
cannam@95: <!--
cannam@95: This manual is for FFTW
cannam@95: (version 3.3.3, 25 November 2012).
cannam@95: 
cannam@95: Copyright (C) 2003 Matteo Frigo.
cannam@95: 
cannam@95: Copyright (C) 2003 Massachusetts Institute of Technology.
cannam@95: 
cannam@95:      Permission is granted to make and distribute verbatim copies of
cannam@95:      this manual provided the copyright notice and this permission
cannam@95:      notice are preserved on all copies.
cannam@95: 
cannam@95:      Permission is granted to copy and distribute modified versions of
cannam@95:      this manual under the conditions for verbatim copying, provided
cannam@95:      that the entire resulting derived work is distributed under the
cannam@95:      terms of a permission notice identical to this one.
cannam@95: 
cannam@95:      Permission is granted to copy and distribute translations of this
cannam@95:      manual into another language, under the above conditions for
cannam@95:      modified versions, except that this permission notice may be
cannam@95:      stated in a translation approved by the Free Software Foundation.
cannam@95:    -->
cannam@95: <meta http-equiv="Content-Style-Type" content="text/css">
cannam@95: <style type="text/css"><!--
cannam@95:   pre.display { font-family:inherit }
cannam@95:   pre.format  { font-family:inherit }
cannam@95:   pre.smalldisplay { font-family:inherit; font-size:smaller }
cannam@95:   pre.smallformat  { font-family:inherit; font-size:smaller }
cannam@95:   pre.smallexample { font-size:smaller }
cannam@95:   pre.smalllisp    { font-size:smaller }
cannam@95:   span.sc    { font-variant:small-caps }
cannam@95:   span.roman { font-family:serif; font-weight:normal; } 
cannam@95:   span.sansserif { font-family:sans-serif; font-weight:normal; } 
cannam@95: --></style>
cannam@95: </head>
cannam@95: <body>
cannam@95: <div class="node">
cannam@95: <a name="Thread-safety"></a>
cannam@95: <p>
cannam@95: Previous:&nbsp;<a rel="previous" accesskey="p" href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f">How Many Threads to Use?</a>,
cannam@95: Up:&nbsp;<a rel="up" accesskey="u" href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW">Multi-threaded FFTW</a>
cannam@95: <hr>
cannam@95: </div>
cannam@95: 
cannam@95: <h3 class="section">5.4 Thread safety</h3>
cannam@95: 
cannam@95: <p><a name="index-threads-341"></a><a name="index-OpenMP-342"></a><a name="index-thread-safety-343"></a>Users writing multi-threaded programs (including OpenMP) must concern
cannam@95: themselves with the <dfn>thread safety</dfn> of the libraries they
cannam@95: use&mdash;that is, whether it is safe to call routines in parallel from
cannam@95: multiple threads.  FFTW can be used in such an environment, but some
cannam@95: care must be taken because the planner routines share data
cannam@95: (e.g. wisdom and trigonometric tables) between calls and plans.
cannam@95: 
cannam@95:    <p>The upshot is that the only thread-safe (re-entrant) routine in FFTW is
cannam@95: <code>fftw_execute</code> (and the new-array variants thereof).  All other routines
cannam@95: (e.g. the planner) should only be called from one thread at a time.  So,
cannam@95: for example, you can wrap a semaphore lock around any calls to the
cannam@95: planner; even more simply, you can just create all of your plans from
cannam@95: one thread.  We do not think this should be an important restriction
cannam@95: (FFTW is designed for the situation where the only performance-sensitive
cannam@95: code is the actual execution of the transform), and the benefits of
cannam@95: shared data between plans are great.
cannam@95: 
cannam@95:    <p>Note also that, since the plan is not modified by <code>fftw_execute</code>,
cannam@95: it is safe to execute the <em>same plan</em> in parallel by multiple
cannam@95: threads.  However, since a given plan operates by default on a fixed
cannam@95: array, you need to use one of the new-array execute functions (see <a href="New_002darray-Execute-Functions.html#New_002darray-Execute-Functions">New-array Execute Functions</a>) so that different threads compute the transform of different data.
cannam@95: 
cannam@95:    <p>(Users should note that these comments only apply to programs using
cannam@95: shared-memory threads or OpenMP.  Parallelism using MPI or forked processes
cannam@95: involves a separate address-space and global variables for each process,
cannam@95: and is not susceptible to problems of this sort.)
cannam@95: 
cannam@95:    <p>If you are configured FFTW with the <code>--enable-debug</code> or
cannam@95: <code>--enable-debug-malloc</code> flags (see <a href="Installation-on-Unix.html#Installation-on-Unix">Installation on Unix</a>),
cannam@95: then <code>fftw_execute</code> is not thread-safe.  These flags are not
cannam@95: documented because they are intended only for developing
cannam@95: and debugging FFTW, but if you must use <code>--enable-debug</code> then you
cannam@95: should also specifically pass <code>--disable-debug-malloc</code> for
cannam@95: <code>fftw_execute</code> to be thread-safe.
cannam@95: 
cannam@95:    </body></html>
cannam@95: