Using Intel® MKL with the NAG* libraries

 

Introduction

The Numerical Algorithms Group (NAG) provides mathematical and statistical software components used in many programs and applications in engineering, science, finance, and research. On Intel platforms (IA-32 and Intel® 64), NAG's numerical software libraries rely on the Intel® Math Kernel Library (Intel® MKL) for certain key building blocks to ensure the highest possible level of performance for Intel processors. Intel MKL is a library of highly optimized, extensively threaded math routines for science, engineering, and financial applications that require maximum performance. Core math functions include BLAS, LAPACK, ScaLAPACK, Sparse Solvers, Fast Fourier Transforms (FFTs), Vector Math, and more, offering performance optimizations for current and next-generation Intel® processors.

Currently, Intel MKL is used for NAG's BLAS and LAPACK functionalities, with the addition of FFTs for NAG's Fortran SMP Libraries.

Obtaining the software

For information on the latest version of the Intel® Math Kernel Library visit http://www.intel.com/software/products/mkl.

The following NAG* products are available on Intel processor-based systems:

  • IA-32 / Linux*: NAG Fortran Library (Mark 22), NAG Fortran SMP Library (Mark 20), NAG C Library (Mark 8)
  • IA-32 / Windows*: NAG Fortran Library (Mark 22), NAG Fortran SMP Library (Release 1.1), NAG C Library (Mark 8)
  • Intel® 64 / 64-bit Linux*: NAG Fortran Library (Mark 22), NAG Fortran SMP Library (Mark 21)
  • Intel® 64 / 64-bit Windows*: NAG Fortran Library (Mark 21)
  • IA-64 / 64-bit Linux*: NAG Fortran Library (Mark 21), NAG Fortran SMP Library (Mark 21), NAG C Library (Mark 8)
  • IA-64 / 64-bit Windows*: NAG Fortran Library (Mark 20)

A worked example: linking Intel® MKL with the NAG* Fortran Library (Mark 22) for Intel® 64 on Linux*

Linux* 64-bit (Intel® 64), Intel® Fortran, Double Precision Installer's Note

Fortran compiler: Intel® Fortran compiler for Intel® 64-based applications version 10.1.017 and compatible (additional tested versions: 11.0.069 and 11.0.074).

Vendor library: Intel MKL version 10.1.1.019 (10.1 Update 1) and compatible.

The following sections are extracted from the NAG* Fortran Library, Mark 22 Users' Note for  Intel® 64, Linux* 64-bit, Intel Fortran, Double Precision section 3. Please refer to the above NAG Users' Note for the details: http://www.nag.com/doc/inun/fl22/l6idcl/un.html

  1. Libraries NOT in the linker search path: In this section we assume that the library has been installed in the directory [INSTALL_DIR].

By default [INSTALL_DIR] is /opt/NAG/fll6i22dcl or /usr/local/NAG/fll6i22dcl depending on your system, though it could have been changed by the installer (see Installer's Note (in.html)). To identify [INSTALL_DIR] consider the following:

  • if /opt/NAG/fll6i22dcl exists, then this is [INSTALL_DIR]
  • if /usr/local/NAG/fll6i22dcl exists, then this is [INSTALL_DIR]
  • consult the installer for the directory [INSTALL_DIR].

To use the NAG Fortran Library and the supplied Intel MKL libraries, you may link in the following manner:

ifort driver.f [INSTALL_DIR]/lib/libnag_mkl.a \
-Wl,--start-group $[INSTALL_DIR]/mkl_em64t/libmkl_intel_lp64.a \
$[INSTALL_DIR]/mkl_em64t/libmkl_intel_thread.a \
$[INSTALL_DIR]/mkl_em64t/libmkl_core.a -Wl,--end-group -lguide -lpthread

where driver.f is your application program; or:

ifort driver.f [INSTALL_DIR]/lib/libnag_mkl.so -L[INSTALL_DIR]/mkl_em64t \
-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_lapack -lmkl -lmkl_core \
-lguide -lpthread

if the shareable library is required.

We recommend the use of the NAG Library with Intel MKL for optimum performance. However, if you prefer to link to a version of the NAG Library which does not require the use of Intel MKL you may wish to use the self-contained libraries as follows:

ifort driver.f [INSTALL_DIR]/lib/libnag_nag.a -lpthread or ifort driver.f [INSTALL_DIR]/lib/libnag_nag.so -lpthread

if the shareable library is required.

If your application has been linked with the shareable NAG and Intel MKL libraries then the environment variable LD_LIBRARY_PATH must be set (or extended) to allow run time linkage.

In the C shell type:

setenv LD_LIBRARY_PATH [INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t

to set LD_LIBRARY_PATH, or

setenv LD_LIBRARY_PATH [INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t:${LD_LIBRARY_PATH}

to extend LD_LIBRARY_PATH if you already have it set.

In the Bourne shell, type:

LD_LIBRARY_PATH=[INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t
export LD_LIBRARY_PATH

to set LD_LIBRARY_PATH, or

LD_LIBRARY_PATH=[INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

to extend LD_LIBRARY_PATH if you already have it set.

Note that you may also need to set LD_LIBRARY_PATH to point at other things such as compiler run-time libraries, for example if you are using a newer version of the compiler.

  1. Libraries in the linker search path

In this section we assume that the compiled libraries and the supplied Intel MKL libraries are pointed at by symbolic links from a directory in the search path of the linker, such as /usr/lib or /usr/lib64.

To use the NAG Fortran Library and the supplied Intel MKL libraries, you may link in the following manner:

ifort driver.f -lnag_mkl -lmkl_intel_lp64 -lmkl_intel_thread \
-lmkl_lapack -lmkl -lmkl_core -lguide -lpthread

To use the static library libnag_mkl.a you need the -Bstatic compiler flag to switch static binding on and -Bdynamic to switch dynamic binding on:

ifort -Bstatic driver.f -lnag_mkl -Wl,--start-group -lmkl_intel_lp64 \
-lmkl_intel_thread -lmkl_core -Wl,--end-group -Bdynamic -lguide -lpthread

We recommend the use of the NAG Library with Intel MKL for optimum performance. However, if you prefer to link to a version of the NAG library which does not require the use of Intel MKL you may wish to use the self-contained libraries as follows:

ifort driver.f -lnag_nag -lpthread

This will usually link to the shareable library in preference to the static library if both the libraries are at the same location.

To use the static library libnag_nag.a you need the -Bstatic compiler flag:

ifort -Bstatic driver.f -lnag_nag -Bdynamic -lpthread

If your application has been linked with the shareable NAG and Intel MKL libraries then the environment variable LD_LIBRARY_PATH must be set (or extended) to allow run time linkage.

In the C shell type:

setenv LD_LIBRARY_PATH [INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t

to set LD_LIBRARY_PATH, or

setenv LD_LIBRARY_PATH [INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t:${LD_LIBRARY_PATH}

to extend LD_LIBRARY_PATH if you already have it set.

In the Bourne shell, type:

LD_LIBRARY_PATH=[INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t
export LD_LIBRARY_PATH

to set LD_LIBRARY_PATH, or

LD_LIBRARY_PATH=[INSTALL_DIR]/lib:[INSTALL_DIR]/mkl_em64t:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

to extend LD_LIBRARY_PATH if you already have it set.

Note that you may also need to set LD_LIBRARY_PATH to point at other things as well, such as compiler run-time libraries, for example if you are using a newer version of the compiler.

Upgrading Intel® MKL for NAG Fortran Library Mark 22 on Intel® 64 with 64-bit Linux*

To get the very best performance on the latest version Intel® processors, it is advised that the very latest version of Intel® MKL be used whenever possible. All NAG products that ship with Intel MKL 10.0 or later can be upgraded to the latest version of Intel MKL. NAG products that ship with earlier versions of Intel MKL (e.g., Intel MKL 8.0) are not compatible with version 10.0 or later and therefore can not be upgraded.

As an example, the LAPACK routines DGESVD, DGESDD, and DSYEVR are up to 1.2x faster with Intel MKL 10.2 Update 2 than with Intel MKL 10.1 Update 1 (measured on the Intel® Xeon® 5600 series for 5000 x 5000 matrices).

We now detail the update process for the current 64-bit Linux* port of NAG's Fortran Library shipped for Intel® 64 architecture (the library is called FL6I22DCL and corresponds to NAG version Mark 22). The Library contains BLAS and LAPACK building blocks derived from Intel MKL 10.1 Update 1. To upgrade to Intel MKL 10.2 Update 2 you may do the following:

  • Backup the mkl_em64tdirectory that is found in the NAG installation directory
    • Example: rename /opt/NAG/fll6i22dcl/mkl_em64t to /opt/NAG/fll6i22dcl/backup.mkl_em64t
  • Create a symbolic link in your NAG installation directory called mkl_em64t that points to the lib/em64tsub-directory of your latest Intel MKL installation
    • Example: if the Intel MKL is installed under the default installation path /opt/intel/mkl/10.2.2.025, one would issue:

ln -fs /opt/intel/mkl/10.2.2.025/lib/em64t mkl_em64t

  • Set appropriate environment variables for dynamic libraries by doing one of the following:
    • update the environment variable LD_LIBRARY_PATH so that the path to the Intel MKL shared libraries is visible to the dynamic loader
    • source the relevant script provided by Intel MKL in /opt/intel/mkl/10.2.2.025/tools/environment/
    • Example using csh/tcsh:

source mklvarsemt64.csh

  • Example using sh:

source mklvarsemt64.sh

Intel continues to work with NAG to include new domains from the latest version of Intel MKL, to ensure these optimizations automatically benefit NAG's customers running on Intel architectures.

NOTE: Such an upgrade may not be consistent with the list of Intel MKL versions that have been tested by NAG for their product. For a list of versions of Intel MKL tested by NAG, please refer to NAG's installation manual, alternatively please refer to the paragraph "NAG's platform-specific installation notes" below. All versions of Intel MKL 10.0 or later can be linked along with NAG libraries, but there might be small numerical differences. Therefore, as a user upgrades to a later version of Intel MKL that has not been officially tested by NAG, it is the user's responsibility to check whether such differences are acceptable for his purposes.

Documentation

Index to documentation on Intel MKL: /en-us/

NAG's platform-specific installation notes for deploying NAG Libraries with the Intel MKL

(For the User's Notes please replace the "in.html" endings with "un.html")

Intel, the Intel logo, Itanium, Pentium, Intel Xeon, Intel Core, Intel MKL and VTune are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* names and brands may be claimed as the property of others.

 

Optimization Notice

The Intel® Math Kernel Library (Intel® MKL) contains functions that are more highly optimized for Intel microprocessors than for other microprocessors. While the functions in Intel® MKL offer optimizations for both Intel and Intel-compatible microprocessors, depending on your code and other factors, you will likely get extra performance on Intel microprocessors.

While the paragraph above describes the basic optimization approach for Intel® MKL as a whole, the library may or may not be optimized to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include Intel® Streaming SIMD Extensions 2 (Intel® SSE2), Intel® Streaming SIMD Extensions 3 (Intel® SSE3), and Supplemental Streaming SIMD Extensions 3 (Intel® 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.

Intel recommends that you evaluate other library products to determine which best meets your requirements.

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.