Question

The docs for FFTW say that fftw_alloc() ensures proper memory alignment. Are there risks associated with using stack variables for the input/output of a given FFTW plan? Will FFTW just run slower, or will it not run at all?

e.g. Is the below C code not recommended?

int main()
{
   fftw_complex in[1024];
   fftw_complex out[1024];

   fftw_plan my_plan;

   my_plan = fftw_plan_dft_1d(1024, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

   fftw_execute(plan);
}

Was it helpful?

Solution

From the docs:

http://www.fftw.org/doc/SIMD-alignment-and-fftw_005fmalloc.html

A program linking to an FFTW library compiled with SIMD support can obtain a nonnegligible speedup for most complex and r2c/c2r transforms. In order to obtain this speedup, however, the arrays of complex (or real) data passed to FFTW must be specially aligned in memory (typically 16-byte aligned), and often this alignment is more stringent than that provided by the usual malloc (etc.) allocation routines.

In order to guarantee proper alignment for SIMD, therefore, in case your program is ever linked against a SIMD-using FFTW, we recommend allocating your transform data with fftw_malloc and de-allocating it with fftw_free. These have exactly the same interface and behavior as malloc/free, except that for a SIMD FFTW they ensure that the returned pointer has the necessary alignment (by calling memalign or its equivalent on your OS).

"Necessary"? No

"Well advised?" Yes - most definitely:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top