cannam@95: cannam@95: cannam@95: Thread safety - FFTW 3.3.3 cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95:
cannam@95: cannam@95:

cannam@95: Previous: How Many Threads to Use?, cannam@95: Up: Multi-threaded FFTW cannam@95:


cannam@95:
cannam@95: cannam@95:

5.4 Thread safety

cannam@95: cannam@95:

Users writing multi-threaded programs (including OpenMP) must concern cannam@95: themselves with the thread safety of the libraries they cannam@95: use—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:

The upshot is that the only thread-safe (re-entrant) routine in FFTW is cannam@95: fftw_execute (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:

Note also that, since the plan is not modified by fftw_execute, cannam@95: it is safe to execute the same plan 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 New-array Execute Functions) so that different threads compute the transform of different data. cannam@95: cannam@95:

(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:

If you are configured FFTW with the --enable-debug or cannam@95: --enable-debug-malloc flags (see Installation on Unix), cannam@95: then fftw_execute 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 --enable-debug then you cannam@95: should also specifically pass --disable-debug-malloc for cannam@95: fftw_execute to be thread-safe. cannam@95: cannam@95: cannam@95: