Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6975 Discussions

link with blas and lapack in Intel MKL kit

cjl
Beginner
5,520 Views

On Linux with GCC, how can I ensure that I am linking against blas and lapack in Intel MKL kit, which is supposed to have better performance than standard Linux system blas and lapack?

I thought if I compile my application with '-lmkl_blas95_lp64 -lmkl_lapack95_lp64', it will link against blas and lapack in Intel MKL kit.

But if I use 'ldd compiled_binary' it shows the binary is linked against standard Linux system blas and lapack

libblas.so.3 => /usr/lib64/libblas.so.3 (0x00007f51fa44d000)
libf77blas.so.3 => /usr/lib64/atlas/libf77blas.so.3 (0x00007f51fa229000)
libcblas.so.3 => /usr/lib64/atlas/libcblas.so.3 (0x00007f51fa008000)

liblapack.so.3 => /usr/lib64/atlas/liblapack.so.3 (0x00007ff407c2f000)

What am I doing wrong here? Thanks.

0 Kudos
9 Replies
mecej4
Honored Contributor III
5,507 Views

If your code does not make any Lapack95 or BLAS95 calls, but calls the Fortran 77 routines in Lapack and BLAS, the two extra libraries that you specified do not contain any routines that are needed, so the linker will pull nothing from them. The routines in the *95 libraries have shorter argument lists and often some of the arguments are optional, so any routine that calls these more convenient interfaces needs to provide interfaces to them. See the examples provided with MKL.

If you are calling Lapack or BLAS routines from C code, you should not be using the *95 libraries at all -- they are only for calling from modern Fortran.

If you want to use the MKL versions of the Lapack and BLAS libraries, you will have to use the linker's -L option to specify the location of those libraries, and -l options to specify which MKL libraries to use.

It is helpful to use the MKL Link Line Advisor for obtaining the command line to use.

0 Kudos
cjl
Beginner
5,470 Views

Then what -L -l option I should use to force my app to use BLAS and LAPACK from MKL?  I thought '-lmkl_blas95_lp64 -lmkl_lapack95_lp64' was for BLAS and LAPACK.

ls *blas* *lapack* in lib/ gives me:
libmkl_blas95_ilp64.a libmkl_scalapack_ilp64.so
libmkl_blas95_lp64.a libmkl_scalapack_ilp64.so.1
libmkl_lapack95_ilp64.a libmkl_scalapack_lp64.a
libmkl_lapack95_lp64.a libmkl_scalapack_lp64.so
libmkl_scalapack_ilp64.a libmkl_scalapack_lp64.so.1

Thanks.

0 Kudos
cjl
Beginner
5,466 Views

I followed MKL Link Line Advisor and used 

-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl

This is the just what I used before trying '-lmkl_blas95_lp64 -lmkl_lapack95_lp64'

ldd shows my app still use blas from system lib /usr/lib64/libblas.so.3

0 Kudos
mecej4
Honored Contributor III
5,430 Views

You have not told us which BLAS and Lapack routines are being called from your code and you have not reported how you compile and link, and I cannot guess what is going wrong.

To repeat what I wrote earlier: You should not be trying to link with libraries containing "95" in their names at all unless you are coding in Fortran and you chose deliberately to call Lapack95/BLAS95 routines.

You should not link libraries and objects with a mix of LP64/ILP64 conventions, with rare exceptions. LP64 is for calling MKL routines with 32-bit integer arguments, and ILP64 is for 64-bit integer arguments.

0 Kudos
cjl
Beginner
5,379 Views

I do not know which BLAS and Lapack routines are being called. I am using a 3rd party lib IpOpt  https://coin-or.github.io/Ipopt/INSTALL.html which says:

-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm

I suppose IpOpt is using standard  BLAS and Lapack routines. So the above should cause the compiled IpOpt to use BLAS and Lapack routines from MKL. But 'ldd' says it's using BLAS and Lapack routines from system '/lib64'.

I am not mixing ilp64 and lp64, I am just trying both (ilp64 always or lp64 always).

Thanks.

0 Kudos
cjl
Beginner
5,378 Views

Are you saying that for standard blas and lapack routines,

-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm   

will link against blas and lapack routines in MKL?

Thanks.

0 Kudos
cjl
Beginner
5,330 Views

I finally found the cause.  CoinIpOpt use another 3rd party lib, which has to be compiled with  

-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm   

as well. Otherwise it is using system blas lib in /lib64.

Thanks. 

0 Kudos
PrasanthD_intel
Moderator
5,295 Views

Hi Jim,


Glad you have found the cause.

As your issue is resolved now, let us know if we can close the thread.


Regards

Prasanth


0 Kudos
PrasanthD_intel
Moderator
5,208 Views

Hi Jim,


As your issue has been resolved, we are closing this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only


Regards

Prasanth


0 Kudos
Reply