Chris@10: Chris@10:
Chris@10:Chris@10: Previous: How Many Threads to Use?, Chris@10: Up: Multi-threaded FFTW Chris@10:
Users writing multi-threaded programs (including OpenMP) must concern Chris@10: themselves with the thread safety of the libraries they Chris@10: use—that is, whether it is safe to call routines in parallel from Chris@10: multiple threads. FFTW can be used in such an environment, but some Chris@10: care must be taken because the planner routines share data Chris@10: (e.g. wisdom and trigonometric tables) between calls and plans. Chris@10: Chris@10:
The upshot is that the only thread-safe (re-entrant) routine in FFTW is
Chris@10: fftw_execute
(and the new-array variants thereof). All other routines
Chris@10: (e.g. the planner) should only be called from one thread at a time. So,
Chris@10: for example, you can wrap a semaphore lock around any calls to the
Chris@10: planner; even more simply, you can just create all of your plans from
Chris@10: one thread. We do not think this should be an important restriction
Chris@10: (FFTW is designed for the situation where the only performance-sensitive
Chris@10: code is the actual execution of the transform), and the benefits of
Chris@10: shared data between plans are great.
Chris@10:
Chris@10:
Note also that, since the plan is not modified by fftw_execute
,
Chris@10: it is safe to execute the same plan in parallel by multiple
Chris@10: threads. However, since a given plan operates by default on a fixed
Chris@10: array, you need to use one of the new-array execute functions (see New-array Execute Functions) so that different threads compute the transform of different data.
Chris@10:
Chris@10:
(Users should note that these comments only apply to programs using Chris@10: shared-memory threads or OpenMP. Parallelism using MPI or forked processes Chris@10: involves a separate address-space and global variables for each process, Chris@10: and is not susceptible to problems of this sort.) Chris@10: Chris@10:
If you are configured FFTW with the --enable-debug
or
Chris@10: --enable-debug-malloc
flags (see Installation on Unix),
Chris@10: then fftw_execute
is not thread-safe. These flags are not
Chris@10: documented because they are intended only for developing
Chris@10: and debugging FFTW, but if you must use --enable-debug
then you
Chris@10: should also specifically pass --disable-debug-malloc
for
Chris@10: fftw_execute
to be thread-safe.
Chris@10:
Chris@10:
Chris@10: