Mercurial > hg > sv-dependency-builds
view src/fftw-3.3.5/doc/html/Thread-safety.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 |
line wrap: on
line source
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- This manual is for FFTW (version 3.3.5, 30 July 2016). 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. --> <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ --> <head> <title>FFTW 3.3.5: Thread safety</title> <meta name="description" content="FFTW 3.3.5: Thread safety"> <meta name="keywords" content="FFTW 3.3.5: Thread safety"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="index.html#Top" rel="start" title="Top"> <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" rel="up" title="Multi-threaded FFTW"> <link href="Distributed_002dmemory-FFTW-with-MPI.html#Distributed_002dmemory-FFTW-with-MPI" rel="next" title="Distributed-memory FFTW with MPI"> <link href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" rel="prev" title="How Many Threads to Use?"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.indentedblock {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smallindentedblock {margin-left: 3.2em; font-size: smaller} div.smalllisp {margin-left: 3.2em} kbd {font-style:oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nocodebreak {white-space:nowrap} span.nolinebreak {white-space:nowrap} span.roman {font-family:serif; font-weight:normal} span.sansserif {font-family:sans-serif; font-weight:normal} ul.no-bullet {list-style: none} --> </style> </head> <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> <a name="Thread-safety"></a> <div class="header"> <p> Previous: <a href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" accesskey="p" rel="prev">How Many Threads to Use?</a>, Up: <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" accesskey="u" rel="up">Multi-threaded FFTW</a> [<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> </div> <hr> <a name="Thread-safety-1"></a> <h3 class="section">5.4 Thread safety</h3> <a name="index-threads-1"></a> <a name="index-OpenMP-3"></a> <a name="index-thread-safety-1"></a> <p>Users writing multi-threaded programs (including OpenMP) must concern themselves with the <em>thread safety</em> of the libraries they use—that is, whether it is safe to call routines in parallel from multiple threads. FFTW can be used in such an environment, but some care must be taken because the planner routines share data (e.g. wisdom and trigonometric tables) between calls and plans. </p> <p>The upshot is that the only thread-safe (re-entrant) routine in FFTW is <code>fftw_execute</code> (and the new-array variants thereof). All other routines (e.g. the planner) should only be called from one thread at a time. So, for example, you can wrap a semaphore lock around any calls to the planner; even more simply, you can just create all of your plans from one thread. We do not think this should be an important restriction (FFTW is designed for the situation where the only performance-sensitive code is the actual execution of the transform), and the benefits of shared data between plans are great. </p> <p>Note also that, since the plan is not modified by <code>fftw_execute</code>, it is safe to execute the <em>same plan</em> in parallel by multiple threads. However, since a given plan operates by default on a fixed 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. </p> <p>(Users should note that these comments only apply to programs using shared-memory threads or OpenMP. Parallelism using MPI or forked processes involves a separate address-space and global variables for each process, and is not susceptible to problems of this sort.) </p> <p>If you are configured FFTW with the <code>--enable-debug</code> or <code>--enable-debug-malloc</code> flags (see <a href="Installation-on-Unix.html#Installation-on-Unix">Installation on Unix</a>), then <code>fftw_execute</code> is not thread-safe. These flags are not documented because they are intended only for developing and debugging FFTW, but if you must use <code>--enable-debug</code> then you should also specifically pass <code>--disable-debug-malloc</code> for <code>fftw_execute</code> to be thread-safe. </p> <p>Starting from FFTW-3.3.5, FFTW supports a new API to make the planner thread-safe: </p><div class="example"> <pre class="example">void fftw_make_planner_thread_safe(void); </pre></div> <a name="index-fftw_005fmake_005fplanner_005fthread_005fsafe"></a> <p>This call installs a hook that wraps a lock around all planner calls. This API is meant for “applications” that use “plugins” in multiple threads, where each “plugin” calls single-threaded FFTW but is unaware of the other “plugins” doing the same thing at the same time. In this case, the “application” calls <code>fftw_make_planner_thread_safe()</code> at the beginning to protect “plugins” from each other. </p><hr> <div class="header"> <p> Previous: <a href="How-Many-Threads-to-Use_003f.html#How-Many-Threads-to-Use_003f" accesskey="p" rel="prev">How Many Threads to Use?</a>, Up: <a href="Multi_002dthreaded-FFTW.html#Multi_002dthreaded-FFTW" accesskey="u" rel="up">Multi-threaded FFTW</a> [<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> </div> </body> </html>