Intel® Math Kernel Library 2018 Developer Reference - C
This section presents examples of using the FFT interface functions described in “Fourier Transform Functions”.
Here are the examples of two one-dimensional computations. These examples use the default settings for all of the configuration parameters, which are specified in “Configuration Settings”.
/* C example, float _Complex is defined in C9X */ #include "mkl_dfti.h" float _Complex x[32]; float y[34]; DFTI_DESCRIPTOR_HANDLE my_desc1_handle; DFTI_DESCRIPTOR_HANDLE my_desc2_handle; MKL_LONG status; //...put input data into x[0],...,x[31]; y[0],...,y[31] status = DftiCreateDescriptor( &my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32); status = DftiCommitDescriptor( my_desc1_handle ); status = DftiComputeForward( my_desc1_handle, x); status = DftiFreeDescriptor(&my_desc1_handle); /* result is x[0], ..., x[31]*/ status = DftiCreateDescriptor( &my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 1, 32); status = DftiCommitDescriptor( my_desc2_handle); status = DftiComputeForward( my_desc2_handle, y); status = DftiFreeDescriptor(&my_desc2_handle); /* result is given in CCS format*/
/* C example, float _Complex is defined in C9X */ #include "mkl_dfti.h" float _Complex x_in[32]; float _Complex x_out[32]; float y_in[32]; float y_out[34]; DFTI_DESCRIPTOR_HANDLE my_desc1_handle; DFTI_DESCRIPTOR_HANDLE my_desc2_handle; MKL_LONG status; //...put input data into x_in[0],...,x_in[31]; y_in[0],...,y_in[31] status = DftiCreateDescriptor( &my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32); status = DftiSetValue( my_desc1_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE); status = DftiCommitDescriptor( my_desc1_handle ); status = DftiComputeForward( my_desc1_handle, x_in, x_out); status = DftiFreeDescriptor(&my_desc1_handle); /* result is x_out[0], ..., x_out[31]*/ status = DftiCreateDescriptor( &my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 1, 32); Status = DftiSetValue( My_Desc2_Handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE); status = DftiCommitDescriptor( my_desc2_handle); status = DftiComputeForward( my_desc2_handle, y_in, y_out); status = DftiFreeDescriptor(&my_desc2_handle); /* result is given by y_out in CCS format*/
/* C99 example */ #include "mkl_dfti.h" float _Complex x[32][100]; float y[34][102]; DFTI_DESCRIPTOR_HANDLE my_desc1_handle; DFTI_DESCRIPTOR_HANDLE my_desc2_handle; MKL_LONG status, l[2]; //...put input data into x[j][k] 0<=j<=31, 0<=k<=99 //...put input data into y[j][k] 0<=j<=31, 0<=k<=99 l[0] = 32; l[1] = 100; status = DftiCreateDescriptor( &my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 2, l); status = DftiCommitDescriptor( my_desc1_handle); status = DftiComputeForward( my_desc1_handle, x); status = DftiFreeDescriptor(&my_desc1_handle); /* result is the complex value x[j][k], 0<=j<=31, 0<=k<=99 */ status = DftiCreateDescriptor( &my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 2, l); status = DftiCommitDescriptor( my_desc2_handle); status = DftiComputeForward( my_desc2_handle, y); status = DftiFreeDescriptor(&my_desc2_handle); /* result is the complex value z(j,k) 0<=j<=31; 0<=k<=99 /* and is stored in CCS format*/
The following example demonstrates how you can change the default configuration settings by using the DftiSetValue function.
For instance, to preserve the input data after the FFT computation, the configuration of DFTI_PLACEMENT should be changed to "not in place" from the default choice of "in place."
The code below illustrates how this can be done:
/* C99 example */ #include "mkl_dfti.h" float _Complex x_in[32], x_out[32]; DFTI_DESCRIPTOR_HANDLE my_desc_handle; MKL_LONG status; //...put input data into x_in[j], 0 <= j < 32 status = DftiCreateDescriptor( &my_desc_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32); status = DftiSetValue( my_desc_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE); status = DftiCommitDescriptor( my_desc_handle); status = DftiComputeForward( my_desc_handle, x_in, x_out); status = DftiFreeDescriptor(&my_desc_handle); /* result is x_out[0], x_out[1], ..., x_out[31] */
This example illustrates the use of status checking functions described in “Fourier Transform Functions”.
/* C */ DFTI_DESCRIPTOR_HANDLE desc; MKL_LONG status; // . . . descriptor creation and other code status = DftiCommitDescriptor(desc); if (status && !DftiErrorClass(status,DFTI_NO_ERROR)) { printf ('Error: %s\n', DftiErrorMessage(status)); }
Below is an example where a 20-by-40 two-dimensional FFT is computed explicitly using one-dimensional transforms.
/* C */ #include "mkl_dfti.h" float _Complex x[20][40]; MKL_LONG stride[2]; MKL_LONG status; DFTI_DESCRIPTOR_HANDLE desc_handle_dim1; DFTI_DESCRIPTOR_HANDLE desc_handle_dim2; //... status = DftiCreateDescriptor( &desc_handle_dim1, DFTI_SINGLE, DFTI_COMPLEX, 1, 20 ); status = DftiCreateDescriptor( &desc_handle_dim2, DFTI_SINGLE, DFTI_COMPLEX, 1, 40 ); /* perform 40 one-dimensional transforms along 1st dimension */ /* note that the 1st dimension data are not unit-stride */ stride[0] = 0; stride[1] = 40; status = DftiSetValue( desc_handle_dim1, DFTI_NUMBER_OF_TRANSFORMS, 40 ); status = DftiSetValue( desc_handle_dim1, DFTI_INPUT_DISTANCE, 1 ); status = DftiSetValue( desc_handle_dim1, DFTI_OUTPUT_DISTANCE, 1 ); status = DftiSetValue( desc_handle_dim1, DFTI_INPUT_STRIDES, stride ); status = DftiSetValue( desc_handle_dim1, DFTI_OUTPUT_STRIDES, stride ); status = DftiCommitDescriptor( desc_handle_dim1 ); status = DftiComputeForward( desc_handle_dim1, x ); /* perform 20 one-dimensional transforms along 2nd dimension */ /* note that the 2nd dimension is unit stride */ status = DftiSetValue( desc_handle_dim2, DFTI_NUMBER_OF_TRANSFORMS, 20 ); status = DftiSetValue( desc_handle_dim2, DFTI_INPUT_DISTANCE, 40 ); status = DftiSetValue( desc_handle_dim2, DFTI_OUTPUT_DISTANCE, 40 ); status = DftiCommitDescriptor( desc_handle_dim2 ); status = DftiComputeForward( desc_handle_dim2, x ); status = DftiFreeDescriptor( &desc_handle_dim1 ); status = DftiFreeDescriptor( &desc_handle_dim2 );
The following code illustrates real multi-dimensional transforms with CCE format storage of conjugate-even complex matrix. Example “Three-Dimensional REAL FFT (C Interface)” is three-dimensional out-of-place transform in C interface.
/* C99 example */ #include "mkl_dfti.h" float x[32][100][19]; float _Complex y[32][100][10]; /* 10 = 19/2 + 1 */ DFTI_DESCRIPTOR_HANDLE my_desc_handle; MKL_LONG status, l[3]; MKL_LONG strides_out[4]; //...put input data into x[j][k][s] 0<=j<=31, 0<=k<=99, 0<=s<=18 l[0] = 32; l[1] = 100; l[2] = 19; strides_out[0] = 0; strides_out[1] = 1000; strides_out[2] = 10; strides_out[3] = 1; status = DftiCreateDescriptor( &my_desc_handle, DFTI_SINGLE, DFTI_REAL, 3, l ); status = DftiSetValue(my_desc_handle, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX); status = DftiSetValue( my_desc_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE ); status = DftiSetValue(my_desc_handle, DFTI_OUTPUT_STRIDES, strides_out); status = DftiCommitDescriptor(my_desc_handle); status = DftiComputeForward(my_desc_handle, x, y); status = DftiFreeDescriptor(&my_desc_handle); /* result is the complex value z(j,k,s) 0<=j<=31; 0<=k<=99, 0<=s<=9 and is stored in complex matrix y in CCE format. */