Development/MKL: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
 
(96 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{Softwarepage|numlib/mkl}}
== Introduction ==


{| width=600px class="wikitable"
== Modules Environment ==
|-
! Description !! Content
|-
| module load
| numlib/mkl
|-
| License
| Commercial. See [https://software.intel.com/en-us/articles/end-user-license-agreement EULA].
|-
| Citing
| n/a
|-
| Links
| [https://software.intel.com/en-us/intel-mkl Intel MKL Homepage] | [https://software.intel.com/en-us/articles/intel-math-kernel-library-documentation Online-Documentation]
|-
| Graphical Interface
| No
|}


== Applications ==
= Description =
'''Intel MKL (Math Kernel Library)''' is a library of optimized math routines for numerical computations such as linear algebra (using BLAS, LAPACK, ScaLAPACK) and discrete Fourier Transformation.
With its standard interface in matrix computation and the interface of the popular fast Fourier transformation library fftw, MKL can be used to replace other libraries with minimal code changes. In fact a program which uses FFTW without MPI doesn't need to be changed at all. Just recompile it with the MKL linker flags.
<br>
* [http://software.intel.com/en-us/articles/intel-math-kernel-library-documentation Online-Documentation]


= Compiling and linking =
=== MATLAB/Simulink ===
Compilation is possible with both GCC and Intel compilers but it is easier for Intel compilers, so this case is explained here.
After loading the compiler and the library module with
<pre>
$ module load compiler/intel
$ module load numlib/mkl
</pre>
you can include the MKL header file in your program:
<source lang=cpp>#include <mkl.h></source>
Compilation is simple:
<pre>$ icpc -c example_mkl.c</pre>
When linking the program you have to tell the compiler to link against the mkl library:
<pre>$ icpc example_mkl.o -mkl</pre>
With the -mkl switch the intel compiler automatically sets the correct linker flags but you can specify them explicitly for example to enable static linking or when non-intel compilers are used. Information about the different options can be found at https://software.intel.com/en-us/node/438568 and especially helpful is the MKL link line advisor at https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor.
By default $MKL_NUM_THREADS is set to 1 and so only one thread will be created, but if you feel the need to run the computation on more cores (after benchmarking) you can set $MKL_NUM_THREADS to a higher number.
<br>
<br>
== FFTW Interface to Intel Math Kernel Library (MKL) ==
Sometimes, [[FFTW|FFTW]] is not available on your cluster. You can use the MKL library
instead and include the FFTW functions, too.


Intel Math Kernel Library (MKL) offers FFTW2 and FFTW3 interfaces to Intel MKL Fast Fourier Transform and Trigonometric Transform functionality. The purpose of these interfaces is to enable applications using FFTW to gain performance with Intel MKL without changing the program source code.
=== Octave ===
To include the proper header files use the compiler option
-I${MKL_INC_DIR}/fftw


If you want to link dynamically against the fftw functions you can just use the flag
=== R ===
-mkl


but when using static linking you have to link against the correct library in the directory
== Programming ==
${MKL_HOME}/interfaces/


See the corresponding webpages:
=== Compilers ===
* [https://software.intel.com/en-us/node/471410 FFTW Interface to Intel Math Kernel Library]

* [https://software.intel.com/de-de/node/471414 FFTW2 Interface to Intel Math Kernel Library]
==== GCC ====
* [https://software.intel.com/en-us/node/471456 FFTW3 Interface to Intel Math Kernel Library]

==== Intel ====

=== Debugging ===

=== Numerical Libraries ===

==== FFTW ====

FFTW is a C subroutine library for computing the discrete Fourier transform
(DFT) in one or more dimensions, of arbitrary input size, and of both real and
complex data (as well as of even/odd data, i.e. the discrete cosine/sine
transforms or DCT/DST).

This package provides three versions of the fftw3
library depending on precision: libfft3, libfftw3f and libfftw3l for double,
single and long-double precision libraries.

Online Documentation: http://www.fftw.org/fftw3_doc/

Local documentation:

See 'info fftw3', 'man fftw-wisdom' and 'man fftw-wisdom-to-conf'.
See also documentation folder pointed to by shell variable $FFTW_DOC_DIR

Hints for compiling and linking:

Load the fftw module, and, if needed, the corresponding openmpi module.

After having loaded the appropriate module(s), you can use several
environment variables to compile and link your application.

* Compile serial program:

<code> gcc example.c -o example -I$FFTW_INC_DIR -L$FFTW_LIB_DIR -lfftw3 -lm </code>

* Compile program with support for POSIX threads:

<code> gcc example.c -o example -I$FFTW_INC_DIR -L$FFTW_LIB_DIR -lfftw3_threads -lfftw3 -lpthread -lm </code>

* Compile program with support for OpenMP threads:

<code> gcc example.c -o example -fopenmp -I$FFTW_INC_DIR -L$FFTW_LIB_DIR -lfftw3_omp -lfftw3 -lm </code>

* Compile program with support for MPI:

<code> mpicc example.c -o example -I$FFTW_INC_DIR -L$FFTW_LIB_DIR -lfftw3_mpi -lfftw3 -lm </code>

* Run program with MPI support:

<code> mpirun -n <ncpu> ./example </code>

(Replace <ncpu> by number of processor cores.)

Replace -lfftw3, -lfftw3_threads, etc. by -lfftw3f, -lfftw3f_threads, etc. for single
precision and by -lfftw3l, -lfftw3l_threads etc. for long-double precision codes, respectively.

These commands will compile your program with dynamic fftw library versions in
which case you also have to have the fftw module loaded for running the program.
Alternatively, you may want to link your program with static fftw library versions.
With static fftw libraries it is only necessary to load the fftw module for compiling
but not for executing the program.

* Compile program with static fftw library versions (example for POSIX threads support):

<code> gcc example.c -o example -I$FFTW_INC_DIR $FFTW_LIB_DIR/{libfftw3_threads.a,libfftw3.a} -lpthread -lm </code>

or:

<code> gcc example.c -o example -I$FFTW_INC_DIR -L$FFTW_LIB_DIR -Wl,-Bstatic -lfftw3 -lfftw3_threads \
-Wl,-Bdynamic -lpthread -lm <code>

Environment variables $FFTW_INC_DIR, $FFTW_LIB_DIR etc. are available after
loading the module.

Sample code for various test cases is provided in folder pointed to by environment
variable $FFTW_EXA_DIR.

==== GNU Scientific Library (GSL) ====

The '''GNU Scientific Library''' (or '''GSL''') is a software library for numerical computations in applied mathematics and science. The GSL is written in the C programming language, but bindings exist for other languages as well.

Online-Documentation: http://www.gnu.org/software/gsl/

Local-Documentation:

See 'info gsl', 'man gsl' and 'man gsl-config'.

Tips for compiling and linking:

After having loaded the gsl environment module, you can use several
environment variables to compile and link your application with the gsl library.

Your source code should contain preprocessor include statements with a gsl/
prefix, such as

<pre> #include <gsl/gsl_math.h> </pre>


A typical compilation command for a source file example.c with the
GNU C compiler gcc is

<code> gcc -Wall -I$GSL_INC_DIR -c example.c </code>

The GSL_INC_DIR environment variable points to location of
the include path for the gsl header files.

The following command can be used to link the application with the
gsl libraries,

<code> gcc -L$GSL_LIB_DIR -o example example.o -lgsl -lgslcblas -lm </code>

The GSL_LIB_DIR environment variable points to the location
of the gsl libraries.

==== Math Kernel Library (MKL) ====

=== MPI ===

=== OpenMP ===

Latest revision as of 00:08, 15 March 2023

The main documentation is available via module help numlib/mkl on the cluster. Most software modules for applications provide working example batch scripts.


Description Content
module load numlib/mkl
License Commercial. See EULA.
Citing n/a
Links Intel MKL Homepage | Online-Documentation
Graphical Interface No

Description

Intel MKL (Math Kernel Library) is a library of optimized math routines for numerical computations such as linear algebra (using BLAS, LAPACK, ScaLAPACK) and discrete Fourier Transformation. With its standard interface in matrix computation and the interface of the popular fast Fourier transformation library fftw, MKL can be used to replace other libraries with minimal code changes. In fact a program which uses FFTW without MPI doesn't need to be changed at all. Just recompile it with the MKL linker flags.

Compiling and linking

Compilation is possible with both GCC and Intel compilers but it is easier for Intel compilers, so this case is explained here. After loading the compiler and the library module with

$ module load compiler/intel
$ module load numlib/mkl

you can include the MKL header file in your program:

#include <mkl.h>

Compilation is simple:

$ icpc -c example_mkl.c

When linking the program you have to tell the compiler to link against the mkl library:

$ icpc example_mkl.o -mkl

With the -mkl switch the intel compiler automatically sets the correct linker flags but you can specify them explicitly for example to enable static linking or when non-intel compilers are used. Information about the different options can be found at https://software.intel.com/en-us/node/438568 and especially helpful is the MKL link line advisor at https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor. By default $MKL_NUM_THREADS is set to 1 and so only one thread will be created, but if you feel the need to run the computation on more cores (after benchmarking) you can set $MKL_NUM_THREADS to a higher number.

FFTW Interface to Intel Math Kernel Library (MKL)

Sometimes, FFTW is not available on your cluster. You can use the MKL library instead and include the FFTW functions, too.

Intel Math Kernel Library (MKL) offers FFTW2 and FFTW3 interfaces to Intel MKL Fast Fourier Transform and Trigonometric Transform functionality. The purpose of these interfaces is to enable applications using FFTW to gain performance with Intel MKL without changing the program source code. To include the proper header files use the compiler option

-I${MKL_INC_DIR}/fftw

If you want to link dynamically against the fftw functions you can just use the flag

-mkl

but when using static linking you have to link against the correct library in the directory

${MKL_HOME}/interfaces/

See the corresponding webpages: