imkl-FFTW¶
![FFTW](images/logo-FFTW.gif)
![IMKL](images/logo-imkl.jpg)
Intel® oneAPI Math Kernel Library (oneMKL) offers FFTW2 and FFTW3 interfaces to Intel® oneAPI Math Kernel Library (oneMKL) Fast Fourier Transform and Trigonometric Transform functionality. The purpose of these interfaces is to enable applications using FFTW (www.fftw.org) to gain performance with Intel® oneAPI Math Kernel Library (oneMKL) without changing the program source code.
Both FFTW2 and FFTW3 interfaces are provided in open source as FFTW wrappers to Intel® oneAPI Math Kernel Library (oneMKL). For ease of use, FFTW3 interface is also integrated in Intel® oneAPI Math Kernel Library (oneMKL).
Usage¶
imkl-FFTW module¶
imkl-FFTW has to be loaded using Lmod prior to running it.
$ module load imkl-FFTW
spider
$ module spider imkl-FFTW
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
imkl-FFTW:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Description:
FFTW interfaces using Intel oneAPI Math Kernel Library
Versions:
imkl-FFTW/2021.4.0-iimpi-2021b
imkl-FFTW/2022.1.0-iimpi-2022a
imkl-FFTW/2022.2.1-iimpi-2022b
imkl-FFTW/2023.1.0-iimpi-2023a
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
For detailed information about a specific "imkl-FFTW" package (including how to load the modules) use the module's full name.
Note that names that have a trailing (E) are extensions provided by other modules.
For example:
$ module spider imkl-FFTW/2023.1.0-iimpi-2023a
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Software version¶
Here you can check the available versions for imkl-FFTW in the different clusters
imkl-FFTW/2021.4.0-iimpi-2021b
imkl-FFTW/2022.1.0-iimpi-2022a
imkl-FFTW/2021.4.0-iimpi-2021b
imkl-FFTW/2022.1.0-iimpi-2022a
imkl-FFTW/2021.4.0-iimpi-2021b
imkl-FFTW/2022.1.0-iimpi-2022a
imkl-FFTW/2022.2.1-iimpi-2022b
imkl-FFTW/2023.1.0-iimpi-2023a
How to use imkl-FFTW¶
In order to use it, you will need to compile your code against the mkl and FFTL libraries.
Let's see how to use it with an example, using the following code:
Example code using imkl-FFTW
#include <stdio.h>
#include <stdlib.h>
#include <mkl.h>
#include "mkl_dfti.h"
int main() {
MKL_LONG N = 8;
MKL_LONG status;
DFTI_DESCRIPTOR_HANDLE handle;
MKL_Complex16 *inout;
// Allocate memory for the input/output array
inout = (MKL_Complex16*)mkl_malloc(N * sizeof(MKL_Complex16), 64);
if (inout == NULL) {
printf("Error allocating memory\n");
return 1;
}
// Initialize the input array with some values
for (int i = 0; i < N; i++) {
inout[i].real = i;
inout[i].imag = 0.0;
}
// Create a descriptor for a double-precision complex 1D forward FFT
status = DftiCreateDescriptor(&handle, DFTI_DOUBLE, DFTI_COMPLEX, 1, N);
if (status != DFTI_NO_ERROR) {
printf("Error creating descriptor: %ld\n", status);
return 1;
}
// Commit the descriptor
status = DftiCommitDescriptor(handle);
if (status != DFTI_NO_ERROR) {
printf("Error committing descriptor: %ld\n", status);
return 1;
}
// Perform the FFT
status = DftiComputeForward(handle, inout);
if (status != DFTI_NO_ERROR) {
printf("Error computing forward FFT: %ld\n", status);
return 1;
}
// Print the results
printf("Results of FFT:\n");
for (int i = 0; i < N; i++) {
printf("out[%d] = (%f, %f)\n", i, inout[i].real, inout[i].imag);
}
// Free the descriptor
status = DftiFreeDescriptor(&handle);
if (status != DFTI_NO_ERROR) {
printf("Error freeing descriptor: %ld\n", status);
return 1;
}
// Free the allocated memory
mkl_free(inout);
return 0;
}
First, we load the module:
$ module load imkl-FFTW/2023.1.0-iimpi-2023a
To compile our code, we will use the following line:
$ icc -qmkl main.c -o example -I/scicomp/builds/Rocky/8.7/IceLake/software/imkl/2023.1.0/mkl/2023.1.0/include
Note
The example code requires to an include file from mkl. The path to the folder containing it must be specified by the -I
flag.
Once compiled, we can execute it using the following submission script:
Batch script for a parallel execution using FFTW
#!/bin/bash
#SBATCH --qos=regular
#SBATCH --job-name=IMKL_FFTW_JOB
#SBATCH --mem=20gb
#SBATCH --cpus-per-task=1
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=5
#SBATCH --output=%x-%j.out
#SBATCH --error=%x-%j.err
module load imkl-FFTW/2023.1.0-iimpi-2023a
mpirun -np 5 ./example
Where:
-np
: number of MPI tasks.