Developer Guide

Developer Guide for Intel® oneAPI Math Kernel Library Linux*

ID 766690
Date 3/31/2023

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

Document Table of Contents
Give Feedback

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, usemkl_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
            integer*8 mkl_malloc
            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)