Intel MKL - shawfdong/hyades GitHub Wiki

Intel MKL (Math Kernel Library) includes highly vectorized and threaded Linear Algebra, Fast Fourier Transforms (FFT), Vector Math and Statistics functions. Cluster-based versions of LAPACK, FFT and sparse solver are also included to support MPI-based distributed memory computing[1].

Intel MKL has the following functional categories:

  • Linear algebra: including optimized BLAS, BLACS, LAPACK, ScaLAPACK, PBLAS, sparse BLAS, sparse solvers such as PARDISO, iterative sparse solvers, and Parallel Direct Sparse Solver for Clusters.
  • Fast Fourier Transforms: Multidimensional (up to 7D) FFTs, FFTW interfaces, Cluster FFT
  • Vector Mathematical Functions (VML)
  • Statistical Functions (VSL)
  • Data fitting
  • others: including Vector Random Number Generators, Poisson Solvers, Optimization Solvers
The Reference Manual contains detailed descriptions of the functions and interfaces for all library domains.

Table of Contents

Documentation

In addition, source codes and data files for Intel MKL examples are located at $MKLROOT/examples on Hyades. Note MKLROOT is an environment variable defined by the module intel_compilers, pointing to the root of the MKL installation.

Linking your application with Intel MKL

Linking examples

Intel MKL is a vast and complex library, with a bewildering array of components, interfaces and options; so linking with it can be tricky. There is a whole chapter in the User's Guide, Chapter 3: Linking Your Application with the Intel Math Kernel Library, that is devoted to this topic. That chapter should be consulted to learn the gory details of linking with Intel MKL. Here we list some basic linking examples.

The most common usage scenario is to link with sequential (serial) version of Intel MKL. For starters, you can use the following linking options:

-lmkl_intel_lp64 -lmkl_core -lmkl_sequential
which will use the LP64 interface (32-bit integer) and link with the dynamic libraries.

For example, to compile an example program for LAPACK by NAG and link with sequential version of Intel MKL:

$ ifort -o lapackpgm.x lapackpgm.f \
  -lmkl_intel_lp64 -lmkl_core -lmkl_sequential

A shortcut is to use the -mkl=sequential option for Intel compilers:

$ ifort -o lapackpgm.x lapackpgm.f -mkl=sequential

If you want to link with the static libraries, use:

-Wl,--start-group \
${MKLROOT}/lib/intel64/libmkl_intel_lp64.a \
${MKLROOT}/lib/intel64/libmkl_core.a \
${MKLROOT}/lib/intel64/libmkl_sequential.a \
-Wl,--end-group
or
-static \
-Wl,--start-group -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -Wl,--end-group
or
-static -mkl=sequential
Note the linker option --start-group archives --end-group causes the specified archives to be searched repeatedly until no new undefined references are created[2]. The option is necessary because there are circular references among the libraries.

To link dynamically with multi-threaded version of Intel MKL, use the following linking options:

-lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -openmp
or use Intel compilers option -mkl=parallel or -mkl.

To link statically, use:

-Wl,--start-group \
${MKLROOT}/lib/intel64/libmkl_intel_lp64.a \
${MKLROOT}/lib/intel64/libmkl_core.a \
${MKLROOT}/lib/intel64/libmkl_intel_thread.a \
-Wl,--end-group
-openmp
or use Intel compilers option -static -mkl=parallel or -static -mkl.

A quick way to link with the Intel MKL cluster components, like BLACS, CDFT (cluster FFT), ScaLAPACK, is to use Intel compilers option -mkl=cluster for Intel MPI. For example:

$ mpiifort -o mpipgm.x mpipgm.f -mkl=cluster

Intel MKL also provides another option for quick linking of your application: Single Dynamic Library (SDL). To use SDL, link with libmkl_rt.so (-lmkl_rt. For example:

$ ifort -o lapackpgm.x lapackpgm.f -lmkl_rt
SDL enables you to select the interface and threading library for Intel MKL at run time. By default, linking with SDL provides:
  • Intel LP64 interface on systems based on the Intel 64 architecture, like Hyades
  • Intel threading
To use other interfaces or change threading preferences, including use of the sequential version of Intel MKL, you need to specify your choices using functions or environment variables as explained in section Dynamically Selecting the Interface and Threading Layer of the User's Guide.

Here we only cover the basic scenario of linking with Intel MKL. For more complex scenarios, please use the online tool Intel MKL Link Line Advisor or the command-line tool mkl_link_tool to determine the libraries and options to specify on your link or compilation line.

Intel MKL Link Line Advisor

Intel MKL Link Line Advisor is an online tool. The tool requests information about your system and on how you intend to use Intel MKL (link dynamically or statically, use threaded or sequential mode, etc.). It then automatically generates the appropriate link line for your application.

Note The Link Line Advisor will suggest a link line like the following:
-L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -lpthread -lm
which is appropriate to be included in a Makefile[3]. However, when you use those options in a command line, you should replace all $(MKLROOT) with ${MKLROOT}, because $(MKLROOT) means command substitution in Bash[4] and Bash will try to execute MKLROOT as a command! And it is not necessary to specify the paths for MKL libraries and headers, because they are already in the default search paths on Hyades; so you can simply remove them from the command-line.

Command-line Link Tool

Using the command-line Link tool provided by Intel MKL can simplify building your application with Intel MKL. The tool not only provides the options, libraries, and environment variables to use, but also performs compilation and building of your application.

The tool mkl_link_tool is installed in the $MKLROOT/tools directory. To learn more about the tool, run:

$ $MKLROOT/tools/mkl_link_tool --help
or consult the knowledge base article on Intel MKL Command-line Link Tool.

References

  1. ^ Intel Math Kernel Library - Details
  2. ^ man ld
  3. ^ GNU make - Basics of Variable References
  4. ^ Bash - Shell expansion
⚠️ **GitHub.com Fallback** ⚠️