Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: FFTW 3.3.8: Usage of Multi-threaded FFTW Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: Chris@82:
Chris@82:

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

Chris@82:
Chris@82:
Chris@82: Chris@82:

5.2 Usage of Multi-threaded FFTW

Chris@82: Chris@82:

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

Chris@82: Chris@82:

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

Chris@82: Chris@82:

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

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

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

Chris@82:

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

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

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

Chris@82: Chris@82:

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

Chris@82: Chris@82:

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

Chris@82:

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

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

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

Chris@82:

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

Chris@82:
Chris@82:
Chris@82:

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

Chris@82:
Chris@82: Chris@82: Chris@82: Chris@82: Chris@82: