Node:Static Arrays in C, Next:Dynamic Arrays in C, Previous:Column-major Format, Up:Multi-dimensional Array Format
Multi-dimensional arrays declared statically (that is, at compile time,
not necessarily with the static
keyword) in C are already
in row-major order. You don't have to do anything special to transform
them. For example:
{ fftw_complex data[NX][NY][NZ]; fftw_plan plan; ... plan = fftw_plan_dft_3d(NX, NY, NZ, &data[0][0][0], &data[0][0][0], FFTW_FORWARD, FFTW_ESTIMATE); ... }
This will plan a 3d in-place transform of size NX x NY x NZ
.
Notice how we took the address of the zero-th element to pass to the
planner (we could also have used a typecast).
However, we tend to discourage users from declaring their
arrays statically in this way, for two reasons. First, this allocates
the array on the stack, which has a very limited size on most
operating systems (declaring an array with more than a few thousand
elements will often cause a crash). Second, it may not optimally
align the array if you link with a SIMD FFTW (see SIMD alignment and fftw_malloc). Instead, we recommend using fftw_malloc
, as
described below.