Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: FFTW 3.3.5: Usage of Multi-threaded FFTW Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42:
Chris@42:

Chris@42: Next: , Previous: , Up: Multi-threaded FFTW   [Contents][Index]

Chris@42:
Chris@42:
Chris@42: Chris@42:

5.2 Usage of Multi-threaded FFTW

Chris@42: Chris@42:

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

Chris@42: Chris@42:

First, programs using the parallel complex transforms should be linked Chris@42: with -lfftw3_threads -lfftw3 -lm on Unix, or -lfftw3_omp Chris@42: -lfftw3 -lm if you compiled with OpenMP. You will also need to link Chris@42: with whatever library is responsible for threads on your system Chris@42: (e.g. -lpthread on GNU/Linux) or include whatever compiler flag Chris@42: enables OpenMP (e.g. -fopenmp with gcc). Chris@42: Chris@42:

Chris@42: Chris@42:

Second, before calling any FFTW routines, you should call the Chris@42: function: Chris@42:

Chris@42:
Chris@42:
int fftw_init_threads(void);
Chris@42: 
Chris@42: Chris@42: Chris@42:

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

Chris@42:

Third, before creating a plan that you want to parallelize, you should Chris@42: call: Chris@42:

Chris@42:
Chris@42:
void fftw_plan_with_nthreads(int nthreads);
Chris@42: 
Chris@42: Chris@42: Chris@42:

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

Chris@42: Chris@42:

With OpenMP, to configure FFTW to use all of the currently running Chris@42: OpenMP threads (set by omp_set_num_threads(nthreads) or by the Chris@42: OMP_NUM_THREADS environment variable), you can do: Chris@42: fftw_plan_with_nthreads(omp_get_max_threads()). (The ‘omp_’ Chris@42: OpenMP functions are declared via #include <omp.h>.) Chris@42:

Chris@42: Chris@42:

Given a plan, you then execute it as usual with Chris@42: fftw_execute(plan), and the execution will use the number of Chris@42: threads specified when the plan was created. When done, you destroy Chris@42: it as usual with fftw_destroy_plan. As described in Chris@42: Thread safety, plan execution is thread-safe, but plan Chris@42: creation and destruction are not: you should create/destroy Chris@42: plans only from a single thread, but can safely execute multiple plans Chris@42: in parallel. Chris@42:

Chris@42:

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

Chris@42:
Chris@42:
void fftw_cleanup_threads(void);
Chris@42: 
Chris@42: Chris@42: Chris@42:

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

Chris@42:

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

Chris@42:
Chris@42:
Chris@42:

Chris@42: Next: , Previous: , Up: Multi-threaded FFTW   [Contents][Index]

Chris@42:
Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: