Copyright (C) 2000-2012 |
GNU Info (fftw.info)Thread safetyThread safety ============= Users writing multi-threaded programs must concern themselves with the "thread safety" 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 certain parts of FFTW use private global variables to share data between calls. In particular, the plan-creation functions share trigonometric tables and accumulated `wisdom'. (Users should note that these comments only apply to programs using shared-memory threads. 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.) The central restriction of FFTW is that it is not safe to create multiple plans in parallel. You must either create all of your plans from a single thread, or instead use a semaphore, mutex, or other mechanism to ensure that different threads don't attempt to create plans at the same time. The same restriction also holds for destruction of plans and importing/forgetting `wisdom'. Once created, a plan may safely be used in any thread. The actual transform routines in FFTW (`fftw_one', etcetera) are re-entrant and thread-safe, so it is fine to call them simultaneously from multiple threads. Another question arises, however--is it safe to use the *same plan* for multiple transforms in parallel? (It would be unsafe if, for example, the plan were modified in some way by the transform.) We address this question by defining an additional planner flag, `FFTW_THREADSAFE'. When included in the flags for any of the plan-creation routines, `FFTW_THREADSAFE' guarantees that the resulting plan will be read-only and safe to use in parallel by multiple threads. automatically generated by info2www version 1.2.2.9 |