Chris@19: Chris@19: Chris@19: Thread safety - FFTW 3.3.4 Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19:
Chris@19: Chris@19:

Chris@19: Previous: How Many Threads to Use?, Chris@19: Up: Multi-threaded FFTW Chris@19:


Chris@19:
Chris@19: Chris@19:

5.4 Thread safety

Chris@19: Chris@19:

Users writing multi-threaded programs (including OpenMP) must concern Chris@19: themselves with the thread safety of the libraries they Chris@19: use—that is, whether it is safe to call routines in parallel from Chris@19: multiple threads. FFTW can be used in such an environment, but some Chris@19: care must be taken because the planner routines share data Chris@19: (e.g. wisdom and trigonometric tables) between calls and plans. Chris@19: Chris@19:

The upshot is that the only thread-safe (re-entrant) routine in FFTW is Chris@19: fftw_execute (and the new-array variants thereof). All other routines Chris@19: (e.g. the planner) should only be called from one thread at a time. So, Chris@19: for example, you can wrap a semaphore lock around any calls to the Chris@19: planner; even more simply, you can just create all of your plans from Chris@19: one thread. We do not think this should be an important restriction Chris@19: (FFTW is designed for the situation where the only performance-sensitive Chris@19: code is the actual execution of the transform), and the benefits of Chris@19: shared data between plans are great. Chris@19: Chris@19:

Note also that, since the plan is not modified by fftw_execute, Chris@19: it is safe to execute the same plan in parallel by multiple Chris@19: threads. However, since a given plan operates by default on a fixed Chris@19: 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@19: Chris@19:

(Users should note that these comments only apply to programs using Chris@19: shared-memory threads or OpenMP. Parallelism using MPI or forked processes Chris@19: involves a separate address-space and global variables for each process, Chris@19: and is not susceptible to problems of this sort.) Chris@19: Chris@19:

If you are configured FFTW with the --enable-debug or Chris@19: --enable-debug-malloc flags (see Installation on Unix), Chris@19: then fftw_execute is not thread-safe. These flags are not Chris@19: documented because they are intended only for developing Chris@19: and debugging FFTW, but if you must use --enable-debug then you Chris@19: should also specifically pass --disable-debug-malloc for Chris@19: fftw_execute to be thread-safe. Chris@19: Chris@19: Chris@19: