Developer Guide

  • 2021.1
  • 12/04/2020
  • Public Content
Contents

Example of Data Alignment

Needs for best performance with
Intel® oneAPI Math Kernel Library
or for reproducible results from run to run of
Intel® oneAPI Math Kernel Library
functions require alignment of data arrays. The following example shows how to align an array on 64-byte boundaries. To do this, use
mkl_malloc()
in place of system provided memory allocators, as shown in the code example below.

Aligning Addresses on 64-byte Boundaries

// ******* C language ******* ... #include <stdlib.h> #include <mkl.h> ... void *darray; int workspace; // Set value of alignment int alignment=64; ... // Allocate aligned workspace darray = mkl_malloc( sizeof(double)*workspace, alignment ); ... // call the program using oneMKL mkl_app( darray ); ... // Free workspace mkl_free( darray );
! ******* Fortran language ******* ... ! Set value of alignment integer alignment parameter (alignment=64) ... ! Declare oneMKL routines #ifdef _IA32 integer mkl_malloc #else integer*8 mkl_malloc #endif external mkl_malloc, mkl_free, mkl_app ... double precision darray pointer (p_wrk,darray(1)) integer workspace ... ! Allocate aligned workspace p_wrk = mkl_malloc( %val(8*workspace), %val(alignment) ) ... ! call the program using oneMKL call mkl_app( darray ) ... ! Free workspace call mkl_free(p_wrk)

Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.