Developer Reference for Intel® oneAPI Math Kernel Library for Fortran

ID 766686
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Examples for Cluster FFT Functions

2D Out-of-place Cluster FFT Computation

The following C example computes a 2-dimensional out-of-place FFT using the cluster FFT interface:

/* C99 example */
#include "mpi.h"
#include "mkl_cdft.h"

DFTI_DESCRIPTOR_DM_HANDLE desc = NULL;
MKL_LONG v, i, j, n, s;
Complex *in, *out;
MKL_LONG dim_sizes[2] = {nx, ny};

MPI_Init(...);

/* Create descriptor for 2D FFT */
DftiCreateDescriptorDM(MPI_COMM_WORLD,
                       &desc, DFTI_DOUBLE, DFTI_COMPLEX, 2, dim_sizes);
/* Ask necessary length of in and out arrays and allocate memory */
DftiGetValueDM(desc,CDFT_LOCAL_SIZE,&v);
in = (Complex*) malloc(v*sizeof(Complex));
out = (Complex*) malloc(v*sizeof(Complex));
/* Fill local array with initial data. Current process performs n rows,
   0 row of in corresponds to s row of virtual global array */
DftiGetValueDM(desc, CDFT_LOCAL_NX, &n);
DftiGetValueDM(desc, CDFT_LOCAL_X_START, &s);
/* Virtual global array globalIN is defined by function f as
   globalIN[i*ny+j]=f(i,j) */
for(i = 0; i < n; ++i)
   for(j = 0; j < ny; ++j) in[i*ny+j] = f(i+s,j);
/* Set that we want out-of-place transform (default is DFTI_INPLACE) */
DftiSetValueDM(desc, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
/* Commit descriptor, calculate FFT, free descriptor */
DftiCommitDescriptorDM(desc);
DftiComputeForwardDM(desc, in, out);
/* Virtual global array globalOUT is defined by function g as
   globalOUT[i*ny+j]=g(i,j)   Now out contains result of FFT. out[i*ny+j]=g(i+s,j) */
DftiFreeDescriptorDM(&desc);
free(in);
free(out);
MPI_Finalize();
 

1D In-place Cluster FFT Computations

The C example below illustrates one-dimensional in-place cluster FFT computations effected with a user-defined workspace:

/* C99 example */
#include "mpi.h"
#include "mkl_cdft.h"

DFTI_DESCRIPTOR_DM_HANDLE desc = NULL;
MKL_LONG N, v, i, n_out, s_out;
Complex *in, *work;

MPI_Init(...);
/* Create descriptor for 1D FFT */
DftiCreateDescriptorDM(MPI_COMM_WORLD, &desc, DFTI_DOUBLE, DFTI_COMPLEX, 1, N);
/* Ask necessary length of array and workspace and allocate memory */
DftiGetValueDM(desc,CDFT_LOCAL_SIZE,&v);
in = (Complex*) malloc(v*sizeof(Complex));
work = (Complex*) malloc(v*sizeof(Complex));
/* Fill local array with initial data. Local array has n elements,
   0 element of in corresponds to s element of virtual global array */
DftiGetValueDM(desc, CDFT_LOCAL_NX, &n);
DftiGetValueDM(desc, CDFT_LOCAL_X_START, &s);
/* Set work array as a workspace */
DftiSetValueDM(desc, CDFT_WORKSPACE, work);
/* Virtual global array globalIN is defined by function f as globalIN[i]=f(i) */
for(i = 0; i < n; ++i) in[i] = f(i+s);
/* Commit descriptor, calculate FFT, free descriptor */
DftiCommitDescriptorDM(desc);
DftiComputeForwardDM(desc,in);
DftiGetValueDM(desc, CDFT_LOCAL_OUT_NX, &n_out);
DftiGetValueDM(desc, CDFT_LOCAL_OUT_X_START, &s_out);
/* Virtual global array globalOUT is defined by function g as globalOUT[i]=g(i)
   Now in contains result of FFT. Local array has n_out elements,
   0 element of in corresponds to s_out element of virtual global array.
   in[i]==g(i+s_out) */
DftiFreeDescriptorDM(&desc);
free(in);
free(work);
MPI_Finalize();