Linking Intel MKL is easy

Linking Intel MKL is easy

TODD R. (Intel)'s picture
icl prog.c /Qmkl

or,

ifort prog.f /Qmkl

That's the easiest way if you are using one of the latest Intel compilers on Windows*. There are similar compiler options for Linux* and Mac OS* X as well.

Another easy way is to use our new dynamic linking model which requires a link to just one library. Add mkl_rt.lib to your Windows* link line or add -lmkl_rt to your Linux* or Mac OS* X link line.

These new options willwork for the cases usedby most users. Those who use less common interfaces or threading models may still want to visit the Link Line Advisor to find the right set of libraries.

11 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
steingre's picture

If it would be so easy, no one would have problems....

mecej4's picture

The easiness claim was made with two explicit conditions:

1. "These new options will work for the cases used by most users."

AND

2. The current Intel compilers are used.

I have found no example for which the /Qmkl (-mkl on Linux/OSX) option did not work. If you have such examples I am sure that they will be given adequate attention if you divulge them here.

rudi-gaelzer's picture
Quoting mecej4 The easiness claim was made with two explicit conditions:

1. "These new options willwork for the cases usedby most users."

AND

2. The current Intel compilers are used.

I have found no example for which the /Qmkl (-mkl on Linux/OSX) option did not work. If you have such examples I am sure that they will be given adequate attention if you divulge them here.

As a matter of fact, I think I found an example (literally from the mkl/examples directory) where these options were unsuccessful.

I'm using (ifort -V):

Intel Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.4.319 Build 20120410

which I think is the latest version.

Take a look at my post here:

http://software.intel.com/en-us/forums/showthread.php?t=105667&o=a&s=lr

mecej4's picture

This thread was about using MKL with simple C and Fortran-77 codes.

Using the Fortran 95 interfaces requires the MKL Lapack95 and Blas95 libraries to be specified at link time, and requires specifying the path for the module files when calling from Fortran-9X.

Earlier releases of MKL came with no prebuilt Lapack95 and Blas95 libraries.

rakesh's picture

Can anyone tell me how to use command line argument for compilation of c program.

Gennady Fedorov (Intel)'s picture

at the very top of this thread Todd already gave two simpliest examples for windows and linux

alexvader's picture

Hi

I used the Link line advisor, to build a link line for my application, with PARDISO, it gave this line

 -L$(MKLROOT)/lib/intel64 -lmkl_scalapack_ilp64 -lmkl_cdft_core -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmpi_ilp64 -lpthread -lm

With this compiler option :

 -openmp -DMKL_ILP64 -I$(MKLROOT)/include

I created this makefile :

CFLAGS = -Wall -O3  -I ../../../SPOOLES-2.2_Intel -I /opt/intel/mkl/include -DMKL_ILP64 -DARCH="Linux" -DSPOOLES -DARPACK -DPARDISO -DMATRIXSTORAGE -DUSE_MT=1
FFLAGS = -O3 -nofor-main -openmp

CC=icc
FC=ifort

.c.o :
        $(CC) $(CFLAGS) -c $<
.f.o :
        $(FC) $(FFLAGS) -c $<

include Makefile.inc

SCCXMAIN = ccx_2.5.c

OCCXF = $(SCCXF:.f=.o)
OCCXC = $(SCCXC:.c=.o)
OCCXMAIN = $(SCCXMAIN:.c=.o)

DIR=/home/alex/Desktop/Buildfactory/Calculix/SPOOLES-2.2_Intel
MKLROOT=/opt/intel/mkl
MKLPATH=/opt/intel/mkl/lib/intel64
MKLINCLUDE=/opt/intel/mkl/include

LIBS = \
       $(DIR)/libspooles.a \
        $(DIR)/MT/src/spoolesMT.a \
        ../../../ARPACK_Intel/libarpack_Linux.a \
        ../../../Pardiso/libpardiso412-INTEL120-X86-64.so \
       -lm -lc -lutil -ldl -lpthread

ccx_2.5: $(OCCXMAIN) ccx_2.5.a -L$(MKLROOT)/lib/intel64 -lmkl_scalapack_ilp64 -lmkl_cdft_core -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmpi_ilp64 -lpthread -lm  $(LIBS)
        ./date.pl; $(CC) $(CFLAGS) -c ccx_2.5.c; $(FC) $(FFLAGS) -o $@ $(OCCXMAIN) ccx_2.5.a  -L$(MKLROOT)/lib/intel64 -lmkl_scalapack_ilp64 -lmkl_cdft_core -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -lmkl_blacs_intelmp$

ccx_2.5.a: $(OCCXF) $(OCCXC)
        ar vr $@ $?

when i type Make this gives me an error :

alex@iskandhar:~/Desktop/Buildfactory/Calculix/CalculiX/ccx_2.5_Intel_Pa/src$ make
make: *** No rule to make target `-L/opt/intel/mkl/lib/intel64', needed by `ccx_2.5'.  Stop.
alex@iskandhar:~/Desktop/Buildfactory/Calculix/CalculiX/ccx_2.5_Intel_Pa/src$

Where is my mistake..?

I understand nothing of makefiles, all i know is that i have to link with Intel compiled Spooles, Arpack, and Pardiso, all the sources have been compiled with icc and ifort

Can someone help me in this..?

BR

Alex

Victor Pasko (Intel)'s picture

Hi,

In the makefile you need the only two `$(OCCXMAIN) ccx_2.5.a' dependencies for target ccx_2.5. So the line should be as follows:

ccx_2.5: $(OCCXMAN) ccx_2.5.a

Also please double check used MKL libraris. E.g. there is incorrect  -lmkl_blacs_intelmp$ in your post

 

Thanks, -- Victor
billsincl's picture

How to reference these from a Fortran program?

I looked under PROJECT PREPERTIES, under FORTRAN,

and I jet FOUR possible choices. How would I know which one ?

Pr does it matter?

Sergey Kostrov's picture

In some C/C++ project ( still in R&D state ) I decided to use runtime binding of MKL functions instead of dynamic linking. Here is a small example how I do it:
...
hMklRtDll = ::LoadLibrary( RTU("mkl_rt.dll") );
if( hMklRtDll == NULL )
break;

CrtPrintf( RTU("Dynamic library mkl_rt.dll loaded\n") );

pfMklGetVersionString = ( void ( * )( char *, int ) )::GetProcAddress( hMklRtDll, "MKL_Get_Version_String" );
if( pfMklGetVersionString == NULL )
break;
...
MKLVersion Ver = { 0x0 };
int iLenData = 256;
char szVerData[256] = { 0x0 };

pfMklGetVersionString( szVerData, iLenData );
CrtPrintfA( "\t%s\n", szVerData );
...
The most important things are that at a compilation phase I don't use any C++ compiler options related to MKL and at a linker phase I don't use any MKL libraries.

Login to leave a comment.