d@0: d@0: d@0: Usage of Multi-threaded FFTW - FFTW 3.2.1 d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0: d@0:
d@0:

d@0: d@0: d@0: Next: , d@0: Previous: Installation and Supported Hardware/Software, d@0: Up: Multi-threaded FFTW d@0:


d@0:
d@0: d@0:

5.2 Usage of Multi-threaded FFTW

d@0: d@0:

Here, it is assumed that the reader is already familiar with the usage d@0: of the uniprocessor FFTW routines, described elsewhere in this manual. d@0: We only describe what one has to change in order to use the d@0: multi-threaded routines. d@0: d@0:

First, programs using the parallel complex transforms should be linked with d@0: -lfftw3_threads -lfftw3 -lm on Unix. You will also need to link d@0: with whatever library is responsible for threads on your system d@0: (e.g. -lpthread on GNU/Linux). d@0: d@0: Second, before calling any FFTW routines, you should call the d@0: function: d@0: d@0:

     int fftw_init_threads(void);
d@0: 
d@0:

d@0: This function, which need only be called once, performs any one-time d@0: initialization required to use threads on your system. It returns zero d@0: if there was some error (which should not happen under normal d@0: circumstances) and a non-zero value otherwise. d@0: d@0:

Third, before creating a plan that you want to parallelize, you should d@0: call: d@0: d@0:

     void fftw_plan_with_nthreads(int nthreads);
d@0: 
d@0:

d@0: The nthreads argument indicates the number of threads you want d@0: FFTW to use (or actually, the maximum number). All plans subsequently d@0: created with any planner routine will use that many threads. You can d@0: call fftw_plan_with_nthreads, create some plans, call d@0: fftw_plan_with_nthreads again with a different argument, and d@0: create some more plans for a new number of threads. Plans already created d@0: before a call to fftw_plan_with_nthreads are unaffected. If you d@0: pass an nthreads argument of 1 (the default), threads are d@0: disabled for subsequent plans. d@0: d@0:

Given a plan, you then execute it as usual with d@0: fftw_execute(plan), and the execution will use the number of d@0: threads specified when the plan was created. When done, you destroy it d@0: as usual with fftw_destroy_plan. d@0: d@0:

There is one additional routine: if you want to get rid of all memory d@0: and other resources allocated internally by FFTW, you can call: d@0: d@0:

     void fftw_cleanup_threads(void);
d@0: 
d@0:

d@0: which is much like the fftw_cleanup() function except that it d@0: also gets rid of threads-related data. You must not execute any d@0: previously created plans after calling this function. d@0: d@0:

We should also mention one other restriction: if you save wisdom from a d@0: program using the multi-threaded FFTW, that wisdom cannot be used d@0: by a program using only the single-threaded FFTW (i.e. not calling d@0: fftw_init_threads). See Words of Wisdom-Saving Plans. d@0: d@0: d@0: d@0: