Developer Guide

Contents

Calling LAPACK, BLAS, and CBLAS Routines from C/C++ Language Environments

Not all
Intel® MKL
function domains support both C and Fortran environments. To use
Intel® MKL
Fortran-style functions in C/C++ environments, you should observe certain conventions, which are discussed for LAPACK and BLAS in the subsections below.
Avoid calling BLAS 95/LAPACK 95 from C/C++. Such calls require skills in manipulating the descriptor of a deferred-shape array, which is the Fortran 90 type. Moreover, BLAS95/LAPACK95 routines contain links to a Fortran RTL.

LAPACK and BLAS

Because LAPACK and BLAS routines are Fortran-style, when calling them from C-language programs, follow the Fortran-style calling conventions:
With row-major order, adopted in C, the last array index changes most quickly and the first one changes most slowly when traversing the memory segment where the array is stored. With Fortran-style column-major order, the last index changes most slowly whereas the first index changes most quickly (as illustrated by the figure below for a two-dimensional array).
For example, if a two-dimensional matrix A of size
m
x
n
is stored densely in a one-dimensional array B, you can access a matrix element like this:
A[i][j] = B[i*n+j]
in C          (
i=0, ... , m-1, j=0, ... , -1
)
A(i,j)  = B((j-1)*m+i)
in Fortran  (
i=1, ... , m, j=1, ... , n
).
When calling LAPACK or BLAS routines from C, be aware that because the Fortran language is case-insensitive, the routine names can be both upper-case or lower-case, with or without the trailing underscore. For example, the following names are equivalent:
  • LAPACK:
    dgetrf, DGETRF, dgetrf_
    , and
    DGETRF_
  • BLAS:
    dgemm, DGEMM, dgemm_
    , and
    DGEMM_
See Example "Calling a Complex BLAS Level 1 Function from C++" on how to call BLAS routines from C.
See also the
Intel® MKL
Developer Reference for a description of the C interface to LAPACK functions.

CBLAS

Instead of calling BLAS routines from a C-language program, you can use the CBLAS interface.
CBLAS is a C-style interface to the BLAS routines. You can call CBLAS routines using regular C-style calls. Use the
mkl.h
header file with the CBLAS interface. The header file specifies enumerated values and prototypes of all the functions. It also determines whether the program is being compiled with a C++ compiler, and if it is, the included file will be correct for use with C++ compilation. Example "Using CBLAS Interface Instead of Calling BLAS Directly from C" illustrates the use of the CBLAS interface.

C Interface to LAPACK

Instead of calling LAPACK routines from a C-language program, you can use the C interface to LAPACK provided by
Intel® MKL
.
The C interface to LAPACK is a C-style interface to the LAPACK routines. This interface supports matrices in row-major and column-major order, which you can define in the first function argument
matrix_order
. Use the
mkl.h
header file with the C interface to LAPACK.
mkl.h
includes the
mkl_lapacke.h
header file, which specifies constants and prototypes of all the functions. It also determines whether the program is being compiled with a C++ compiler, and if it is, the included file will be correct for use with C++ compilation. You can find examples of the C interface to LAPACK in the
examples
/
lapacke
subdirectory in the
Intel® MKL
installation directory.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804